Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Question about DAQ sampling

Solved!
Go to solution

I am wondering, if I set the DAQ for continuous sampling and set the rate to say, 1 khz, then I read a single sample DBL value within a loop, what am I reading at that sample? Is it an average of the sampling that the DAQ carried out at the set rate? I am simply trying to monitor analog voltages on 9 channels. What is the point of setting a sampling rate on the DAQ if I'm just reading a single sample?

 

Should I set it to "N channel N samples" to take advatage of this setting that was done on the DAQ hardware? See below screen shot of code. Thanks.

bbbbbbbbbb.gif

0 Kudos
Message 1 of 9
(5,032 Views)

In the code you posted, the data would be sampled at 2 kHz, with the sample clock derived by the oscillator on the DAQ card.  The software would read back 1 point at a time from the buffer of acquired data.  If the software cannot keep up with the 2 kHz sample rate, then you be reading old data (and you will eventually get a buffer overflow error).

 

If you only care about the most recent sample and don't need an exact 2 kHz sample rate, you could remove hardware timing altogether.

 

 

Best Regards,

John Passiak
0 Kudos
Message 2 of 9
(5,019 Views)
Unless the board supports hardware timed single sampling and unless you explicitly select that, when you do 1 sample, you are doing software timed acquisition and the sample rate is whatever your loop iteration rate is. There is no averaging.
Message 3 of 9
(5,003 Views)

You can still read 1 sample at a time and use a hardware-timed buffered acquisition (hardware-timed single-point is non-buffered).  The data will accumulate in the DAQmx buffer and the loop will iterate no faster than the sample rate on average (since the read call will block until a new sample is available).  For fast rates this wouldn't work since the loop wouldn't be able to keep up if it is only removing 1 sample at a time from the buffer.

 

I actually didn't notice this but the original screenshot is clearing the DAQmx task inside the loop--that's wrong no matter how the task is configured.

 

 

Best Regards,

John Passiak
0 Kudos
Message 4 of 9
(4,998 Views)

THanks Dennis and John. 

 

I have decided that I would like to allow for setting the hardware sampling rate and then reading the data in the loop as "N channel N sample 2D DBL."  

 

The only issue I'm having with this approach is how my .csv file is now being saved. I am indexing the 2D array coming out of the read function such that each row (correspondin to each DAQ channel) is being separated. I perform some scalar operations on the values then attempt to concatenate it all back into an array and write to spreadsheet file. Instead of a nice spreadsheet where each column of data represents each channel of the DAQ, like I got when I used single sample, I'm getting this massive spreadsheet with many rows and columns. I'm trying to figure out whats going wrong. The write to spreadsheet is being used iteratively (append mode). Please see attached code and screenshot. I've tried some reshaping approaches but I can't get this to work.

 

THanks

vvvv.gifhh.gif 

0 Kudos
Message 5 of 9
(4,997 Views)

I thought we answered that already (here).  Just take the average of each of the channels after you index it to get one point per channel.

 

 

Best Regards,

John Passiak
0 Kudos
Message 6 of 9
(4,992 Views)

Yes that was the original approach, however, we decided that we need more data. We don't want to filter it further by averaging any of it. 

 

Ideally I'd like to have this 2d DBL data end up in a final .csv representation where there are n columns representing n DAQ channels. I'm wondering how I might acheieve this. Thanks.

0 Kudos
Message 7 of 9
(4,990 Views)
Solution
Accepted by topic author Snow_In_Tehran

Transpose the data going into the Write Spreadsheet File VI.  There is a boolean input to the function that does this.

 

 

Best Regards,

John Passiak
Message 8 of 9
(4,983 Views)

Thanks. I knew this was a simple solution. I also applied a transpose 2D array at the output of the read function so that it would give me a corresponence between channels and columns as opposed to channels and rows. 

0 Kudos
Message 9 of 9
(4,981 Views)