Transferring Multi-Channel Data in DMA Applications

If you need to use DMA to transfer data from multiple I/O channels from an FPGA target to a host computer, NI recommends combining the data from each channel into a single array before writing the data to the DMA buffer. Combining data in this way is known as interleaving. Interleaving multi-channel data is useful because transferring the interleaved array requires only a single DMA channel, freeing up other DMA channels for other tasks. After you read the interleaved data from the DMA buffer, decimate the array to retrieve the data for each separate channel.

Note Interleaving works best when data from all channels is the same type. Otherwise, LabVIEW might coerce data when writing to the buffer, which can reduce precision.

Interleaving Data on the FPGA Target

The following figure shows an FPGA VI that acquires and interleaves data.

1378

The VI in the previous figure acquires data from three input channels: AI0, AI1, and AI2. The VI uses the Build Array function to interleave data from these channels into a single array. Finally, the FIFO Method Node writes this single array to the DMA channel. The DMA channel transfers this array one element at a time from the FPGA target to the host computer.

Due to interleaving, the array contains the following elements:

Array Element Data
0 Sample 1 from AI0
1 Sample 1 from AI1
2 Sample 1 from AI2
3 Sample 2 from AI0
4 Sample 2 from AI1
5 Sample 2 from AI2
Note NI recommends setting the number of elements of the buffer to an integer multiple of the number of channels you are interleaving. This design ensures the buffer holds the same number of data points for each channel. In this example, the buffer has six elements, which is enough room for two measurements from each of the three channels.

Decimating Data on the Host Computer

The following figure shows the VI that reads the data on the host computer.

1378

Note the following actions in the previous figure:

  • When reading from a DMA channel, you must specify the Number of Elements to read. To calculate this number in this example, multiply the number of times you sampled each channel by the number of channels. In this example, the number of channels is three.
  • The Decimate 1D Array function has been resized to contain three output terminals; therefore, this function splits the interleaved array into three separate arrays. The first array contains the measurements from AI0, the second array contains the measurements from AI1, and the third array contains the data from AI2.
    Note If you had a fourth channel of data, you would resize the Decimate 1D Array function to include a fourth output terminal.
  • The purpose of the Build Array, Transpose 2D Array, and To Double Precision Float functions is to prepare the data for display on a waveform chart. You can replace these functions with ones that process the decimated data in the way that best fits your application.