Multirate Analog Output Example DAQ Personality


This document is part of the Introduction to Programming With NI R Series. This FPGA personality gives you the ability to use all eight analog outputs on R Series devices. You can use each analog output channel in either streaming mode or regeneration mode. Streaming mode means that new samples are continuously sent from the host VI to the FPGA and are output as they are received. Regeneration mode means that a block of memory on the FPGA is filled with samples, and then the FPGA continuously indexes through these samples without further host interaction. Currently, no multifunction data acquisition (DAQ) board gives the analog outputs the ability to update at independent rates, and this example personality fills that need.

Download the Multirate Analog Output Example DAQ Personality


LabVIEW FPGA Personality


Note: This personality uses a lot of FPGA resources. Consider a larger FPGA when using this personality as is. ( Virtex-5 LX50, LX85, LX110, or Kintex-7 70T, 160T)

The NI LabVIEW FPGA design code has two main parts: DMA Processing Loops and Channel Processing Loops.

The DMA Processing Loops redirect the data that is sent from the host via the DMA FIFOs. Based on whether the user has selected streaming (default) or regeneration mode, the samples are directed to either a local first-in-first-out (FIFO) memory buffer or to a memory location, respectively, for a particular channel.

All R Series multifunction reconfigurable I/O (RIO) devices have at least three DMA channels. This example personality uses three corresponding While Loops to process the data and redirect the samples. Several channels share each DMA FIFO and all channels within the group update at the same rate; that is, there can be three different rates among all eight channels.

The front panel controls Rate012Rate345, and Rate67 are the number of ticks (using the 40 MHz onboard clock) that the particular group of channels use as a period. For example, if Rate012 is equal to 40,000 then channels 0, 1, and 2 update at 10 KHz (40,000,000/40,000).


Figure 1. FPGA Front Panel


The format for sending data over the DMA FIFO is as follows:

Channels 0, 1, and 2 use DMA Output FIFO 0. Channels 3, 4, and 5 use DMA Output FIFO 1. Channels 6 and 7 use DMA Output FIFO 2. Data sent over incorrect DMA FIFOs is discarded.

Elements are sent over the DMA FIFO as a series:

  • The first element in the series determines the channel (0–7).
  • The second element in the series determines the number of analog output samples in this series.
  • The remaining elements are the analog output samples.


Channel #

N Samples

Sample 1

Sample 2


Sample N


All of the DMA FIFOs on the FPGA have 4,095 elements of type U32.

The DMA Processing Loops use a Case structure for determining which channel is to receive the remaining samples and a For loop for iterating through them. If the channel is in regeneration mode, then the number of samples is written to location 0 of the memory block for that channel.


Figure 2. DMA Processing Loop in Regeneration Mode


If the channel is in streaming mode, then the number of samples is written to the local FIFO for that channel.

Figure 3. DMA Processing Loop in Streaming Mode


The Channel Processing Loops are responsible for writing the samples from either the local FIFO or the memory block to the analog output channel. There are eight channels so there are eight While Loops. Each is responsible for one channel. Two Boolean controls, Pause and Mode, modify the behavior of a given channel.

If a user has selected to pause the channel by setting the Pause control to true, then nothing is written to that analog output channel and new samples received over the local FIFO are discarded. This prevents the DMA FIFO from getting backed up by a single paused channel. Pausing can be toggled dynamically at run time.

If the user has set the Mode control to false, then the channel is in streaming mode. In this case, the samples are taken from the local FIFO for that channel and written to the analog output channel. If no samples are available in the FIFO, then the loop continues and writes out the last value that it did receive. This functionality is obtained by wiring a numeric constant with value 0 into the FIFO read.


Figure 4. Channel Processing Loop in Streaming Mode


If the user has set the Mode control to true, then the channel is in regeneration mode. In this case, the processing loop for that channel iterates through the memory block rather than the local FIFO. It compares a numeric index against the value in address 0 of the memory block (the total number of samples) and increases by one if they do not match. If they do match, then this Channel Processing Loop has reached the end of the regeneration buffer and therefore the index is reset to address 1 and the process continues.


Figure 5. Channel Processing Loop in Regeneration Mode


A local variable is made from Rate012Rate345, and Rate67 for use in timing the other While Loops.

Regeneration can be toggled at run time; however, it is possible that when switching back to streaming mode there may still be some older samples in the local FIFO. For this reason, it is recommended that at the start of the host program, the user decides whether to specify a mode for each channel and not change it at run time.

There is a limited amount of memory on R series devices, so some channels have been allocated larger memory blocks than others (as likely, not all of them will be used in regeneration mode). The sizes of the memory buffers are as follows:



Number of Elements in Memory Block

















Table 1. Memory Allocated for Each Analog Channel


This allocation was chosen to allow three channels with different update rates (channels 0, 3, and 6) to have sizeable memory block sizes for regeneration. However, with the LabVIEW FPGA Module, these sizes could be changed if desired. Also, keep in mind that the very first element is used to store the number of samples in the waveform that are currently stored in the memory block.



We have included two example host VIs: one with all channels in streaming mode and the other with all channels in regeneration mode. However, customized host VIs could easily be written to interface with this FPGA personality with any mix of channels in regeneration or streaming mode.

Figure 6. Example Host VI Front Panel


The host code needs to accomplish by the following:

  • Open a reference to the FPGA Personality and download the bitfile.
  • Configure the depth of the FIFOs, start them, and then run the bitfile. It is recommended that you leave these settings as configured.
  • Write to the controls on the FPGA’s front panel for each channel. To be specific:
    • Pause
    • Mode
    • Update Rate 
  • Send series of elements over the correct DMA FIFO for each channel. This needs to be done repeatedly if in streaming mode, but only once if the channel is in regeneration mode. The host is responsible for writing a number of samples to the memory block that is less than or equal to its size. The host VI can replace the waveform in the memory block at run time by ensuring the Mode control is true and sending another series of elements across the proper DMA FIFO for that channel.
  • Close the FPGA reference. If the system is in streaming mode, Close and reset should be selected as an option for this function, as no more samples need to be written. However, if there are any channels in regeneration mode, and the user wishes to have them continue writing even after the host VI has stopped, then Close should be selected and no resetting should be done.
  • Figure 7. Initializing the FPGA Section of the Host VI


    In this snippet of block diagram code from the example regeneration host VI, we open an FPGA reference, download the bitfile to the FPGA, and configure the depth of the local DMA FIFOs (those which will be on the host PC). We then start the DMA FIFOs and run the bitfile. Also, not shown in this screenshot, we set the update rate of the channels. The user specifies the update rate in terms of frequency, but the FPGA code is expecting this in terms of number of ticks of the 40 MHz clock, so we use the subVI.

    Figure 8. Writing Samples From Channels 0, 1, and 2 to Their Corresponding DMA FIFO


    In this section of block diagram code, from the example streaming host VI, we iterate through the channels to create samples using the basic function generator VI, write the samples to their respective DMA FIFO, and check if the user has paused any of the channels (top right). Previous to this in the block diagram, we set which of the channels were in regeneration mode.

    We have written the example host using three parallel While Loops, so that it can supply the three DMA channels with data at different rates. This prevents starvation of higher update rate channels. When high update rates are used, you may need to increase the number of elements sent in each DMA transfer.



    This example personality was designed to allow very flexible configurations of analog output. You can run it as is for a multirate analog output functionality or use it as a starting point for more specialized test or control applications.

    You do not need the LabVIEW FPGA Module to use this personality. However, you do need the module if you want to make any modifications to the FPGA code. The NI-RIO driver is the only driver necessary.



    Multirate Analog Output Example DAQ Personality


    Was this information helpful?