06-18-2019 02:21 AM
I want to detect peak from the analog input, and once there is a peak, output a pulse immediately. but it seems that the while loop obtains a certain number of sample one time, how can it output pulse immediately?
Solved! Go to Solution.
06-18-2019 02:28 AM - edited 06-18-2019 02:28 AM
Hi frogliang,
it seems that the while loop obtains a certain number of sample one time
Which while loop are you talking about?
Mind to share your VI?
how can it output pulse immediately?
How are you detecting "pulses"? How do you define a "pulse"?
Some DAQ devices allow to trigger DAQmx tasks based on AI signals: which DAQ hardware do you use?
06-18-2019 02:43 AM
hi GerdW,
thank you!
I use the structure as the peak detector sample shows. I need to do some calculations base on the peak value and then trigger a voltage output pulse that is 1ms duration and 1.5V.
best regards
Liang
06-18-2019 02:44 AM
and forgot to mention that the device I use is myDAQ. thank you!
06-18-2019 03:01 AM
06-18-2019 06:57 AM - edited 06-18-2019 06:58 AM
Hi Liang,
As was already described by GerdW, the loop can only iterate (go to next loop iteration) once the elements inside have finished running - i.e. in your case, every 100/sample rate seconds.
If you read 1 Sample per iteration, it will be faster, but you may hit buffering issues if the loop cannot run fast enough to keep up with the acquisition (sample rate). If you don't connect a number of samples, it will read all available samples and return more or less immediately (but preventing buffer problems).
Note that you can also use Greater Than (with Element comparison mode) and Or Array Elements to detect if anything was higher than a threshold value. This won't tell you when the event occurred, but since it's already in the past, you probably don't care - you just want to find out as fast as possible. In the case of a single sample per iteration, you won't need the Or Array Elements either.
You'd have to test, but I'd guess that you might have a faster acquisition loop (once you have it set up) if you keep the DAQmx Write node in a separate loop and use something like a notifier to trigger the output. This might (but test - I don't know) make your input more responsive (because it won't be constantly writing the same low value to the output). It might also make your block diagram tidier, which in some cases is even worth a tiny bit of inefficiency if it is not faster. Your choice (but test!)