Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to record data every n seconds?

Hi,

Here are what I want to do:
1. Measure data from multiple channels;
2. For every m data points, calculate mean etc.;
3. Record the mean and the corresponding time;
4. Wait n seconds, measure another m data points.

The attached is my vi file. My questions are:
1. Assume that the sample rate is defined as 1024, the number of channels is 8, and 1024 samples are measured for each channel. Is the total time required for measurement 1 second (1024/1024) or 8 seconds (8*1024/1024)? I checked the data file, and time interval is 1 second. Why?

2. If the waiting time is set as 0, the time interval between every data record is 8 seconds. Now the waiting time is set as 10 seconds, is the time interval between every data record 10 seconds or 18 seconds (measurement time + waiting time)? Again, I checked the data file, and time interval is 10 seconds. Why?

Thanks,
Bei 
0 Kudos
Message 1 of 8
(4,452 Views)

Hi Bei,

What hardware are you using?

The DAQ card has 2 clocks – a samples clock and convert clock. The convert clock is how fast the multiplexer will run each time the sample clock ‘clocks’ in a value. The acquisition will take 1 second (1024 samples / 1024 samples/s ) because this convert clock will run through all lines each time the sample clock ‘clocks’.

For your second question, I believe the entire loop will take 18 seconds if your ‘time to wait’ is 10. If your code takes 8 seconds without a wait (or ‘time to wait’ = 0 ) – this sounds like a long time for what you are doing, than this is the minimum execution time your code will take to run. Adding a ‘wait(ms)’ timer with a value of 10,000 in its own frame of a flat sequence will add 10 seconds to the time, forcing the entire code execution to take 18 seconds. See picture below for an example of how you can determine how long your code takes to run. It takes the current time (in ticks) and subrtracts the previous time from it, resulting in the amount of time the code took to run.

Please also be careful of how you code, as currently you have the DAQ setup to do finite samples, but are continuously reading – this will throw an error and must be changed to either read once or do a continuous acquisition.


Message Edited by David L. on 07-25-2007 05:55 PM

David L.
Systems Engineering
National Instruments
0 Kudos
Message 2 of 8
(4,424 Views)
Hi, David,

Thanks for answering my questions. The DAQ device I use is USB 6009.

By the way, I want to do batch measurement. Every time, x samples are read, and the time between two measurements is n seconds. The attached is my revised block diagram. The sample mode will be set as "Continuous samples", but the number of samples per channel for the DAQ Read will be set as x. Is there problem for this setting?

Thanks,
Bei

Message Edited by Qifu on 07-25-2007 06:28 PM

0 Kudos
Message 3 of 8
(4,422 Views)

Bei,

At a glance, the code looks much better. One note – when doing continuous acquisition, the card is continually acquiring and filling up the buffer. Just because we read every 2 seconds does not mean that the card only does an acquisition every 2 seconds. Because of this, depending on the sample rate, you will eventually get a buffer overflow because the card will be filling up the buffer faster than we are reading samples out of it.

For your application, since timing is not a big concern, the easiest way to accomplish what you would like is to bring all of the DAQmx code inside the while loop or create a DAQ assistant to perform the same functionality and eliminate the low level DAQms VI’s. This will start, acquire, and stop the task each iteration of the while loop, therefore only taking 1024 samples and then waiting n seconds before doing it over again.


Also, below is updated code on how to measure the time your while loop takes. I was slightly mistaken last post.


Message Edited by David L. on 07-25-2007 07:37 PM

David L.
Systems Engineering
National Instruments
Message 4 of 8
(4,417 Views)
Thanks. I will put all of the DAQmx code inside the loop.

If we read the data every 2 seconds, will we get the newest data or the oldest in the buffer? I'm just curious.

Bei
0 Kudos
Message 5 of 8
(4,409 Views)
By putting the DAQmx code inside the while loop, you will get fresh 1024 samples (the newest data) every time, as clearing the task also clears the buffer.
David L.
Systems Engineering
National Instruments
0 Kudos
Message 6 of 8
(4,404 Views)
I understand the case of putting the DAQmx inside the loop.

How about my code in the second post? I put them outside the loop. Will I get the newest samples in the buffer?

Bei
0 Kudos
Message 7 of 8
(4,402 Views)

No. If we do not start, read, and stop the task inside the while loop, only having the DAQmx read inside the while loop will give us ‘old’ data. This is because the data will continue to be acquired from the beginning, but you are only reading it every two seconds. The buffer will hold the old data until it is read out.

David L.
Systems Engineering
National Instruments
0 Kudos
Message 8 of 8
(4,370 Views)