03-11-2015 03:33 AM
Hey,
actually I am working on a project, where I would like to calculate the distance between my ultrasonic sensor
and my object. I have a NI 9402 and one ultrasonic sensor, which can send and receive the signal.
My idea was to generate a signal on channel 0 and to receive the "answer" on channel 3.
It is working ok, but I still have problems in calculating a precise time value to calculate the distance.
I would really appreciate if someone would have an idea how to realise that
Thanks in advance for your help.
Kind regards,
Felix
03-11-2015 05:38 PM
Hey there Felix,
I'm not exactly sure what sort of problems your running into calculating the time value. Could you elaborate?
I do have a hunch at what might be going on. You are using a local variable to communicate between the two loops. This can lead to unexpected behavior, since the value of the local variable may change before it is read, leading to a race condition where we do not know what the outcome of the code will be.
If you are looking to measure time, and do it in two separate loops, I would look into using something like an FGV timer
https://decibel.ni.com/content/docs/DOC-35414
This is a commonly way to measure time in a way that can be used to prevent race conditions.
Also, if you ever need to convert LabVIEW code into a different version, you can post the code to the following forum with your request:
http://forums.ni.com/t5/Version-Conversion/bd-p/VersionConversion
03-12-2015 09:08 AM
Thanks for your answer. I think that might be the problem.
I have tried to implement the timer, but it didn't really worked.
I think I did a mistake. I haven't understood, how to send the different time values between the loops.
Could you maybe do me the favor and show me how to fix my VI with the new timer?
I would really appreciate that and thanks for your help in advance!
Kind regards,
Felix