Overview
One major benefit of Reconfigurable I/O (RIO) technology is the ability to create custom hardware to generate analog waveforms for specific applications. This tutorial describes one common method for developing a customized periodic waveform generator using RIO enabled hardware (for this tutorial we are using CompactRIO) and the LabVIEW FPGA Module. For additional information about waveform generation with the LabVIEW FPGA Module and CompactRIO return to the main tutorial, "Waveform Generation with CompactRIO."
Table of Contents
- Periodic Waveform Description
- Periodic Waveform Applications with CompactRIO
- Periodic Waveform Generation Using Sine Generator Express VI
- Periodic Waveform Generation Using FPGA Memory
- Conclusion
- Periodic Waveform LabVIEW FPGA Examples
Periodic Waveform Description
A periodic waveform is a waveform that repeats itself at regular intervals. The unit of regularity in a periodic waveform is called its cycle. The waveform shown below is a periodic sine wave that has a cycle of 50 samples. Periodic waveforms do not have to be sinusoidal and can be arbitrarily complex within the defined cycle.
Periodic waveforms of varying shapes, amplitudes, and frequencies are used for simulation and control of electronic devices across a broad range of industries. The most common types of periodic waveforms are sine, square, triangle, and sawtooth, used in a variety of applications for simulation and control of electronic devices . As an application example, sawtooth waveforms are often used to sweep the frequency of a second signal. By using a sawtooth waveform to drive a voltage-controlled oscillator, engineers can continuously sweep through specific frequency ranges. As another application example, square waves are used in acoustical testing. Because square waves contain only odd integer harmonics, an acoustic engineer is able to compare the actual sound pattern of an audio system they are testing with the familiar square wave pattern. In addition to sine, square, triangle, and sawtooth cycles, periodic waveforms can also contain complex waveform cycles that allow engineers to represent periodic noise or specific sound patterns.
CompactRIO gives engineers and scientists a customizable, rugged, and portable solution for generating periodic waveforms. The LabVIEW FPGA Module combined with CompactRIO hardware, provides maximum hardware flexibility for engineers. As an example, for periodic waveform generation developers are able to customize their hardware so they have the ability to continuously change the update rate, gain, and waveform type as the program runs. Also, developers can customize their hardware triggering to suit the needs of their specific application. In addition, using the LabVIEW FPGA Module developers can easily define the timing and synchronization of FPGA functions on the same CompactRIO hardware without any knowledge of hardware design or low-level EDA tools. This is beneficial if an application requires the tight synchronization of waveform generation with other FPGA functionality such as digital I/O and analog input.
We are able to generate periodic waveforms with CompactRIO hardware and the LabVIEW FPGA Module using several different methods. The first method involves the use of the LabVIEW FPGA Sine Generator Express VI. By using this Express VI we can quickly develop an FPGA program, download it to the target hardware, and have a fully functional sinusoidal generator with frequency and phase offset controls. The second method uses advanced functionality of the LabVIEW FPGA Module to load arbitrarily complex cycles of a periodic waveform to the FPGA memory. This tutorial outlines these two methods of periodic waveform generation in detail.
Periodic Waveform Generation Using Sine Generator Express VI
First we will develop a simple sinusoidal waveform generator by using the LabVIEW FPGA Sine Generator Express VI. The advantage of using this Express VI is it allows us to quickly define our FPGA VI because of its built-in functionality. The Sine Generator Express VI performs all the low-level FPGA programming, such as memory reads and writes, so it is transparent to the programmer. This saves valuable development time and allows us to get our custom hardware up and running faster. This section describes how to create a sinusoidal waveform generator and also discusses the use of good programming practices to create scalable, maintainable, and robust FPGA code. Refer to the section, Periodic Waveform LabVIEW FPGA Examples, to download the example program.
Defining Hardware with the LabVIEW FPGA Module

Figure 2: FGPA VI: Sine_Generation(fpga)

Figure 3. Sine Generator Configuration Dialog Box
NOTE: Voltage Output with CompactRIO Analog Output Modules
The LabVIEW FPGA Module utilizes integer math for all mathematical operations; therefore, analog output operations with CompactRIO must utilize the binary code representation of the desired output voltage. The binary code representation of the desired voltage is determined by dividing the voltage by the code width of the module. The code width (or step size) is defined as the smallest change in voltage that the system can output. Code width is calculated according to the following equation:
For instance, the cRIO-9263 analog output module is a 16-bit analog output module with a range of -10V to +10V. Therefore the code width of the module is .305176mV/step (20V / 2^16 steps). Therefore, to output 5.0 volts, you would need to divide 5.0 V by .305176mV. This division yields a binary value of 16384.
National Instruments has included a VI for each CompactRIO analog output module that does this conversion. This VI is named Convert to Binary (cRIO-XXXX), where XXXX is the model number of the module. It is included in the cRIO-XXXX Support Files LLB located in the \examples\FGPA\CompactRIO\cRIO-XXXX\ directory. This VI converts desired voltage values into the binary code representation of that voltage through the following equation:
Configuring the Host Interface
There are several benefits for creating an API for your LabVIEW host VI. One major benefit that an API provides is abstraction, which involves grouping low-level code into logical functions or data stores. Creating the API greatly increases the usability of your FPGA VI by encapsulating the low-level functionality and increasing modularity of the code. Once the modules (subVIs) are created, you can simply place them into any LabVIEW Real-Time or LabVIEW for Windows application as functional nodes. In our example, shown in Figure 4, we have created four modules as subVIs: Open, Start, Set Controls, and Clear.

Figure 4. Top Level VI -> Sine_Generation(Host)

Figure 5. Opening and Closing the FPGA Reference
Once these controls are set, the Invoke Method function specifies the Run action and the code runs continuously in the While Loop of the FPGA VI.

Figure 6. Starting the FPGA VI on the Target Hardware
The previous section described how to use the LabVIEW FPGA Sine Generator Express VI for a fast way to create a sinusoidal function generator. This Express VI is great for applications that only need a sinusoidal waveform output, but it often does not have the full functionality that the developer needs for periodic waveform generation. The Sine Generator Express VI only lets the user change the frequency and offset period continuously as the waveform is being generated. In addition, the Express VI does not allow for generation of periodic waveforms with complex cycles. By using the advanced LabVIEW FPGA programming functions, Memory Read and Memory Write, we are able to take advantage of the onboard FPGA memory and create periodic waveforms with complex cycles. These functions allow the developer to load an arbitrarily complex waveform cycle with up to 8192 16-bit samples and continuously generate that cycle as a periodic waveform. This section outlines the creation of a periodic waveform generator that uses the FPGA onboard memory. Additionally, it discusses the use of good programming practices to create scalable, maintainable, and robust FPGA code. Refer to the last section, Periodic Waveform LabVIEW FPGA Examples, to download the example program.
Configuring the Hardware with the LabVIEW FPGA Module
- Read data from the FPGA memory continuously
- Output data to an analog output channel*
- Allow the user to adjust the waveform frequency and amplitude while continuously outputting signal

Figure 8. False Case of FPGA VI: Writing Waveform Elements Into FPGA Memory

Figure 9. True Case of FPGA VI: Reading Waveform Elements and Outputting
NOTE: Voltage Output with CompactRIO Analog Output Modules
The LabVIEW FPGA Module utilizes integer math for all mathematical operations; therefore, analog output operations with CompactRIO must utilize the binary code representation of the desired output voltage. The binary code representation of the desired voltage is determined by dividing the voltage by the code width of the module. The code width (or step size) is defined as the smallest change in voltage that the system can output. Code width is calculated according to the following equation:
For instance, the cRIO-9263 analog output module is a 16-bit analog output module with a range of -10V to +10V. Therefore the code width of the module is .305176mV/step (20V / 2^16 steps). Therefore, to output 5.0 volts, you would need to divide 5.0 V by .305176mV. This division yields a binary value of 16384.
National Instruments has included a VI for each CompactRIO analog output module that does this conversion. This VI is named Convert to Binary (cRIO-XXXX), where XXXX is the model number of the module. It is included in the cRIO-XXXX Support Files LLB located in the \examples\FGPA\CompactRIO\cRIO-XXXX\ directory. This VI converts desired voltage values into the binary code representation of that voltage through the following equation:
Configuring the Host Interface

Figure 10. Top-Level VI -> Periodic_Output_Memory(Host)

Figure 11. Opening and Closing the FPGA Reference
Once a waveform cycle is created or read from a file, it then needs to be loaded to the FPGA memory. Remember from our LabVIEW FPGA VI, Read_Write_Memory(fpga), we have to continuously call the false case to write multiple data values into memory. To do this we use a For Loop that calls a Read/Write Control function and Invoke Method on each iteration. The Read/Write Control function allows us to update the two controls, Address and Data, on the FPGA VI. After updating these controls, we use the Invoke Method function and specify the action as Run to execute the FPGA VI on our target hardware. Each time the For Loop iterates it writes a data value from our Waveform Input array to the FPGA memory at the address specified by the iteration terminal. By using the LabVIEW Array Size function we are able to set the loop count terminal on the For Loop. The subVI Convert to Binary (cRIO-9263) takes an input voltage (+-10V) and converts it to the binary code (-32768 to +32767) that is accepted by the cRIO-9263 Analog Output Module.

Figure 12. Loading the Waveform Cycle to FPGA Memory

Figure 13. Starting the FPGA VI on the Target Hardware
CompactRIO gives engineers and scientists a customizable, rugged, and portable solution for periodic waveform generation. The LabVIEW FPGA Module, and CompactRIO hardware provides maximum flexibility for the developer. In this tutorial we have outlined two methods for creating periodic waveform generators. By using the LabVIEW FPGA Sine Generator Express VI we are able to quickly design our FPGA VI and configure the target hardware. This Express VI performs all the low-level FPGA programming, such as memory reads and writes, so it is transparent to the programmer saving valuable development time. For more advanced periodic waveform generator functionality we use the FPGA memory. The FPGA memory can be accessed by using Memory Read and Memory Write FPGA VIs, allowing us to create complex periodic waveform cycles. The periodic waveform generators that we outlined throughout this tutorial can be downloaded below. For additional information about waveform generation with the LabVIEW FPGA Module and CompactRIO return to the main tutorial, "Waveform Generation with CompactRIO"
See Also:
Waveform Generation with CompactRIO
Periodic Waveform LabVIEW FPGA Examples
See Also:
Sinusoidal Waveform Generation with LabVIEW FPGA (Sine Generator Express VI)
Periodic Waveform Generation with LabVIEW FPGA (Memory Read and Write)
Related Links:
CompactRIO Product Page
LabVIEW FPGA Module Product Page
LabVIEW FPGA Module User Manual
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/).



