NI LabVIEW For CompactRIO Developer's Guide-21-29
NI LabVIEW For CompactRIO Developer's Guide-21-29
Figure 2.1. If you have LabVIEW FPGA installed, you are prompted to select a programming
mode
when adding a CompactRIO system to your LabVIEW project.
When communicating data between an FPGA VI and Real-Time VI, you have the option to stream data at very high
rates using DMA FIFOs, or to communicate single-point data using controls and indicators.
14
Hybrid Mode
Using the CompactRIO Scan Mode and LabVIEW FPGA at the same time on a target is known as Hybrid Mode. With
this approach, the modules you select to program directly with LabVIEW FPGA are removed from the I/O scan, and
the remaining modules communicate with the RIO Scan Interface. Note that the RIO Scan Interface uses two of the
three DMA channels that are normally available for use in LabVIEW FPGA.
This section offers tips on choosing a programming mode for your CompactRIO application. You should choose a
programming mode based on your application requirements for performance, reliability, customization, and I/O. The
NI LabVIEW for CompactRIO Developer’s Guide discusses programming techniques and best practices for both
LabVIEW FPGA programming and the RIO Scan Interface use.
Figure 2.2. With LabVIEW FPGA, you can create custom FPGA VIs for high-speed data
acquisition,
control loops, or custom timing and triggering.
15
hardware circuitry. Because there is no OS on the FPGA chip, the code is implemented in a way that ensures
maximum performance and reliability.
Custom Triggering/Timing/Synchronization
With the reconfigurable FPGA, you can create simple, advanced, or otherwise custom implementations of triggers,
timing schemes, and I/O or chassis synchronization. These can be as elaborate as triggering a custom CAN message
based on the rise of an analog acquisition exceeding a threshold or as simple as acquiring input values on the rising
edge of an external clock source.
■■ Encoding/decoding sensors
■■ Tachometers
■■ Data reduction
■■ Third-party IP integration
■■ Sensor simulation
■■ Hardware-in-the-loop simulation
16
Using LabVIEW FPGA Interface Mode
When you discover your CompactRIO controller from the LabVIEW project, select LabVIEW FPGA Interface as your
programming mode. LabVIEW FPGA Interface mode automatically detects your I/O modules and adds them to the
LabVIEW project. You can find more information and best practices on using LabVIEW FPGA Interface mode in
Chapter 5: Customizing Hardware Through LabVIEW FPGA.
RIO Scan Interface technology allows single-point I/O access up to rates of a few hundred hertz without the need to
write FPGA code or an RT to FPGA interface. When the controller is accessing I/O via the scan interface, module I/O
is automatically read from the modules and placed in a current value table on the CompactRIO controller.
I/O Modules
I/O Modules
I/O Variables NI Scan Engine
RIO Scan
I/O Memory Interface
LabVIEW Table
Real-Time VI
Figure 2.3. Block Diagram Description of the RIO Scan Interface Software Components
When deciding to use Scan Mode for a CompactRIO application, you should consider the required performance or
loop rates and channel count. The graph in Figure 2.4 shows benchmarking that was completed using Scan Mode for
a PID control loop, including one analog input and one analog output. The data shows that PID loop rates higher than
100 Hz combined with a high-channel count have a significant impact on CPU usage. Generally, you should not use
Scan Mode when you require loop rates faster than 500 Hz.
17
Figure 2.4. When using the RIO Scan Interface, high-channel counts combined with
high-loop rates have a significant impact on CPU.
Although you should not use Scan Mode for high-speed data acquisition or control loops, it does offer several benefits:
■■ Ease of Programming—Drag and drop your I/O variables directly into your LabVIEW Real-Time VI during
development.
■■ Ability to Dynamically Detect I/O Modules—Slots not configured through the project automatically detect
inserted modules. You can then configure these modules through the variable API.
■■ Fault Engine—The NI Scan Engine features the built-in NI Fault Engine that throws errors deterministically.
■■ Diagnostics and Debugging—With the Distributed System Manager, you can view current values and faults
as well as override current I/O values while your program is running.
Not all CompactRIO hardware works with NI Scan Mode. For a list of C Series I/O modules that feature Scan Mode
support, see C Series Modules Supported by CompactRIO Scan Mode. CompactRIO targets with 1M gate FPGAs
cannot fully support the scan interface. You can implement some scan interface features on unsupported targets,
but you must use LabVIEW FPGA.
18
Figure 2.5. Drag and drop I/O variables onto your Real-Time VI block diagram.
The Scan Engine also provides a Timed-Loop timing source, so you can synchronize code with I/O updates for low-jitter
control applications.
Figure 2.6. Use a Timed Loop with the clock source set to Synchronize to Scan Engine
to synchronize the loop to I/O updates.
You can find example programs for using Scan Mode at \LabVIEW\examples\ScanEngine.
19
When programming in Scan Mode, another option for interfacing to I/O variables is through the I/O Variable
programmatic API, shown in the Figure 2.7. The programmatic API offers several benefits over the static I/O Variable
Node API:
■■ You can iterate through multiple variables at once without dropping down a large number of I/O Variable Nodes
■■ Deployment to a CompactRIO target is less complicated since the items are not bound to a LabVIEW project
■■ You can change I/O variable configuration settings while running an application, and configuration settings are
viewable on the block diagram
While the programmatic API offers several advantages, it does require more programming. The I/O Variable programmatic
API can be found in the LabVIEW functions palette under Data Communication»Shared Variable»I/O Variable.
When deploying Scan Engine I/O variables to a CompactRIO controller, note that these variables have the potential
to take up a significant portion of the CPU bandwidth. If you deploy a chassis in Scan Mode that physically contains
all the modules you want to use, it publishes a variable called PercentHWScanUtilization. This value tells you what
percentage of CPU bandwidth is dedicated to reading or writing I/O variables based on your scan time and deployed
hardware. Based on this, you have an idea of how much time can be dedicated to other processes.
Figure 2.8. Monitor the CPU bandwidth that is used for reading and writing to Scan Engine I/O
variables.
20
When to Use Hybrid Mode
Using Scan Mode and LabVIEW FPGA at the same time on a target is known as Hybrid Mode. With this approach,
the modules you select to program directly with LabVIEW FPGA are removed from the I/O scan, and the remaining
modules communicate with the RIO Scan Interface. When you compile your LabVIEW FPGA VI, if any I/O modules
are configured to use Scan Mode, the necessary components of the RIO Scan Interface are included in the compile.
The result is a single bitfile that works with the Scan Mode features for modules configured to use Scan Mode as
well as your custom FPGA logic that communicates directly with the remaining I/O modules.
Figure 2.9. After activating Hybrid Mode, write an FPGA VI to interface with the module
and pass data to the real-time host.
In Hybrid Mode, you can continue using the RIO Scan Interface on some modules while programming others directly
on the FPGA. You can use the FPGA programming model to handle high-speed operations, inline processing,
waveform buffered acquisition, and certain modules that do not feature Scan Mode support. Activate FPGA
programming for a particular module by dragging and dropping the module project item from under the CompactRIO
chassis to under the FPGA target. By doing this, you can program the FPGA for custom code running in parallel with
the scan interface for other modules. You can access the FPGA I/O from the real-time VI by using either the FPGA
Host Interface Functions or User-Defined Variables.
21
Figure 2.10. Activate FPGA programming for a particular module by dragging and dropping the
module project item from under the CompactRIO chassis to under the FPGA target.
You need to note a few important limitations when using Hybrid Mode. First, the compile time significantly increases
because the compiler has to combine the default RIO Scan Interface bitfile as well as the FPGA code that was
created into one bitfile. Secondly, the number of DMA channels that you can use in the FPGA code is reduced since
the Scan Engine uses two channels. Most FPGAs have three DMA channels, so most applications have only one
DMA channel left to use in the FPGA code.
22