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

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


Feedback


Yes No

Related Categories

Related Links - Developer Zone

Related Links - Products and Services

Using DMA FIFO to Develop High-Speed Data Acquistion Applications for Reconfigurable I/O Devices

14 ratings | 3.93 out of 5
Print

Overview

The LabVIEW 8 FPGA Module improves data transfers by up to 20X for developing high-speed buffered data acquisition applications for Compact RIO or R-Series devices. FPGA FIFOs can now be configured for Direct Memory Access (DMA). This allows the FPGA to use the host RAM as if it were its own. This offers significant performance enhancements over using the traditional Local FIFO and reading indicators using the FPGA Host Interface VIs for transferring data from the FPGA to the host.

DMA transfers are accomplished by using a FIFO architecture. The FIFO is composed of 2 parts that behave as one FIFO. The first part of this FIFO is on the FPGA device. This FIFO uses block RAM on the FPGA device. The second part of the DMA FIFO is on the host machine. This portion of the FIFO uses memory on the host machine. A DMA engine automatically transfers data from the FPGA device RAM to the host machine memory.

This document describes the steps necessary to create a simple yet fast buffered, multi-channel, simultaneous data acquisition application using DMA to transfer data between the FPGA and the Host.

Create The Project

After opening LabVIEW 8.0, choose to create an Empty Project. Add the FPGA device by right-clicking on My Computer, and choosing New>>Targets and Devices. Find the FPGA Target you wish to program, and add it to the project.

Your project should look similar to this:


To add a blank VI for the FPGA, right-click the FPGA in the Project Explorer and choose New>>VI. Open Up the block diagram of this blank VI.

Create a FIFO


For our FPGA VI, we would like to acquire data from an analog input channel, and write this data into an FPGA FIFO to implement the DMA transfer.

To create the FIFO, right-click the FPGA Target again and choose New>>FIFO.



The FPGA FIFO properties window will appear. Here we can name the FPGA FIFO, and configure it for DMA. For this example program, we will name the FPGA FIFO “Data”. To use DMA, click the pull-down menu in the Transfer box, and select DMA. This is different than Local since the data within the RAM used by a DMA FIFO is transferred directly to the host machine.

Notice that the FPGA FIFO only supports U32 (unsigned 32-bit integer) datatypes and only certain depths are available. To save resources, choose the smallest size that is reasonable for your application. This is done by comparing the rate at which data points are put into the FPGA FIFO to the rate at which the Host application will be able to read points out. The slower the Host VI is compared to the FPGA VI, the larger a FIFO you will need to allocate. For the purposes of this application, let’s use a depth of 4095.

The FPGA VI


The attached VI, fpgaAcquire.vi, runs on the FPGA target.



Following the block diagram above, four channels of analog input are sampled simultaneously. The resulting 16-bit numbers are combined into an array. The array is passed into a For Loop. The For Loop indexes through each element of the array and passes the data into a DMA FIFO sequentially with a timeout of 5 ticks. This means that if the DMA operation takes longer than 5 ticks, the data value will not be written. This would appear as data switching between channels. In this case, increase the timeout or add a while loop which tries to write as long as the value returned from Full is true. If Full is frequently true, then increasing the size of the DMA FIFO buffer will help.

The overall loop rate is set by the Count (uSec) control which sets the period.

Implement DMA on the Host Side


DMA uses a programming flow similar to many communication/acquisition techniques used in LabVIEW. This is done using an Invoke Method Node found on the FPGA Interface Palette. To use FIFO methods, note that the FIFO name “Data” appears at the top of the list of methods when left-clicking the node.

Note: You must first configure the Open FPGA VI Reference function and wire the output of this function to the FPGA VI Reference input of the Invoke Method Node to see the available DMA FIFOs and methods.



To the right of the FIFO names are the available methods, in order of proper programming flow. Similar to a DAQ task, we begin by configuring the FIFO on the host and starting the DMA. Then in a loop we can read from the FIFO until the stop button is pressed. Outside the loop, we execute the Stop method to make sure all allocated resources are freed. Below is an example:


[+] Enlarge Image

The DMA methods configure, start, and stop are optional methods. The DMA read method is the only required method to read data from a DMA FIFO. If only the Read Method is used the host side memory is configured to a size twice as large as the FPGA device side memory. Also the read method will automatically start the DMA transfers on the first read. DMA transfers are stopped when the Close FPGA VI Reference function is called.

Note the parameters of the Read method:



Number of Elements indicates how many elements are to be read. The function will complete when this many elements are acquired, or the Timeout is exceeded, whichever comes first. The same amount of overhead is associated with reading a few elements as with reading many. For applications in which the host loop is much slower than the FPGA loop, it is better to read more elements at a time. By monitoring the Elements Remaining output, one can determine if the host loop should be run at a faster rate or if more samples should be read per loop iteration.

Note: The Elements Remaining output returns the number of elements remaining in memory on the host machine. This does not return the number of elements remaining in the FPGA device RAM.


[+] Enlarge Image

The rest of the host application de-interlaces the 32-bit array to get four arrays that represent the four channels and are converted to signed 16-bit integers, double, and then recalibrated to reflect the full +/-10V range of the FPGA target.

Using DMA, it is easy to create a fast and intuitive data acquisition application for R Series or ComapctRIO FPGA hardware. This makes it even easier to create customized hardware for control or monitoring at high speed with deterministic behavior.

Downloads

riodataacqdma.lvproj

hostread.vi

fpgaacquire.vi

14 ratings | 3.93 out of 5
Print

Reader Comments | Submit a comment »

DMA Host-to-FPGA
Host-to-FPGA DMA was implemented in LabVIEW FPGA 8.2 http://zone.ni.com/reference/en- XX/help/371599B- 01/lvfpgahosthelp/fpga_writing_dma/
- Oct 23, 2007

NI fails to mention that FIFOs are NOT implemented for communications from the RT to the FPGA. It currently only works in reverse as per this document.
- Peter Badcock, ResMed Ltd. peterba@resmed.com.au - Mar 22, 2007

NI fails to mention that FIFOs are NOT implemented for communications from the RT to the FPGA. It currently only works in reverse as per this document.
- Peter Badcock, ResMed Ltd. peterba@resmed.com.au - Mar 20, 2007

DMA RT to FPGA?
What about a DMA example that is for a host to target (RT to FPGA)?
- Greg Larrabee, SSS, Inc.. greg.larrabee@simsuptsvcs.com - Mar 1, 2007

okay start, but
This is an okay start, but it doesn't indicate how to connect the board to anything other than LabView. I was hoping for links to manuals and other information. How about some throughput values?
- Nov 11, 2005

 

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/).