LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with ultrasonic sensor and cRIO

Solved!
Go to solution

Hi, i'm trying to connect my Ultrasonic sensor to my cRIO to read distance  but i'm having some issues. The sensor has 4 pins, echo, trigger, vcc, ground. The trigger is connected to a DO (NI 9472) and the echo (receiver) to DI (NI 9411). The sensor first need to get 10 usec pulse in trigger to activate the echo pin. When echo is activated, it sends a ultrasonic signal and when it bounce and return, thats the distance. My issue is I can't read anything. I want to measure the time when DI is on and when is off. How should i do that? I'm working with FPGA so I thought I could just put the DI and DO in there and control them via RT but i couldnt. Any suggest? Please. 

I'm using LV 8.0 and cRIO 9002. Chassis 9104.

Thank you

0 Kudos
Message 1 of 8
(4,949 Views)

Hello,

could you please attach your VI?

 

-James

Greetings and Regards,
James
0 Kudos
Message 2 of 8
(4,897 Views)

This is the VI. In my project, I have this part inside the FPGA. I also tried to connect the DI to the stop control just to stop the process and see if the value measured had congruence with the distance I was using. Thank you for your help

0 Kudos
Message 3 of 8
(4,890 Views)

Hello rolandonunez,

 

You must disable the output before you can use the same resource to read input. Here is a link that might help you:

http://zone.ni.com/reference/en-XX/help/371599H-01/lvfpgaconcepts/performing_basic_i_o/

If you want to measure the time from when the digital input was on and then off, you can try something like this:

http://digital.ni.com/public.nsf/allkb/6F6B9F4E149C80578625652800784764

Like the example in the link, you can add another frame for you code and then compare the times. 

Hope this helps.

 

Regards.

0 Kudos
Message 4 of 8
(4,869 Views)
Solution
Accepted by topic author rolandonunez

Here is my code for reading an HC-SR04 in LAbVIEW FPGA:

hcsr04 fpga.PNG

TriggerTankLevelRead is set True by the Real Time host (cRIO), this kicks off a measurement.

The cRIO then waits about 100mS before reading TankLevelPulse.  during this time, the FPGA executed the frames:

DIO1 high, 10uS delay, DIO1 Low.  Wait for rising edge, get start time, wait for falling edge, get stop time, subtract times and return pulse length.

Abort is used to get out of the otherwise endless while loops if the sensor is disconnected.

I have been using this code to read liquid level in a tank for a couple of years now, so thumbs up to the sensor, and the software!

I think this will work for you too. Happy to help,

Michael.

Message 5 of 8
(4,863 Views)

Thank you very much! It works!

0 Kudos
Message 6 of 8
(4,836 Views)

Hi Michael.

I was wondering what is the coding for the false condition in the case structure?

Hope that you can help.

0 Kudos
Message 7 of 8
(4,335 Views)

Hi Razak,

 

coding for the false condition in the case structure?

Most probably "doing nothing"…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 8
(4,328 Views)