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: 

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 12
(2,973 Views)
Hi,

If you are concerned about losing data, then you can do a continuous acquisition which is going to be buffered automatically by DAQmx. Then you can do the calculations on this data outside of the while loop once it is acquired. You can also post your code, so that I can take a look at it. I may be able to show you an example of what you are trying to do based on the code you post. Have a Great Day!

George
0 Kudos
Message 2 of 12
(2,919 Views)
Hello,

Thank you very much for your help. Here is my code. There is something wrong with it. I used shift register of the do while loop. but it seems that the some data is missing from the output of the "previous data" because the reading of the previous data is the same as the reading as the "the present data". It would be very appreciated if you could have a look at it.

Thanks again,
Frank
0 Kudos
Message 3 of 12
(2,906 Views)
Is there anyone can reply this? I have similar question too.Thanks.
0 Kudos
Message 4 of 12
(2,881 Views)
I don't understand what you're doing with the index array. You're reading 1000 points at a time from DAQmx Read, yet you have scalar values for previous data and present data, as the output of an index array that has no index wired (this will give you the first value in the array).

The DAQmx Read will return continuous data with no gaps, yet since your present/past data calculations are only operating on the first point returned by each read. I think this is why you're not getting the desired results.

Joe
0 Kudos
Message 5 of 12
(2,872 Views)
Thanks for your reply. Then if I need to get every value in a array and the comparison between two values, how can I do it?

Thanks,
0 Kudos
Message 6 of 12
(2,864 Views)
You have not explained what you are trying to accomplish. The way you have your program set up, every iteration of your while loop you will have 1000 data points returned from the read, and the previous 1000 points coming out of the shift register. Explain what type of comparison you want to do between the two arrays, and I'm sure someone will be able to help you out.

Joe
0 Kudos
Message 7 of 12
(2,857 Views)
Okay, here is what I need to do.
We need to compare two consecutive samples in one array not comparing two arrays. the logic is like this:

We need to count the pulses in a data stream got from Daqmx. The pulses are determined by the conditions:
IF voltage>= threadshold voltage AND the previous voltage < threadshold voltage.

It looks like the shift register function can't not do this, Is there any other way that I can get two consecutive samples in a data stream? What if I need to read 8 channels and do the same pulse counting in each channel?

Thanks,
0 Kudos
Message 8 of 12
(2,853 Views)
You probably need to pass the array output of DAQmx Read into a for loop, and compare adjacent elements. Send the last sample from the array into the shift register to compare against in the next iteration of the while loop. Alternatively, read a single sample at a time from DAQmx Read (instead of 1000), and you can possibly keep more of your existing logic intact.

Joe
0 Kudos
Message 9 of 12
(2,836 Views)
I did try to read 1 sample at a time, but the readings are still not right. The present data reading and the previous data reading are still the same. Why is that?

Thanks for your reply.
0 Kudos
Message 10 of 12
(2,834 Views)