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: 

How to set the sampling interval using DAQ device?

Solved!
Go to solution

Now I have a capacity sensor and a 24 bit DAQ device (http://www.mccdaq.com/usb-data-acquisition/USB-2404-10.aspx).

The DAQ device has the maximum sampling rate of 50kS/s . My question is how to set the interval of data collection. For example, if I set the sampling rate to 2000, in continuous sampling mode, I use DAQmx read.vi in a while loop and set the 'number of samples per channel' to 100. I want to plot these data as a function of time by using a XY graph and also save these data. So I add a 'Mean' function to get the average of the 100 samples per each loop (than means, there are 20 data output per second). But when I set the 'number of samples per channel' much smaller (to get more data per second), there are some problems. It seems that the program cannot read so many data and get the average at a higher frequency. I don't know where the problem is. All in all, how to collect data more frequently?Maybe I didn't express my question clearly. I'll upload a simple program later if necessary. Thanks.

 

0 Kudos
Message 1 of 11
(4,728 Views)

Sorry, I just write a simple program, as describe above. My actual program is much more complex than this.

Thanks.

0 Kudos
Message 2 of 11
(4,726 Views)

If you want to speed up your acquisition, you need to change the sampling rate not the number of samples you're reading at a time.

 

The number of samples to read refers to the number of samples you are going to empty from the buffer at that time.  A good rule of thumb is to read at 1/10th of your sample rate - that is if you are sampling at 2000 Hz, read 200 samples at a time and let your loop run at 10 Hz (for some reason this seems to work really well on Windows machines).

 

The problems you are running into come when you are either not reading samples off of the buffer fast enough, so they get overwritten (overflow) or you are reading them too fast and then your read is timing out (underflow).

Chris
Certified LabVIEW Architect
Certified TestStand Architect
0 Kudos
Message 3 of 11
(4,714 Views)

Hi Chris,

 

Thanks very much for your reply.

So you are suggesting that samples to read per one loop is 1/10 of the sampling rate, to avoid over flow or under flow?

And I should increase the sampling rate (say, 20000 Hz) and also the samples to read (should be 2000) at the same time, if I want to speed up acquisition?

But should I still do the average calculation? If so, I can still output only 10 data points in 1 second. How to output more data points per second? Thanks.

 

 

0 Kudos
Message 4 of 11
(4,707 Views)

1/10th should help ward off both underflow and overflow, though I suspect that you are seeing overflow.

 

Yes, you should increase both in concert.

Chris
Certified LabVIEW Architect
Certified TestStand Architect
0 Kudos
Message 5 of 11
(4,699 Views)

Thanks.

I'm not sure if this is overflow, when I set sampling rate to 2000Hz and samples to read to 20, then I observed the data we collected is somehow delayed with the actual input. That means, I want the while loop to be operated at 100 Hz, but actually it cannot. Am I right?

 

So now I understand the rule of thumb about the sampling rate and samples to read. But how can I output (using Write to Spreadsheet File) the data at a higher frequency? If the 1/10th is adopted, then I can only get 10 data points per second after I do the average. I cannot output all the data without using the average value, i.e. 2000 data points per second. That should too large. It seems kind of self-contradictory.

0 Kudos
Message 6 of 11
(4,695 Views)

Anyone helps me out?

0 Kudos
Message 7 of 11
(4,675 Views)

Hello

 

-          In continuous acquisition: Sampling rate: As Chris told you this value specifies how frequently the DAQ is going to take a value from the signal and it is going to put that information in the buffer.

 

-          Samples to read: The DAQmx read function waits for this amount in the buffer to take out the information from the buffer. For example if you specify 50, once you have 50 values in the buffer, the DAQmx read is going to put in the output these 50 values, and the buffer is cleared.

 

-          Samples per channel: In continuous mode, NI DAQmx uses this value to determine the buffer size.

http://digital.ni.com/public.nsf/allkb/E1E67695E76BA75B86256DB1004E9B07

 

-          Now you are calculating the mean value for your samples to read for EACH iteration in the while loop.  How many iterations you are going to have, well: (rate) / (samples to read) per second. You can play with this formula to increase the information that you want to write in the file. You need to take care of the buffer size!!

 

          Regards

0 Kudos
Message 8 of 11
(4,651 Views)

Thanks.

Yes, the time of iteration is exactly what I'm concerning about. Theoretically, it should be  (rate) / (samples to read) per second. But I think it also depends on the computer processor and should exist an maximum limit.

If the iteration cannot be processed fast enough, the data in the buffer cannot be read out fast enough, then the buffer will be overwritten or overflow. Am I right?

Is the 1/10 rule of thumb also considering into the frequency of iteration?

0 Kudos
Message 9 of 11
(4,644 Views)

Another question is in continuous mode, NI DAQmx uses Samples per channel to determine the buffer size. But according to the website you specified, it says if the acquisition is continuous (sample mode on the DAQmx Timing.vi is set to Continuous Samples), NI-DAQmx will allocate a buffer according to the following table. And for sample rate between 100 - 10,000 S/s, the buffer size is 10 kS. So if I set the sample rate to be 5000 S/s, and set the Samples per channel to be 20000, then what exactly the buffer size is? 20 kS or 10 kS?

Thanks.

0 Kudos
Message 10 of 11
(4,641 Views)