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.

Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Fast sampling without losing data (DAQmx)

Hi, there

In my Labview application it is needed to sample as fast as 8000Hz. I used Labview sample file "Cont Acq&Graph Voltage-Int Clk.vi" as a template and made some changes. In the do-while loop, I want to perform some calculations using most recent sample and the previous sample. Based on my understanding, the smallest time interval in loop is about 1ms... so I can't use time delay vi to accurately control the loop executing rate with such a high sampling rate. So what I am about to do is to read 100 samples from buffer very iteration and add a 100ms time delay inside the loop. Then do the calculations with these 100 samples and read the next 100 samples. but How can I make sure that I don't lose any data this way. It seems that the time delay vi is only an approximation... is that true? Does anyone have any idea better than this?

Thank you.
0 Kudos
Message 1 of 2
(2,638 Views)
Hi Frank,

On your DAQmxRead VI you'll see an input labeled "number of samples per channel." Whatever number you wire into this will be the EXACT amount of data points that are returned on each execution of DAQmxRead. This means that if you wire 100 into the "number of samples per channel" you will get an array of 100 data points on each loop execution. Then you can perform your data manipulation on that array of 100. On the next loop execution you will get another 100 data points. Now here's the tricky part...

At 8000 Hz, 100 samples takes 0.0125 seconds. If your data calculations take LESS than 0.0125 seconds, you will have less than the needed 100 data points on the next DAQmxRead execution. Since you specified to read 100 data points, DAQmxRead will wait until all 100 points are ready and then return. If your data calculations take MORE than 0.0125 seconds to execute DAQmxRead will have more than 100 points available when it executes. Now it will only grab 100 data points from the DAQ card's buffer and leave some backlog. The backlog will grow with each loop execution until you get a buffer overflow. The solution to this is to INCREASE the "number of samples per channel" to be read with each DAQmxRead execution.

-Sal
Message 2 of 2
(2,614 Views)