From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to measure pulse width with MyRIO

Solved!
Go to solution

Hi,

 

Sorry in advanced if this isn't the most suitable forum.  I'm not entirely sure whether this was a more general "software" problem or specific to the MyRIO.  I have searched the forums and have found a few related topics but could find none that help me in this context.

 

I am trying to measure the pulse width of an ultrasonic ping sensor.  It outputs a conditioned signal - the time it is high directly corelates to how far away the object is.  Being new to LabVIEW I'm confused as to how I should calculate the time it remains high.  

 

I've read that LabVIEW shouldn't need "variables" like in python or C, so what is the best way of measuring the time the signal is high?  Normally I would go (new_time - old_time) but obviously I can't store an old time in LabVIEW like I would in python or C.

 

Other notes:

I've got the ping sensor echoing properly and I can display the echos on a chart and see a perfectly valid square wave.

chart.png

0 Kudos
Message 1 of 6
(4,391 Views)

Don't worry, I've ended up using an arduino to do the data collecting.  It then pipes it over UART to the MyRIO.  I can grab the distance in cm with a single line and the NewPing library on the arduino.

0 Kudos
Message 2 of 6
(4,359 Views)
Solution
Accepted by topic author jabelone

To answer your question about how you would do it in LabVIEW...

 

While LabVIEW doesn't have declared/named variables like you have in a text-based language, data is stored on the wires. You can use nodes like the feedback node or shift registers to store values between iterations of a loop:

Feedback.PNG(this will keep subtracting y (starting with 0) and store the result for the next time it runs)

 

LabVIEW also has functions in the maths/signal processing palette for doing pulse width detection on a waveform.


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 3 of 6
(4,353 Views)

Thanks heaps, I think the notion of Feedback Nodes (and potentially shift registers) is what I was missing.

0 Kudos
Message 4 of 6
(4,345 Views)

how to create measure the pulse and counting

0 Kudos
Message 5 of 6
(3,592 Views)

I'm not sure exactly what you are asking, but we do have pulse width examples in NI Example Finder (Help tab >> Find Examples). The PWM Measurement.lvproj example shows you how to measure a digital input signal and calculate the time the signal is high or low. 

0 Kudos
Message 6 of 6
(3,570 Views)