LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

saving data after threshold is reached

hi, im sure there must be a really simple way to do this but I basically want to monitor the voltage acquired from a DAQ device and then trigger saving of the data once the threshold of 0.02 V is reached. This is part of a much more complicated code and in the long term i want to save the data from multiple different sources using this trigger so it needs to happen at the exact time the data reaches the threshold and not at the end of that loop (hope that makes sense) 

0 Kudos
Message 1 of 5
(527 Views)

I would recommend you to start from Producer/Consumer Read Waveform Data and Write to TDMS at Two Different Rates

You can add some threshold-checking logic to the enqueue element node.

-------------------------------------------------------
Control Lead | Intelline Inc
0 Kudos
Message 2 of 5
(513 Views)

There are two "competing" needs concerning the data stream, and you haven't (a) provided LabVIEW code (not a "picture of VIs", but actual, complete VIs so we can "see for ourselves" what/how you plan to do things, and (b) you haven't given us enough details about the nature of the signal(s) you are using, including such things as "desired sampling rate".

 

It appears (to me) that the "signal of interest" is probably an analog signal, since you give a threshold of 0.02 V (which doesn't make a lot of sense for a digital signal).  If so, you'll want to sample it at equal time increments, say 1 kHz, and DAQ devices have quite accurate clocks that make it fairly simple to sample 1000 points at 1 kHz and deliver them to you once/second.  You also have a full second until the next 1000 points arrive to see if any of the previous 1000 points pass your threshold, but you will likely find out half-a-second after the fact.

 

On the other hand, you can take single samples, test for threshold, and start your sampling when you find the threshold.  That means you've got a software loop "spinning", waiting for the threshold to occur.

 

Or you build a (physical) Trigger circuit that makes a Digital (TTL) Pulse when the threshold (which you could provide using an Analog Output signal)  is achieved.  [Actually, depending on the DAQ devices you have available, you might be able to do this in a LabVIEW "Trigger loop", running in parallel with the main VI, and use this to start the "real" A/D conversion of 1000 points at 1 kHz].  

 

Sometimes when I'm thinking about how I might handle problems posed on the Forums, such as yours, I do a little "free association" and come up with other ideas in the middle of the paragraph, as in the previous paragraph.  One of the very nice things about LabVIEW is how easy it is to build little test routines and "try them out."  I don't pretend to "know the answers", but over the years, I've gotten pretty good at figuring out how to "try things out" ...

 

You might consider posting your code so we can make more "focused" suggestions.  As many of the long-time LabVIEW users do not upgrade every year, please "Save for Previous Version" and specify LabVIEW 2019 or 2021.

 

Bob Schor

0 Kudos
Message 3 of 5
(507 Views)

really sorry I meant to send it as a snippet not a picture here is the file 

0 Kudos
Message 4 of 5
(501 Views)

Thank you for the code.  Looks like my "guesses" were basically correct -- I even got the sampling rate right.

 

You are sampling 100 points from 1 channel at 1 kHz, so every 0.1 s, you get 100 points, one of which might be > 0.02 (units).  You want to save data starting with the first point that is > 0.02 for some number of points (or some other ending condition) -- for simplicity, lets say 1000 points.

 

Here's a (relatively simple) way to do this.  People have mentioned a "Producer/Consumer Design Pattern" to you before -- this is a pair of loops running in parallel, with one (the Producer) sending data to the other (the Consumer) to "do something intelligent with it because I don't have time to bother with it".

 

[Oh -- before I forget -- get rid of the 100 ms wait inside your DAQmx Read (Producer) Loop.  The "clock" inside the DAQmx device is much more precise than the PC's millisecond clock, which can be delayed by all kinds of frivolous PC "affairs".]

 

So you have a Loop that gets 100-point Data Packets and send them via a Queue or a Stream Channel Wire (my preference) to another freely-running Loop, the Consumer, which does the Processing.  What does the Consumer need to do?

 

To begin with, it needs to know whether it in in the "sub-threshold" or "post-threshold" case, i.e. if it already has "seen" data > 0.02.  Let's assume sub-threshold.  So it needs to look at the 100 points and decide if any are > 0.02.  It also needs to decide the first one > 0.02.  That's a fairly simple test -- a loop that returns the index of the first point > 0.02, or -1 if no such point exists.

 

So now you have some data that are post-threshold.  Save them somehow, and in subsequent calls to this Consumer, add the new points to the end of the collection until you've got the right number of points, then do whatever you need to do with the entire collection.  Note that this might well require another Producer/Consumer design, with the current Consumer (I'll call it Consumer 1) acting like Producer 2 and sending the "assembled post-threshold data" to Consumer 2 to plot, save to disk, run FFTs, whatever.

 

Some subtle problems with your current code:

  • Your DAQmx Read outputs a Waveform (a good choice).  The key element is an Array of Data ("Y").  You compare this with a Boolean (0.02) and get a Waveform (another Array) of Booleans.  So you could have an array of 100 F, an array of 100 T, or an array of a mixture of T and F, not very helpful or useful.
  • It appears to be a little-known fact that more than a decade ago, NI made Boolean Functions accept the Error Line as an input, so you don't need to unbundle the Status line, you can just wire the Error Line into an Or function with the Stop Button.  [I think this feature only works with the Error Line...].
  • I always found Notifiers to be tricky ...

Bob Schor

 

0 Kudos
Message 5 of 5
(460 Views)