Example Code

Reference Example: Multi-channel PID Control with Operator Interface on CompactRIO

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


  • NI RIO

Code and Documents



This reference example includes a recommended architecture for performing low channel count multi-channel PID control on a Real-Time (RT) CompactRIO (cRIO) controller with a host user interface. Channel I/O is performed using the cRIO chassis configured for Scan Mode.

The LabVIEW Project consists of two major components. The RT application running on the cRIO controller (cRIO 9074 for this example) and the operater interface running on development environment on a host machine. The RT application is the PID Control (RT VI).vi and the operator interface is listed as HMI (Host VI).vi. The two running applications communicate using Network Published Shared variables. Here is a snapshot of the project layout:


The RT application PID Control (RT VI).vi is broken up into 3 sections; Initialize, Control, Shutdown.

  • The Initialize section initializes the Network Published Shared Variables, PID Gains, and Arrays used during the control process.
  • The Control Process section runs two parallel loops. The Deterministic Control Loop (which is synchronized with the Scan Engine) is responsible for performing the PID control on 4 temperature process variables. This is achieved by reading the Scan I/O Variables from the cRIO modules, implementing PID control to those values (Using the PID.vi which is included in the PID and Fuzzy Logic Toolkit), and then writing the command output to the output modules using the Scan I/O Variables. The Non-Deterministic UI and Network Loop is responsible for communicating with the HMI (Host VI) using Network Published Shared Variables. The status of each channel, PID Gains, and output limits information is passed to the HMI (Host VI) from the controller. The HMI (Host VI) can also issue new set points, output ranges, PID gains, and commands to stop through the Non-Deterministic Loop.
  • The Shutdown section sets the outputs of the cRIO modules to a safe value.


The Host VI (HMI (Host VI).vi) is also broken up into 3 sections; Initialize, Main UI, Shutdown.

  • The Initialize section initializes Network Published Shared Variables (heartbeat and idle checking)
  • The Main UI Loop is responsible for sending the output range, PID gains, heartbeat, and setpoint information to the RT control application on the cRIO. It also produces a useful display on the front panel which shows a graph of the process data.
  • The Shutdown section gives you the option to send an idle command to the controller to halt control while the Host VI is not running. 



Steps to Implement or Execute Code

  1. Begin by running the Host VI (HMI (Host VI).vi) and setting your desired Idle functionality and Control Parameters. You also have the ability enable or disable the Control Process.
  2. Once you have configured the Host Interface as desired, begin the RT Application VI PID Control (RT VI).vi. The Host UI should now update with the appropriate values from the controller.
  3. Adjust the Parameters and Setpoint as desired.
  4. Make sure to properly shutdown both of the VI's using the corresponding Stop buttons. Optionally, the control process will also return to an idle state if the network connection with the host is lost.



LabVIEW 8.6 or higher Development Environment

LabVIEW Real-Time 8.6 or higher

LabVIEW PID and Fuzzy Logic Toolkit


Computer with LabVIEW Development Environment

cRIO Controller  (This example uses a cRIO-9074 integrated controller but other cRIO setups can be used)

cRIO Chassis that supports Scan Interface (http://zone.ni.com/reference/en-XX/help/372603F-01/riohelprt/supported_hardware_rt/)

cRIO I/O Modules (NI 9211 and NI 9474 are used in this example)

Ethernet Cabling

Additional Information

This example uses the ni.com style controls from the UI Interest Group

View the CompactRIO Developer's Guide for additional development guidlines and reference architectures.

**This document has been updated to meet the current required format for the NI Code Exchange. For more details visit this discussion thread**

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

NI Employee

thanks for posting!  could you please rename your attachment to include the LabVIEW version? "_lvXX.zip" is fine.

Todd S.
LabVIEW Community Manager
National Instruments
NI Employee

Updated the attached code.

The timed loops were set at the same priority. Whoops.

If you downloaded this previously, make sure to set your control loop to a priority greater than 100.