Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Document Type: Tutorial
NI Supported: Yes
Publish Date: Sep 6, 2006

Continuous Waveform Acquisition

20 ratings | 3.15 out of 5
Print
Waveform acquisition applications that do not have a predetermined number of samples, or that run for such lengths of time that a single buffer of data is too large to practically fit into memory may need to make use of continuous acquisition. In a continuous acquisition, data is placed into a circular buffer by the DAQ hardware. Simultaneously, the software removes previously acquired data from the buffer and processes it. Typical processing operations include mathematical operations, screen display, and file I/O. As long as the software removes data from the buffer at least as fast as the hardware provides it, the circular buffer never fills, and the operation may continue endlessly.

Double-Buffered Input Operations
The data buffer for double-buffered input operations is configured as a circular buffer. In addition, NI-DAQ logically divides the buffer into two equal halves (no actual division exists in the buffer). By dividing the buffer into two halves, NI-DAQ can coordinate user access to the data buffer with the DAQ device. The coordination scheme is simple— NI-DAQ copies data from the circular buffer in sequential halves to a transfer buffer you create.You can process or store the data in the transfer buffer however you choose.

Figure 4-1 illustrates a series of sequential data transfers.


Figure 4-1. Double-Buffered Input with Sequential Data Transfers

The double-buffered input operation begins when the DAQ device starts writing data into the first half of the circular buffer (Figure 4-1a). After the device begins writing to the second half of the circular buffer, NI-DAQ can copy the data from the first half into the transfer buffer (Figure 4-1b). You can then store the data in the transfer block to disk or process it according to your application needs. After the input device has filled the second half of the circular buffer, the device returns to the first half buffer and overwrites the old data. NI-DAQ can now copy the second half of the circular buffer to the transfer buffer (Figure 4-1c). The data in the transfer buffer is again available for use by your application. The process can be repeated endlessly to produce a continuous stream of data to your application. Notice that Figure 4-1d is equivalent to the step in Figure 4-1b and is the start of a two-step cycle.

Potential Setbacks
The double-buffered coordination scheme is not flawless. An application might experience two possible problems with double-buffered input. The first is the possibility of the DAQ device overwriting data before NI-DAQ has copied it to the transfer buffer. This situation is illustrated by Figure 4-2.


Figure 4-2. Double-Buffered Input with an Overwrite Before Copy

Notice that in Figure 4-2b, NI-DAQ has missed the opportunity to copy data from the first half of the circular buffer to the transfer buffer while the DAQ device is writing data to the second half. As a result, the DAQ device begins overwriting the data in the first half of the circular buffer before NI-DAQ has copied it to the transfer buffer (Figure 4-2c). To guarantee uncorrupted data, NI-DAQ must wait until the device finishes overwriting data in the first half before copying the data into the transfer buffer. After the device has begun to write to the second half, NI-DAQ copies the data from the first half of the circular buffer to the transfer buffer (Figure 4-2d).

For the previously described situation, NI-DAQ returns an overwrite before copy warning ( overWriteError ). This warning indicates that the data in the transfer buffer is valid, but some earlier input data has been lost. Subsequent transfers will not return the warning as long as they keep pace with the DAQ device as in Figure 4-1.

The second potential problem occurs when an input device overwrites data that NI-DAQ is simultaneously copying to the transfer buffer. NI-DAQ returns an overwrite error ( overWriteError ) when this occurs. The situation is presented in Figure 4-3.


Figure 4-3. Double-Buffered Input with an Overwrite

In Figure 4-3b, NI-DAQ has started to copy data from the first half of the circular buffer into the transfer buffer. However, NI-DAQ is unable to copy the entire half before the DAQ device begins overwriting data in the first half buffer (Figure 4-3c). Consequently, data copied into the transfer buffer might be corrupted; that is, it might contain both old and new data points. Future transfers will execute normally as long as neither of the problem conditions re-occur.

The most frequency problem with continuous waveform acquisition is that the software fails to remove the data as fast as the hardware provides it. When this happens, an overrun condition occurs. To prevent this from happening, optimize the performance of the software loop that is retrieving the data by increasing the efficiency of the code, and/or removing unnecessary processing. If it becomes impossible to speed the code any further, the data acquisition will need to be slowed.


20 ratings | 3.15 out of 5
Print

Reader Comments | Submit a comment »

 

Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).