LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Programming Ultrasonic sensor HC-SR04

Hi

 

I'm trying to calculate the distance. I'm using an NI USB-6008 card. It has only one counter. So I'm going to find the digital out and then create a counter (in program). How do I program using only one counter (of the ni 6008)? I need configuration help too.

 

Please help.

0 Kudos
Message 1 of 22
(5,374 Views)

Hi kdm,

 

it's a good idea to discuss hardware related questions with NI sales guys before acquiring some cheap USB boxes! Reading spec sheets might help too.

 

Your sensor needs (atleast) 10µs TTL trigger pulses. You will have a hard time to generate them with your USB6008… (Well, you could create 10ms pulses with those software-timed digital outputs.)

- Your sensor outputs its measurement data as time-coded signal. You will have a hard time to measure that time interval accurately with your UBS6008…

 

What do you want to count with that simple falling edge counter of the USB6008?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 22
(5,358 Views)

Hi Gerd,

 

How to send a 10us pulse on the trigger input? 

Is the trigger pin connected to digital input (of usb6008) and echo pin connected to digital output?

0 Kudos
Message 3 of 22
(5,350 Views)
You would be lucky to generate a 1ms pulse and your understanding of inputs and outputs is backwards.
0 Kudos
Message 4 of 22
(5,346 Views)

Hi

 

And why do we need a counter? The PFI 0 pin can be connected to what?

Can echo pin be connected to PFI 0? 

0 Kudos
Message 5 of 22
(5,339 Views)

Hi kdm,

 

you started the discussion on using counters in your own question! Now you ask "why to use them"?

 

You can physically connect the ECHO pin with PFI0 input of the USB6008 - but you will not measure any meaningful values…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 22
(5,333 Views)

Hi Gerd,

 

Why wont I get meaningful values?

 

Can I use the PFI 0 as trigger output (10us) and then design a counter in the program? 

0 Kudos
Message 7 of 22
(5,330 Views)

Hi kdm,

 

did you read the manual of the USB6008? There's a chapter on usage of PFI0 that answers yopur question…

 

You can "design a counter" in your programm, but what do you want to count? You need to measure a time between two edges of a digital signal!

 

An idea: To measure the time of that digital signal you need to use one AI of the USB6008. It allows a sample rate of 10kS/s giving you a timing resolution of 100µs. You will need to analyze the AI signal to find your digital signal's edges…

Best regards,
GerdW


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

Hi Gerd,

 

Yes, I read the manual. I've decided to use the PFI0 for the trigger pulse.

 

For counter design:

I could not understand your idea of using the AI signal to calculate time. Can you please elaborate?

And the minimun pulse width of echo is 150us, so I need to read for every "less than 150us". Am I right? 

Or, can I begin a counter for every true (high) of a rising edge and then set a falling edge. When a falling edge, I make counter to stop. The resulting count value is multiplied by the time (read loop time) to get time elapsed.

0 Kudos
Message 9 of 22
(5,284 Views)

Hi kdm,

 

again: read the specs of both devices, sensor and USB6008. Compare the specs to understand, what you can achieve with this combination - and what doesn't fit…

 

- You can read TTL signals with an AI too. The AI has the advantage of hardware-timed operation with a max sample rate of 10kS/s giving you a timing resolution of 100µs. You can detect echo pulses of atleast 100µs length - but only in 100µs steps (aka resolution). Will this fit for your application?

- The PFI0 ONLY acts as falling edge counter. That's it. No time measurement. No starting on rising edge and no stopping on falling edge. Just counting falling edges. Will this fit your application?

 

AGAIN: Compare the specs of both devices, sensor and USB6008!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 22
(5,279 Views)