Example Program Drafts

cancel
Showing results for 
Search instead for 
Did you mean: 

myRIO HC-SR04 Ultrasound Module

Overview

This code is for use on the FPGA of a myRIO, and is used to get a time of flight reading from a 4 pin ultrasound sensor, such as the HC-SR04

Description

Using pulse width measurements, this code measures the response of an ultrasound module to give the time to receive a response. This time directly corresponds to distance, and can be converted by dividing by 1,000,000 (to convert to seconds) then multiplying by the 340 (the speed of sound).

There are two loops in this code, one to manage the pulse width measurement of the module's ECHO line, and another to trigger the module on the TRIG line.

Steps to Implement or Execute Code

  1. Create new project
  2. Add this code to the FPGA target of a myRIO
  3. Ensure that your hardware matches the connectors used in the VI (In this case DIO3 on connector C is used for ECHO and DIO7 on connector C is used for TRIG)
  4. Compile FPGA code
  5. Run FPGA code

(This code will not run unless under and FPGA target in a project)

Requirements

Software

LabVIEW 2013

Hardware

NI myRIO

Additional Images or Video


download.jpg


Matt H
Applications Engineer
National Instruments UK
Comments
Member tejas14
Member

Please place the 2011 version compatible vi .

Thanks in advance

Tejas

Member Lexilighty
Member

Hi,

Thanks for your VI. I am trying to deploy this in labview 2014 and I keep getting an error: Find the vi named: "nirbiEmuTemplateMethod_erros.vi"

I wonder if you could help out with this missing file.

Member MrGoodat
Member

Hi,

could you please tell me in wich range the distance measurment works?

I am looking for a system to detect very small distances like 10µm to around 5mm.

But at first thanks for such a nice VI.

Member prince29
Member

it finds an error on your vi.. do you know how to solve it

Member techfreak
Member

Hello, I am new to Myrio !! I need to use this sensor for distance measurement. I will be greatful if someone provide me with the VI that works fine.

Thanks

Member deby.gauraf.035
Member

hello, i'm a newbie of myRio (FPGA)..

i'm doing my project now about ultrasonic sensor SR-HC04 that need recognize distance in centimeter..i just know time of flight in uS ,, but i need the distance data in centimeter..So how can i solve it?? To all the expert please help me to solve my problem...

Member prince29
Member

hi there.. the time is in μs (*10^-6 seconds). so, you will have to:

1. divide the result by 10^6 to get the result in seconds

2. Divide by 2, because the time measured is for the whole trip, going and coming, but the barrier found is in the middle of this time

3. Multiply by 340m/s, the speed of sound, ant the result is the distance in meters

4. for cm, divide by 100 and you are good to go

Member techfreak
Member

Can you please tell me how you programmed myrio to get the pulse width in microseconds, that would help me a lot. Is there any kind of interrupt which triggers the count.

Thanks

Member shubhangijoshi
Member

Can we use Ultrasonic sensor to with MYRIO in Real time target mode....

If yes, how ?

If no, why....

Pl help as my project is based on this...

Member BerlinFatih
Member

Thank you MHutch,

i have the Version Labview 2015.

The first problems was the DIOxx, because the VI from MHitch ist 2013. After change the DIOxx to correct function, was to be running the Project.
And the helpinging from prince29 was beautiful.

Sorry for my bad English.

Member Shlok1229
Member

Shubhangijoshi,

It would not be good to use RT for this as it does not give as good timing precision.

Member Shlok1229
Member

Nice work..

Member Milos321
Member

Hi,

could you please tell me, how we can use this code not in FPGA mode, because we need data from sensor fore another function that we can not use in FPGA mode, like controling motor or something similar.

Member Shlok1229
Member

Hi,

We need not necessarily use the VI in FPGA mode to acquire and view the data.

You can simply use the Open FPGA VI Reference and the read/write control to get the same values in the RT VI.

temp.PNG

Hope this helps you.

Member Milos321
Member

Hi ,

We also have that problem, we run FPGA VI and get values from sensors, then we get this valuse using Open FPGA VI Reference and the read/write to another RT VI but on this RT VI another function dont work, like controling motors, LED diods or sometihing like that. Generally its look like this two VI cant work simultaneously, but we dont have any errors, and both VI are runing.

If you have any idea or solution, we would be grateful to share it with us.


Member Shlok1229
Member

Can you please elaborate on your problem and create a thread in the forum?

Member Milos321
Member

Hi,

We have 3 ultrasnic sensor, and mesure distance with them in FPGA mode, then we must use that measurement and control robot(4 DC motor RT VI) , if distance is less then some value robot must stop.

Generaly, problem is that when we run FPGA mode other simple VI don't work. For exemple, we try to turn on LED diods on MyRIO parallel with FPGA VI, we compile both VI and dont have any errors, but our LED diod dont react when we press button.

But FPGA VI work well. Our priority task, is to make bond between FPGA VI that give us feedback about distance, and that use that variables to prevent the robot from punching the trammels in RT VI.

Member Shlok1229
Member

Hi,

I really don't see any reason why your VI won't work.

I can recommend you to only acquire data in the FPGA VI and link the data to the RT VI and use and process it there.

Do not do signal processing in the FPGA VI, it will just complicate things. There will be no need for you to actually RUN the FPGA VI, just refer to it as I said before.

For example, create controls for the LEDs in the FPGA VI, and actually control it in the RT one.

If there is any problem that you can't understand, please post to the NI forum, attach your files and I can try to do my best to help you.

Member Milos321
Member

Ok, I will post to NI forum and attach files. It just example for LEDs, our program is a litle bit complicated, we just need to use measurement from sensor in FPGA mode to RT VI, and we get measured distance in RT VI, but other funcion in that RT VI don't work.

Member Theodoro_Cardoso
Member

Hi,

I couldn't find the donwload link, was it removed or am I just a newbie that can't see it?

Thanks in advance

 

Contributors