Example Code

Generate a PWM (Pulse-width modulation) Output Signal On cRIO/sbRIO Targets Using Scan Interface Mode

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.


  • CompactRIO|SingleBoardRIO


  • LabVIEW Real-Time Module
  • LabVIEW


  • NI RIO

Code and Documents




This example demonstrates how you can implement a simple low frequency PWM (Pulse-width modulation) output signal using a cRIO/sbRIO in Scan Interface mode.



The FPGA of a cRIO/sbRIO can be used in two different modes:

  • LabVIEW FPGA Interface
  • Scan Interface

In LabVIEW FPGA Interface mode, you can use LabVIEW FPGA programming to add more flexibility, customization, and deterministic timing to your applications. The LabVIEW FPGA Interface mode enables you to use the whole power of the FPGA, but you have to create, test, debug and compile your FPGA program which can be challenging if you use FPGA for the first time.

In Scan Interface mode, you do not need to do any LabVIEW FPGA development or program communication between FPGA and Host VIs. You also do not need to wait for VIs to be compiled to the FPGA before deploying and running them. In Scan Interface mode, LabVIEW programs the FPGA on the cRIO/sbRIO target with a pre build FPGA program. More information about the Scan Interface mode are available here:

Using NI CompactRIO Scan Mode with NI LabVIEW Software

The Scan Interface mode is not available on all cRIOs/sbRIOs. Not all C-Series modules are supported in the Scan Interface mode. Take a look into this site for the supported cRIOs/sbRIOs and C-Series modules:
Software Support for CompactRIO, CompactDAQ, Single-Board RIO, R Series, FlexRIO, and EtherCAT
The Scan Interface mode provides the ability to run up to two C-Series modules in specialty digital mode. This mode should be preferred for the generation of PWM signals:
How Can I Perform Pulse-Width Modulation Using the Scan Interface?
This example demonstrates a way to create additional PWM signals, if you already use two c-Series in specialty digital mode. The Scan Interface mode limits the update rate of a C-Series module to ~1kHz. The fastest PWM signal which can be generated with this example has a frequency of 500Hz.
This example will only work for low frequencies, for most applications use the speciality digital mode.

If program the FPGA by yourself, you can generate a much faster and more accurate PWM signal.



  • LabVIEW Base Development System 2012 (or compatible)
  • LabVIEW Real-Time Module 2012 (or compatible)
  • NI-RIO 12.0 (or compatible)


  • A supported cRIO/sbRIO with an supported digital output module


Steps to Implement or Execute Code

  1. Download and open the attached ZIP-file
  2. Open the [Main] ...VI and follow the instructions on the Front Panel


Additional Information or References

[Main] Generate PWM signal - Front Panel.png
[Main] Generate PWM signal - Block Diagram.png


**The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text ‘NIVerified’. Read here for more information about the new Example Guidelines and Community Platform.**

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.


Thanks man... That is exactly what I wanted... Do you have an example of a quadrature encoder? Thanks


I want block diagram of pwm generator for 3 phase inverter using crio.


can you provide me with the code for SPWM for 3 three phase inverter using CRIO?