LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Capture fist occurrence of threshold

I'm trying to find the first occurrence of a passing a threshold using the Threshold 1D Array function.  My labview program is continuously sampling the output of a variable DC power supply.  The supply will start at 0V and I will increase and eventually pass the set threshold.  I'm using a DC power supply to simulate a transducer that will essentially output a step function with a rise time of 50ms and amplitude of 5V.  I don’t have the transducer yet.  What I want to accomplish in labview is to display only the first occurrence of the threshold being passed.  In my attached BD, the threshold function refreshes with every while loop iteration.  The while loop reads 100 samples of data sampled at 1kHz with each iteration.  Because this is much faster than I can turn the knob, the reported index is either 0 or 99 depending if I'm increasing above the threshold or decreasing below the threshold.  If I turn my knob quickly about the threshold point, I can see the index indicator very briefly display an index between 0 and 99.  I'm not sure how to only capture the first occurrence and could use some guidance.

 

Another idea I’ve been toying with is to eliminate the continuous sampling and do a measurement analogous to a single sweep on an oscilloscope.  I could tell labview to capture a finite amount of samples that would capture the whole step function from the transducer.  Then have a for loop function that would store the results into an array.  The entire array would then go into a threshold function.  I’m still new with labview and I’m not sure how to implement that in a BD.

0 Kudos
Message 1 of 6
(2,284 Views)

You would put it inside a case structure and have a boolean in an initialized shift register that toggles when the first instance is found. Don't forget to add "i" x 1000 to the fractional index. Also include a mechanism to reset.

 

(If you would attach a VI instead of a picture, somebody might actually show you directly.)

0 Kudos
Message 2 of 6
(2,280 Views)
0 Kudos
Message 3 of 6
(2,273 Views)

Maybe this can give you some ideas ....

 

(Of course you don't want to build an ever-growing array or stop once the threshold is found, so modify as needed)

0 Kudos
Message 4 of 6
(2,247 Views)

Thanks for your help!  I've been looking at your example and trying to figure out how it works. I get that when the size of the simulated data array is equal to the output of the threshold 1D function this will trigger boolean to display the fractional index.  What I don't understand is the additional arithmetic performed on the output of the threshold 1D fuction (OUTPUT + I * 1000).  Also, is there a reason you chose the for loop iteration count to be 1000?

0 Kudos
Message 5 of 6
(2,194 Views)
  • The FOR loop just simulates a new data segment and can be of any size. You can even remove it to simulate getting one point at a a time.
  • If you don't multiply, the position starts from zero with each iteration of the while loop because we only look at the new segment. Of course you could look at the built array instead, but that means you would need to inspect an ever-growing array where you look at ancient elements over and over. That can get expensive. (If the number of points varies per iteration, you would accumulate the running start index in a shift register, same idea)
0 Kudos
Message 6 of 6
(2,180 Views)