Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems when using for loop to control total DAQ sampling time

The task is to continuously collect analog data for 20 seconds and display the signal every one second. The labview code I borrowed from NI example database is attached.
 
the sampling rate was set as 1000 Hz and the samples per channel was set as 1000 as well. The for loop will cycle for 20 times before stop. My expectation is that each cycle takes 1 second exactly and total sampling time will be 20 seconds. But when the code is running, one loop cycle only takes about 0.5 seconds. If the sampling rate and samples per channel are changed to 100, then each loop cycle only takes 0.05 seconds and the DAQ finishes in 1 second instead of 20 seconds.
 
I do not how exactly the DAQmx read function works. Can I control the total sampling time by using for loop? 
 
Please help and thanks a lot.
 
BTW, I am using NI USB 9233 for DAQ.
0 Kudos
Message 1 of 7
(3,496 Views)
0 Kudos
Message 2 of 7
(3,488 Views)

the sampling rate was set as 1000 Hz and the samples per channel was set as 1000 as well. The for loop will cycle for 20 times before stop. My expectation is that each cycle takes 1 second exactly and total sampling time will be 20 seconds.
Wheather you use a For or While loop, each acquisistion loop should take 1 second for the above mentioned values of Sampling rate and Number of samples /channel
 
Had you created a simulated DAQ device on your hardware?? You sure you are not calling that device's ID in this vi??
Do check if you are acquiring from the correct Physical channel on your DAQ device USB 9233
 
Also see if replacing the For with a While loop makes a difference and let us know
0 Kudos
Message 3 of 7
(3,470 Views)

Hi,

Thanks for the reply.

I did use a physical NI USB 9233. There is no simulated device installed.

I tried WHILE loop this morning and got same problem.

If the sampling rate is one of the following: 2K, 5K and 10K Hz, then the sampling time will be 1 second. Other than those rates, the sampling time will be unpredictable.

Thanks again for the help.

 

 

0 Kudos
Message 4 of 7
(3,466 Views)

A few things:

Your acquisition will start as soon as you call DAQmx Start - the read just pulls X # of samples from the PC buffer whenever it is called. The total time it will take to acquire 20,000 samples at 1000 S/s is going to be 20 seconds - this does not mean that each loop iteration will take exactly 1 second. So if you find the time difference between when you call DAQmx start and when you exit the loop, your time should be close to 20 seconds (plus some start up time for DAQmx Start). Most loops will run at 1 second, but things can change this: if one loop runs longer due to extra processing or Windows being Windows, the DAQ card will continue to fill the buffer, and the next DAQmx Read will not have to take 1 second to pull from the buffer because the samples are already there. So that next loop could be less than a second. You could see this on the first loop iteration as well - since the DAQmx Start is called before the loop starts, there will be samples already in the buffer when the DAQmx Read is made.

If you want to have it less dependent on the system, you can use one of the wait functions to control the loop timing.

Hope this helps, please post back if you have additional questions.

Cheers,

Andrew S

National Instruments

 

Message Edited by stilly32 on 06-06-2007 03:18 PM

0 Kudos
Message 5 of 7
(3,450 Views)
darkblue,
 
I think what you are seeing can be explained if you look at the specifications for your device (9233) here:
 
If you take a look at the input Specifications->Input Characteristics, you will notice that there is a finite set of available sample rates.  The slowest internal sample rate available is 2 kHz.  What I suspect happens is you select a rate below this, and the driver picks the sample rate which is most appropriate for the rate you requested, in this case 2 kHz.  To verify this, you should be able to use the DAQmx Timing property node and read back the Sample Clock -> Rate property.
 
Hope this helps,
Dan

Message Edited by Mcdan on 06-06-2007 05:25 PM

Message 6 of 7
(3,443 Views)

Thank you all for the replies.

I did not realize that NI 9233 only accept certain sampling rates like Don just pointed out. I tried for those sampling rates and all worked well. I also found out when a sampling rate that is not in the list will be automatically coerced to the next available one in the list.

Thanks again for the your help.

0 Kudos
Message 7 of 7
(3,416 Views)