DAQmx Timing and Sample Rates

Updated Aug 1, 2018

Reported In

Driver

  • NI-DAQmx

Other

NI DAQ

Issue Details

I am performing basic data acquisition using the DAQmx Timing function.  How does the sample clock relate to how fast my data is read?

Solution

There are two aspects to reading data: how quickly the real world signal is digitized (how fast?) and how much data is retrieved by software at a time from the hardware FIFO (how much?).  These hardware-software configurations are codependent on each other.  

On the hardware side, the DAQmx Timing function determines the rate of data flow from the device/sensor to the hardware FIFO on the data acquisition board. On the software side, the DAQmx Read function determines the transfer of data from the PC buffer into the software. See figure below:



Part 1: From Device/Sensor to Hardware FIFO on the DAQ Board 

Overview
The DAQmx Timing function controls the number of and rate at which samples are acquired from a device. This function operates in three different sample modes: finite, continuous, and hardware timed single point. Which mode you select affects the number of samples acquired.
The DAQmx Timing  function is polymorphic; the instance discussed here is Sample Clock. For more information on the other instances of DAQmx Timing, see DAQmx Help

How Much?
For finite acquisition, the Samples Per Channel input of the DAQmx Timing function determines how many samples are read on each channel.  In other words, Sample Per Channel sets the size of the chunk of data that will be collected.
For continuous acquisition, the Samples Per Channel determines the size of the PC buffer designated for each channel.   

How Fast?
The Rate input of the DAQmx Timing function determines how fast the samples are acquired and put on the hardware FIFO.  The value specifying the rate is dependent on the timebase specified in the source input of the DAQmx Timing function.  The rate specified must be a division of the source. For example, the default source on the X Series cards is the onboard clock (100MHz).   For more information on achievable acquisition rates, refer to KnowledgeBase article 39BCDJMV and 27R8Q3YF, or page 9-1 of the X Series User Manual for more information.

Part 2: From Hardware FIFO to PC Buffer and Programming Environment

How Much?
The Number of Samples Per Channel input of the DAQmx Read function determines how many samples are pulled from the PC buffer to the programming environment. The selected data transfer mechanism (DMA, Interrupt Requests, Programmed I/O, or USB bulk) determines how the samples are actually brought from the hardware FIFO to the PC buffer. Refer to NI-DAQmx Help: Data Transfer Mechanisms for more information. When using the Programmed I/O method, the DAQmx Read function takes samples directly from the hardware FIFO itself. When using all other transfer mechanisms, which are hardware timed, it is recommended that the number of samples be 1/10th the rate specified on the DAQmx Timing function.  For example, if the rate input on the DAQmx Timing function is 1000 (Hz), then the number of samples per channel on the DAQmx Read function should be no more than 100. This is to ensure there are not PC buffer overwrite or underwrite errors.  
Note: The Number of Samples Per Channel input is only available on the DAQmx Read function if the function is configured to read multiple samples. 
If Number of Samples Per Channel is -1, unwired, or not set while the acquisition mode is Finite (acquisition mode is an input for the DAQmx Timing function), then the DAQmx Read function will wait until all the samples in the finite acquisition are in the PC buffer and then reads them in.  If the acquisition mode is continuous, then all the samples currently available in the PC buffer are read. 
                
How Fast?
When performing Programmed I/O, the rate at which the samples are read from the hardware FIFO on the DAQ board to the programming environment is dependent on how often the Read function is called. Since the DAQmx Read function is often in a while loop, the loop rate will determine how often the DAQmx Read function is executed.  The speed of the software will also be dependent on the speed of the processor and the number of processes occurring at a time. When using the other data transfer mechanisms, the speed at which the samples are brought into the PC buffer from the hardware FIFO are independent of the execution speed of the program. For this reason, it is often desirable to use non-Programmed I/O mechanisms, which enforces the use of the PC buffer, so that multiple samples can be preserved in time for the DAQmx Read function to read.

Summary
When determining how fast your data will be acquired, keep in mind that both steps in the acquisition must agree. The rate at which the data is transferred from the hardware FIFO to the PC buffer must not be too fast or too slow compared to the rate at which the data is being loaded into the hardware FIFO itself.  If it is too fast or too slow, a PC buffer error will be thrown. Refer to Understanding and Avoiding Overwrite and Overflow Errors with NI-DAQmx for more information about buffer errors.
 

WAS THIS ARTICLE HELPFUL?

Not Helpful