Developing Embedded Applications Using CompactRIO and LabVIEW FPGA - PG
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA - PG
Developing Embedded
en
Applications Using
m
CompactRIO and
tru
LabVIEW FPGA TM
ns
Participant Guide
lI
na
io
at
Copyright
© 2023 National Instruments Corporation. All rights reserved.
2
Under the copyright laws, this publication may not be reproduced or transmitted in any form, electronic or
mechanical, including photocopying, recording, storing in an information retrieval system, or translating, in whole
ht
materials belonging to others, you may use NI software only to reproduce materials that you may reproduce in
accordance with the terms of any applicable license or other legal restriction.
yr
ts
FIELDBUS FOUNDATION™ and FOUNDATION™ are trademarks of the Fieldbus Foundation.
EtherCAT® is a registered trademark of and licensed by Beckhoff Automation GmbH.
en
CANopen® is a registered Community Trademark of CAN in Automation e.V.
DeviceNet™ and EtherNet/IP™ are trademarks of ODVA.
Go!, SensorDAQ, and Vernier are registered trademarks of Vernier Software & Technology. Vernier Software &
m
Technology and vernier.com are trademarks or trade dress.
Xilinx is the registered trademark of Xilinx, Inc.
tru
Taptite and Trilobular are registered trademarks of Research Engineering & Manufacturing Inc.
FireWire® is the registered trademark of Apple Inc.
Linux® is the registered trademark of Linus Torvalds in the U.S. and other countries.
ns
Handle Graphics®, MATLAB®, Real-Time Workshop®, Simulink®, Stateflow®, and xPC TargetBox® are registered
trademarks, and TargetBox™ and Target Language Compiler™ are trademarks of The MathWorks, Inc.
Tektronix®, Tek, and Tektronix, Enabling Technology are registered trademarks of Tektronix, Inc.
lI
The Bluetooth® word mark is a registered trademark owned by the Bluetooth SIG, Inc.
na
The ExpressCard™ word mark and logos are owned by PCMCIA and any use of such marks by NI is under license.
The mark LabWindows is used under a license from Microsoft Corporation. Windows is a registered trademark of
Microsoft Corporation in the United States and other countries.
io
Other product and company names mentioned herein are trademarks or trade names of their respective
companies.
at
Members of the NI Partner Program are business entities independent from NI and have no agency, partnership,
or joint-venture relationship with NI.
N
Patents
For patents covering NI products/technology, refer to the appropriate location: Help»Patents in your software,
the patents.txt file on your media, or the National Instruments Patent Notice at ni.com/patents.
3
2 02
ht
ig
Support
Worldwide Technical Support and Product Information
yr
ni.com
op
NI Corporate Headquarters
11500 North Mopac Expressway Austin, Texas 78759-3504 USA Tel: 512 683 0100
For further support information, refer to the Additional Information and Resources appendix. To comment on NI
C
documentation, refer to the NI website at ni.com/info and enter the Info Code feedback.
ts
en
Table of Contents
m
tru
Student Guide
A. Course Description ....................................................................................... vii
ns
B. What You Need to Get Started....................................................................... vii
C. Installing Course Files ................................................................................... viii
D. Course Goals ............................................................................................... viii
lI
Lesson 1
Programming Using LabVIEW FPGA
na
A. Introduction to FPGA ....................................................................................
B. Developing an FPGA VI .................................................................................
1-3
1-8
io
C. Interactive Front Panel Communication ........................................................... 1-13
D. Selecting an Execution Mode ......................................................................... 1-14
at
Lesson 2
02
Lesson 3
Signal Processing in LabVIEW FPGA
A. Using Fixed-Point Data Type .......................................................................... 3-3
Exercise 3-1: Explore Fixed-Point Configurations ................................................. 3-12
B. Using Single-Precision Floating-Point............................................................... 3-17
Exercise 3-2: Process the Tachometer and Accelerometer Signals ......................... 3-20
ts
C. Performing FPGA Math & Analysis ................................................................. 3-26
D. Integrating Third-Party Intellectual Property (IP) ................................................ 3-30
en
Lesson 4
Inter-Process Communication in LabVIEW FPGA
m
A. Exploring Parallel Loops on FPGA ................................................................... 4-3
B. Transferring Latest Data (Tag) ....................................................................... 4-6
tru
Exercise 4-1: Transfer Latest Values to PID Loop ................................................ 4-15
C. Transferring Buffered Data (Stream, Message) ................................................. 4-28
Lesson 5
ns
Communicating between the FPGA and Real-Time VIs
A. Programmatically Communicating with the FPGA VI from the Real-Time VI.......... 5-3
lI
B. Deploying an FPGA VI................................................................................... 5-5
C. Transferring Latest Data (Tag) ....................................................................... 5-10
Exercise 5-1: Transfer Tag Data between FPGA and RT ....................................... 5-13
na
D. Transferring Buffered Data (Stream, Message) .................................................
Exercise 5-2: Transfer Stream Data from FPGA to RT Target ................................
Exercise 5-3: Explore DMA FIFO Interleaving ......................................................
5-20
5-30
5-42
io
E. Synchronizing the RT VI and FPGA VI ............................................................. 5-46
F. Implementing an FPGA Watchdog .................................................................. 5-49
at
Lesson 6
Exploring Common FPGA Optimizations
A. Optimization Use Cases ................................................................................ 6-3
3
Lesson 7
ig
Appendix A
Additional Information and Resources
C
iv | ni.com
ts
en
Student Guide
m
tru
ns
In this student guide, you will learn about the course
lI
description and the items you need to get started in this
course.
Topics
na
A. Course Description
io
B. What You Need to Get Started
C. Installing Course Files
at
D. Course Goals
N
3
02
2
ht
ig
yr
op
C
C
op
yr
ig
ht
202
3
N
at
io
na
lI
ns
tru
m
en
ts
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
A. Course Description
The Developing Embedded Applications Using CompactRIO and LabVIEW FPGA course is part of a
series of courses designed to build your proficiency with LabVIEW, LabVIEW Real-Time and LabVIEW
FPGA and help you prepare for exams to become an NI Certified LabVIEW Embedded Developer and
NI Certified LabVIEW Architect.
ts
The participant guide is divided into lessons. Each lesson contains the following:
en
• An introduction with the lesson objective and a list of topics and exercises.
• Slide images with additional descriptions of topics, activities, demonstrations, and multimedia
segments.
m
• A set of exercises to reinforce topics. Some lessons include optional and challenge
• exercises.
tru
• A lesson review that tests and reinforces important concepts and skills taught in the lesson.
ns
Before you use this exercise manual, make sure you have the following items listed below:
lI
Note Not all exercises require all the hardware and software listed below.
Software
•
•
LabVIEW 2023 Q3 (32-bit)
na
LabVIEW Real-Time Module 2023 Q1 (32-bit)
io
• LabVIEW FPGA Module 2023 Q1 (32-bit)
NI-DAQmx 2023 Q3 (32-bit)
at
•
Hardware
• An NI CompactRIO from either the 904x or 905x product lines
3
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA course USB, containing
ht
Directory Description
ts
3. Browse the CD drive and follow the readme file instructions to complete the setup.
en
4. Use the USB drive partition to save your files.
File Locations
m
• Exercise files are in the C:\Exercises\FPGA folder assuming that you copied the files on your root
directory.
tru
• Solution files are in the C:\Solutions\FPGA folder assuming that you copied the files on your root
directory.
ns
D. Course Goals
This course will strengthen your knowledge on the following:
lI
• Design, prototype, and deploy an embedded application.
• Implement functionality on FPGA using the LabVIEW FPGA module.
•
•
na
Communicate data between the FPGA, RT, and PC.
Debug, benchmark, and test your application.
Deploy your application to multiple systems.
io
•
at
N
3
2 02
ht
ig
yr
op
C
viii | ni.com
ts
1
en
Programming
m
Using LabVIEW
tru
FPGA
ns
lI
na
io
Learn about FPGA common usages, how to work with
at
Topics
A. Introduction to FPGA
3
B. Developing an FPGA VI
02
E. Compiling an FPGA VI
F. Compilation Considerations
ht
G. Basic Optimizations
Exercises
ig
A. Introduction to FPGA
Objective: Explore the composition and common uses of FPGAs.
ts
Field-Programmable FPGAs are reprogrammable integrated circuits that contain an array of
en
Gate Array (FPGA) programmable logic blocks. FPGA chip adoption is driven by their flexibility,
hardware-timed speed and reliability, and parallelism.
m
tru
ns
lI
na
io
at
N
Unlike processors, FPGAs are truly parallel in nature, so different processing operations do not have
to compete for the same resources. Each independent processing task is assigned to a dedicated
3
section of the chip and can function autonomously without any influence from other logic blocks. As
a result, the performance of one part of the application is not affected when you add more processing.
02
Every FPGA chip is made up of a finite number of predefined resources with programmable
interconnects to implement a reconfigurable digital circuit and I/O blocks to allow the circuit to access
2
FPGA resource specifications often include the number of configurable logic blocks, the number of
ht
fixed function logic blocks such as multipliers, and the size of memory resources like embedded block
RAM. Of the many FPGA specifications, these are typically the most important when selecting and
ig
comparing FPGAs for a particular application. The configurable logic blocks (CLBs) are the basic logic
unit of an FPGA. Sometimes referred to as slices or logic cells, CLBs are made up of two basic
yr
components: flip-flops and look-up tables (LUTs). Various FPGA families differ in the way flip-flops
and LUTs are packaged together, so it is important to understand flip-flops and LUTs.
op
C
ts
The configurable logic blocks (CLBs) are the basic logic unit of an FPGA. Sometimes referred to as
slices or logic cells, CLBs are made up of two basic components: flip-flops and look-up tables (LUTs).
en
Various FPGA families differ in the way flip-flops and LUTs are packaged together, so it is important
to understand flip-flops and LUTs.
m
Flip-flops are binary shift registers used to synchronize logic and save logical states between clock
cycles within an FPGA circuit. On every clock edge, a flip-flop latches the 1 or 0 (TRUE or FALSE)
tru
value on its input and holds that value constant until the next clock edge.
Much of the logic in a CLB is implemented using very small amounts of RAM in the form of LUTs. It
is easy to assume that the number of system gates in an FPGA refers to the number of NAND gates
ns
and NOR gates in a chip. But all combinatorial logic (ANDs, ORs, NANDs, XORs, and so on) is
implemented as truth tables within LUT memory. A truth table is a predefined list of outputs for every
combination of inputs.
lI
na
io
at
N
An FPGA is analogous to a printed circuit board that has many unconnected components.
Traditionally, the devices are connected with physical wires soldered to the pins with a wire wrapping
tool or embedded in the printed circuit board. The physical wires are difficult to modify. However, the
3
connections in an FPGA circuit are dynamically defined in software when the LabVIEW code compiles
and the bitstream is downloaded. The bitstream causes semiconductor switches to turn on or off,
02
1-4 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
m
sbRIO CompactRIO EtherCAT 9145
tru
ns
lI
FlexRIO Multifunction RIO Modular Instruments
• No need for hardware description languages (HDLs) such as VHDL and Verilog.
N
3
2 02
ht
ig
yr
op
The emergence of graphical HLS design tools, such as LabVIEW, has removed some of the major
C
obstacles to the traditional HDL (hardware description language) design process. The LabVIEW
programming environment is distinctly suited for FPGA programming because it clearly represents
parallelism and data flow, so users who are both experienced and inexperienced in traditional FPGA
design processes can leverage FPGA technology.
ts
•
The icons on the FPGA graphic represent that some FPGA hardware resources are used for bus
en
communication from FPGA to RT and for I/O communication.
m
tru
ns
lI
FPGA Common Use Cases
na
These are some of the most common use cases for FPGA. With FPGA, you can describe any task that
you want to execute directly on your target at specific rates (usually high rates, MHz). When you
program an FPGA, you are describing the logic that the desired process will have to complete to
io
function, so it is like defining a different custom chip every time you build the FPGA code.
at
FPGAs are reconfigurable, which means that once you build an application describing the functionality
for your FPGA, you can then make updates or even redesign your FPGA if needed, which is excellent
to ensure continuous improvements and sustainability for the applications.
N
Performance
3
• Multi-loop analog PID loop rates exceed 100 kHz on embedded RIO FPGA hardware, whereas they
run at 30 kHz in real-time without FPGA hardware.
02
• Digital control loop rates can execute up to 1 MS/s or more, depending on the target.
• Single-cycle timed loops execute up to 200 MHz or more, depending on the target and clock
2
configuration.
• Due to its parallel processing ability, adding additional computation does not necessarily reduce
ht
Note Maximum rates vary depending on application size, requirements, and HW resources
ig
available.
yr
Reliability
• Once the FPGA is programmed, it becomes a hardware chip with all the associated reliability.
op
• Furthermore, it is highly deterministic. With an FPGA, you can implement code that synthesizes
deterministic hardware down to tens of nanoseconds.
C
Reconfigurability
• Reconfigurable through software. Create a chip that is reconfigurable with changes in software,
creating new hardware at any time.
1-6 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
performance and determinism. You can get the most out of the resources available with readable code
and graphic design.
en
The emergence of graphical HLS design tools, such as LabVIEW, has removed some of the major
obstacles to the traditional HDL design process. The LabVIEW programming environment is distinctly
suited for FPGA programming because it clearly represents parallelism and data flow, so users who
m
are both experienced and inexperienced in traditional FPGA design processes can leverage FPGA
technology. In addition, so that previous intellectual property (IP) is not lost, you can use LabVIEW to
tru
integrate existing VHDL into your LabVIEW FPGA designs.
Note Because LabVIEW FPGA is highly integrated with hardware, there is no need to
ns
rewrite code in VHDL to meet timing or resource constraints, as may be the case in many
HLS code generators.
lI
Then, to simulate and verify the behavior of your FPGA logic, LabVIEW offers features directly in the
development environment. Without knowledge of the low-level HDL language, you can create test
benches to exercise the logic of your design. In addition, the flexibility of the LabVIEW environment
na
helps more advanced users model the timing and logic of their designs by exporting to cycle-accurate
simulators such as Xilinx ISim. LabVIEW FPGA compilation tools automate the compilation process,
so you can start the process with a click of a button and receive reports and errors, if any, as
io
compilation stages are completed. If timing errors do occur because of your FPGA design, LabVIEW
highlights these critical paths graphically to expedite the debugging process.
at
N
3
2 02
ht
ig
yr
op
C
B. Developing an FPGA VI
Objective: Learn how to add a VI to the FPGA target in your LabVIEW project and explore some
commonly used FPGA palettes.
ts
To create a new FPGA VI:
en
a. Right-click FPGA Target in the Project Explorer window, then select New»VI.
b. Save the VI in the appropriate folder and save the project.
m
tru
ns
lI
na
io
at
N
Note In this example, the FPGA target lives under the compactRIO-9056 real-time target.
3
In some applications, there will not be a real-time component of the LabVIEW project.
2 02
ht
ig
yr
op
C
1-8 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
• FPGA I/O
• Data Storage & Transfer
en
• Synchronization
• FPGA Math & Analysis
• IP Integration
m
tru
ns
lI
na
io
at
N
3
I/O Node—Performs specific FPGA I/O operations on FPGA targets. You can configure the FPGA I/O
Node with one or more FPGA I/O items.
C
I/O Constant—Use the FPGA I/O constant to specify an FPGA I/O item on the block diagram.
ts
I/O Methods—Invokes a method on an I/O item or hardware under an FPGA target in the Project
Explorer window, such as a C Series module. In some cases, you can also invoke methods on the
en
FPGA target itself. The methods available depend on the FPGA target and the FPGA I/O item or
C Series module you select.
m
I/O Property—Gets or sets one or more properties on an I/O item or hardware under an FPGA target
in the Project Explorer window, such as a C Series module. In some cases, you can also set and
retrieve properties on the FPGA target itself. The properties available vary by the FPGA target, the
tru
C Series module, and the I/O resource.
User-Controlled I/O Sampling—Use the User-Controlled I/O Sampling functions to perform I/O with
ns
more specific control over the I/O hardware than you have with the FPGA I/O functions.
cRIO I/O Device—Use the cRIO I/O Device to specify a cRIO I/O item on the block diagram.
lI
Resources For more information, refer to LabVIEW Help.
1-10 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
• Analog Period Measurement—Calculates the period of an evenly sampled periodic signal using
threshold crossing detection. This Express VI accepts frames of data, performs measurement on
the input data, and returns a valid single result for each frame.
• Butterworth Filter—Filters one or more input signals using a lowpass or highpass IIR Butterworth
filter.
ts
• DC and RMS Measurements—Calculates the DC (mean) and/or RMS values of an input signal. You
can also use this Express VI to calculate the intermediate sum, mean square, or square sum values
en
in order to save FPGA resources. This Express VI accepts frames of data, performs measurement
on the input data, and returns a valid single result for each frame.
• FFT—Computes the Fast Fourier Transform (FFT). The Single Channel, Single Sample input format
m
computes the FFT point by point. The Single Channel, Multiple Samples input format allows you
to perform FFT analysis on a data stream with multiple samples/cycle.
tru
• Mean, Variance, and Standard Deviation—Calculates the mean, variance, and/or standard
deviation of an input signal. This Express VI analyzes discrete frames of data rather than analyzing
data continuously. This Express VI waits for N cycles to collect a frame of data before returning
one valid output, where N is the number of samples in each frame. It then waits for another N
ns
cycles to return another valid output.
• Notch Filter—Attenuates a specific frequency band in one or more input signals using a second
order IIR notch filter.
lI
• Rational Resampler—Provides a rational resampling filter that updates the input sample rate by an
na
L/M factor, where L is an interpolation factor and M is a decimation factor.
• Scaled Window—Minimizes spectral leakage associated with truncated waveforms. This Express
VI scales the windowed time-domain signal so that when a LabVIEW object computes the power
io
or amplitude spectrum of the windowed waveform, all windows provide the same level within the
accuracy constraints of the output wavelength.
at
• Z-Transform Delay Node—Stores data from one VI execution or loop iteration to the next. This
node is the Feedback Node in z-transform view.
N
• Control VIs—Use the Control VIs in FPGA VIs to create control applications for FPGA targets.
• Generation VIs—Use the Generation VIs in FPGA VIs to generate signals.
High Throughput Math Functions—Use the High Throughput Math functions to achieve high
3
•
throughput rates when performing fixed-point math and analysis on FPGA targets.
02
• Linear Algebra Functions—Use the Linear Algebra functions to perform vector and matrix
calculations in high-speed and high-throughput FPGA applications, such as RF applications.
• NI Floating-Point Library—Redirects to the LabVIEW Tools Network page on ni.com, where you
2
can download a library of floating-point math operation functions. You can use these functions in
your FPGA application to minimize resource usage outside single-cycle Timed Loops or to optimize
ht
changes of Boolean inputs, detecting zero crossings, delaying the input value, limiting the valid
range of a signal, and performing linear interpolation.
yr
op
C
ts
•
en
m
tru
ns
lI
If you only need to transfer the latest values of data to or from a host VI, you can store the data in
1-12 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
To communicate between the development PC and the VI running on the FPGA, use Interactive Front
Panel Communication.
en
The FPGA has no true user interface; therefore:
Must communicate data from the FPGA to the host PC or rely exclusively on I/O.
m
•
tru
•
ns
• Test with the development computer first or add indicators as probes.
To programmatically control and communicate with FPGA VIs from RT (host) VIs, use Programmatic
lI
FPGA Interface Communication. The front panel data you receive during Interactive Front Panel
Communication is not deterministic.
na
io
at
N
3
2 02
ht
communication.
• Cannot use debugging tools when running an FPGA VI on the FPGA target.
Test with simulation on the development computer first or add indicators as probes.
C
Note Avoid using large front panel arrays as a data storage mechanism – use VI-scoped
memory instead.
ts
To select an Execution Mode:
a. In the Project Explorer window, right-click FPGA Target»Select Execution Mode and select
en
Simulation (Simulated I/O).
b. In the Project Explorer window, right-click FPGA Target and select Properties.
From the Execution Mode category, select Simulation and click OK.
m
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
1-14 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
FPGA target. Some FPGA targets do not support this option. Some FPGA targets that support this
option do not support all I/O resources.
en
• Third-Party Simulation—Executes the FPGA VI in an installed third-party simulator. Select this
execution mode to enable cycle-accurate simulation.
m
Testing with Simulation Execution Mode
You can run the FPGA VI in Windows to check the logic of the application before compiling. The
tru
development computer simulates the I/O operations but does not duplicate the hardware timing. The
development computer can use either simulated I/O or real I/O from the FPGA target. Simulated I/O
can be generated using random data or a custom VI.
ns
Troubleshoot using traditional debugging tools:
• Execution highlighting—Execution highlighting shows the movement of data on the block diagram
lI
from one node to another using bubbles that move along the wires.
• Single-stepping—Single-step through a VI to view each action taken by each VI on the block
•
diagram as the VI runs.
na
Probe tools—Use the Probe tool to check intermediate values on a wire as the VI runs.
Breakpoints—Use the Breakpoint Tool to place a breakpoint on a VI, node, or wire and pause
io
execution at that location.
at
When testing is complete, set the execution mode to the FPGA target so that the VI can be compiled
and tested on the FPGA target.
N
3
2 02
ht
ig
yr
op
C
ts
en
Simulation (Simulated I/O)—The FPGA VI will execute on the development computer using simulated
data for any I/O. You can either use random data for I/O reads or you can create and use a custom VI
to generate your simulated I/O.
m
tru
Note You can also simulate your FPGA VI with real I/O data using the Desktop Execution
Node. This is covered later in this course.
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
1-16 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
Requirements
To complete this exercise, it is necessary to have access to the following hardware and software.
en
Software:
• LabVIEW 2023 Q3 (32-bit)
m
• NI-DAQmx 2023 Q3 (32-bit)
LabVIEW Real-Time Module 2023 Q1 (32-bit)
tru
•
ns
Hardware:
• An NI CompactRIO from either the 904x or 905x product lines
lI
• USB Type C or RJ45 Ethernet connection
• NI-9211 Thermocouple Input C Series Module
•
• Windows 10 PC na
NI-9474 Digital I/O C Series Module
io
Scenario
at
The hardware is already configured in NI MAX. Before you begin development, you should create a
LabVIEW project that contains the proper configuration for an FPGA target. In this case, the FPGA
target is on the cRIO-9056.
N
Create an FPGA VI that performs three parallel mathematical operations on two numbers. Compiling
an application can be very time-consuming, so you should make sure the code functions properly
3
before compiling. In a simple application, such as this exercise, errors are unlikely. However, as you
02
create more complex applications, it is important that you test the code on the development computer
before compiling. Testing on the development computer ensures that you detect and correct errors
before you begin a lengthy compilation.
2
ht
ig
yr
op
C
Implementation
1. Create a project:
a. Launch NI LabVIEW.
b. Select File»Create Project»Blank Project.
ts
• In the C:\Exercises\FPGA directory, create a new Executing a VI folder to save the
project in it.
en
c. Select File»Save Project to save the project as Basic cRIO FPGA.lvproj in the
C:\Exercises\FPGA\Executing a VI directory.
d. Notice that the project contains the root and the My Computer target.
m
2. Create the CompactRIO target:
a. In Project Explorer, right-click Project: Basic cRIO FPGA.lvproj and select
tru
New»Targets and Devices to display the Add Targets and Devices dialog box.
Note Be sure to right-click the Basic cRIO FPGA item and not the My Computer item.
ns
Right-click My Computer to add new targets. However, targets under My Computer must
be internal targets on the computer, such as PCI, PCIe, PXI, and PXIe devices.
lI
b. Select Existing target or device.
c. Expand Real-Time CompactRIO.
d. Select the cRIO-9056 Target.
e. Click OK.
na
3. Verify the proper configuration of the project:
io
a. In Project Explorer, expand cRIO-9056.
at
b. Expand the Chassis.
c. Verify that a node exists for each corresponding module in your CompactRIO chassis.
For example, Mod1 (Slot 1, NI 9234).
N
1-18 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
Note The FPGA Target should be automatically added into the project. If not, right-click
the Chassis, then select New»FPGA Target.
ts
a. Right-click FPGA Target and select New»VI.
en
b. Save the VI as Simple Math in the C:\Exercises\FPGA\Executing a VI\Basic cRIO FPGA
directory.
2. Set the project to execute the VI in simulation mode:
m
a. Right-click FPGA Target and select Select Execution Mode»Simulation (Simulated I/O).
b. The project should now resemble Figure 1-1.
tru
Figure 1-1. Basic cRIO FPGA.lvproj with VI in Simulation Execution Mode
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
ts
en
1 2
m
tru
ns
1 Numeric Controls—Search for Numeric Control in the Controls Palette.
2 Numeric Indicators—Search for Numeric Indicator in the Controls Palette.
lI
4. Complete the block diagram as shown in Figure 1-3.
na
Figure 1-3. Simple Math VI Block Diagram
io
2
at
N
1
3
5
2 02
3
ht
4
ig
1-20 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
Test
1. Test the VI to verify functionality in simulation execution mode:
a. Open the front panel of the Simple Math VI and run the VI.
b. Test the functionality of the VI by using several different values for X and Y and verifying that
X+Y=, X-Y=, and X*Y= each return expected values.
ts
2. Use the debugging tools on the Simple Math VI.
en
Another advantage of testing your VI in the simulation execution mode is that you can use the
standard LabVIEW debugging tools. The debugging tools help you quickly diagnose any errors that
may occur. After you download the application to the FPGA, you can no longer access these tools in
m
the compiled application. It is good practice to debug the FPGA VI as much as possible before you
compile the VI for FPGA.
tru
a. Open the block diagram of Simple Math VI.
b. Click Highlight Execution on the toolbar to turn on execution highlighting.
ns
c. Update the values on the front panel.
lI
d. Run the VI and observe how the values update on the block diagram.
4. Leave the VI and project open for use in the next exercise.
io
End of Exercise 1-1
at
N
3
2 02
ht
ig
yr
op
C
E. Compiling an FPGA VI
Objective: Investigate the compilation process and details of the FPGA VI.
ts
Once you have finished the verification of the logic with all the tools available, like I/O Simulation and
the different debugging tools, you can continue with the compilation now that you are more certain
that it should work correctly in the FPGA.
en
m
tru
ns
How the Compilation Process Works
lI
The following steps outline the process of compiling FPGA VIs:
na
1. Start Compile—Start the compilation process via one of four previously mentioned methods.
2. Generation of Intermediate Files—LabVIEW converts the FPGA VI into intermediate files
(HDL [hardware description language] code) to send to the compile server.
io
3. HDL compilation, analysis, and synthesis—The compile worker transforms intermediate files (HDL
code) into digital logic elements.
at
a. Mapping—The compile worker divides the application logic between the physical building
block on the FPGA.
N
b. Placing and Routing—The compile worker assigns the logic to physical building blocks on the
FPGA and routes the connections between the logic blocks to meet the space or timing
constraints of the compilation.
3
4. Bitfile creation—LabVIEW saves the bitfile in a subdirectory of the project directory and may
02
The Build Specification should be created before you can compile the FPGA VI into an FPGA
application. If you click the Run button without first making a build specification, LabVIEW
ht
automatically creates and specifies a default build specification for the corresponding VI. LabVIEW
uses the build options you set to generate the HDL and bitfile from the block diagram. If you create
ig
multiple build specifications, you can specify which is the default build specification. Right-click a build
specification under an FPGA target in the Project Explorer window and select from the following
options. The options can vary depending on the hardware target.
yr
a. In the Project Explorer window, under FPGA Target, right-click Build Specifications and select
New»Compilation.
b. From the My Compilation Properties dialog box, select Source Files category. Move the
C
1-22 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
2. Press <Ctrl> and click Run to force a compile, compiling the VI regardless of the current state of
the bitfile. LabVIEW does not run the VI after finishing the compile.
en
3. To check if there is a valid bitfile already created for the VI, right-click the Build Specification of
the VI in the project and select Build.
4. Right-click the Build Specification of the VI in the project and select Rebuild to force a compile,
m
compiling a VI no matter which state the current bitfile is in. LabVIEW does not run the VI after
finishing the compile.
tru
Stages of the Compilation Process
Each step of the compilation process includes some subtleties and information you can use. NI
ns
exposes this information in a timely manner. You can use LabVIEW FPGA software to automatically
or manually stop the compilation at any time due to an error, an estimate out of bounds, or a
user-directed cancel.
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
ts
3. Once compilation starts, do not edit the VI.
4. Create a compilation queue by starting another compilation while the first is still running.
en
m
tru
ns
lI
Do not edit VI while compiling. Either abort the compilation or save the modified VI under a different
filename and perform your edits there. You can create a queue of compilations by opening another
na
FPGA VI and starting a compilation for that VI while the first compilation is still running. Once the first
compilation finishes, the next will start.
io
Compilation Status Window—Configuration Report
This type of report displays project information and the Xilinx compiler configuration you specified in
at
1-24 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
RAM.
• Used—Indicates how many of the FPGA elements the compiled FPGA VI uses.
en
• Total—Indicates the total number of FPGA elements in the FPGA.
• Percent—Indicates the percentage of the FPGA elements that the FPGA application uses. If the
Percent is greater than 100, a warning message alerts you that the estimated device utilization
m
exceeds 100 percent. Depending on the FPGA VI and hardware, Xilinx may still be able to fit
everything on the FPGA. However, you may want to stop the compilation and optimize the
tru
FPGA VI.
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
ts
component must be able to run. Some FPGA VI components, such as Timed Loops, are visible on
the block diagram, while others, such as CLIP, are not. If Requested (MHz) is greater than
en
Maximum (MHz), the compilation fails. Click Investigate Timing Violation to analyze the timing
violations.
• Maximum (MHz)—Indicates the theoretical maximum compilation rate, in megahertz, for the FPGA
m
VI or FPGA VI component. For specific FPGA targets, the Xilinx compiler does not attempt to
optimize if a design meets the timing requirements.
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
1-26 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
m
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
ts
Use the FPGA Compile Worker window to view information about a compilation. This window contains
the following components:
en
• Status—Displays status information for the current compilation job.
• Jobs—Displays information about the current compilation jobs.
• Configure—Displays the Configure Compile Worker dialog box.
m
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
1-28 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
Requirements
To complete this exercise, it is necessary to have access to the following hardware and software.
en
Software:
• LabVIEW 2023 Q3 (32-bit)
m
• NI-DAQmx 2023 Q3 (32-bit)
LabVIEW Real-Time Module 2023 Q1 (32-bit)
tru
•
ns
Hardware:
• An NI CompactRIO from either the 904x or 905x product lines
lI
• USB Type C or RJ45 Ethernet connection
• NI-9211 Thermocouple Input C Series Module
•
• Windows 10 PC na
NI-9474 Digital I/O C Series Module
io
Scenario
at
Compile Simple Math VI from Exercise 1-1 to run on the cRIO-9056 FPGA. The compile server
converts Simple Math VI to a bitstream file, which can be loaded and executed on the FPGA.
N
Implementation
3
Part A
02
Modify Basic cRIO FPGA.lvproj to execute Simple Math VI on the FPGA target and start the
compilation process:
1. From the C:\Exercises\FPGA\Executing a VI directory, open Basic cRIO FPGA.lvproj.
2
2. From Project Explorer, right-click cRIO-9056»Chassis and select Deploy to deploy the chassis
settings.
ht
Figure 1-4. Basic cRIO FPGA.lvpoj with VI in FPGA Target Execution Mode
ts
en
m
tru
ns
lI
na
io
at
a. Open and run Simple Math VI. When executing on the FPGA target, click Run in LabVIEW to
start the compilation. Use the local compile server to specify that LabVIEW use the compilation
tools installed on the local computer, called localhost.
3
Note You may see a Windows Security Alert dialog box if a Windows firewall is blocking
the compile server. Click Unblock when prompted to continue compilation.
2
b. Notice that LabVIEW automatically created a Build Specification for the Simple Math VI in
ht
1-30 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
Part B
When the compilation is complete, examine the generated reports and test the VI on the FPGA. The
Compilation Status window indicates when the compile has finished, as shown in Figure 1-5.
ts
en
m
tru
ns
lI
na
io
at
N
3
02
5. Examine the reports generated during compilation. Depending on your specific FPGA target, you
2
can select the following reports from the Reports pull-down menu:
a. In the Compilation Status window, Summary is selected by default and is available only when
ht
the compilation is complete. This report contains a summary of the generated bitfile.
b. Configuration—This report displays project information and the Xilinx compiler configuration
ig
utilization as estimated before the synthesis of the FPGA VI. Take particular note of the
Percent field, which indicates the percentage of the FPGA elements that the VI uses. If any
op
Percent value exceeds 100 percent, then the compilation may fail.
Note The Compilation Status window for the cRIO-9056 does not have this item.
C
ts
f. Estimated timing (map)—This report contains a summary of the FPGA clocks, as estimated
en
during the mapping of the FPGA VI.
g. Final timing (place and route)—This report contains a summary of the FPGA clocks after the
routing step of compilation.
m
6. Close the Compilation Status window.
Test
tru
1. Run the VI:
a. Change the X and Y values and click Run.
ns
2. Save and close Simple Math VI.
3. Save and close Basic cRIO FPGA.lvproj.
lI
End of Exercise 1-2
na
io
at
N
3
2 02
ht
ig
yr
op
C
1-32 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
F. Compilation Considerations
Objective: Explore other compilation methods and error.
ts
Moving wires on the block diagram is considered a cosmetic change. If the FPGA VI has any
non-cosmetic changes, then LabVIEW will recompile your VI on the next run. Here are some examples:
en
• Change the algorithm on the block diagram.
• Add or delete functions on the block diagram.
• Rename control or indicator.
m
• Add control or indicator.
tru
Compiling an FPGA VI Remotely: Select a Compile Server
At the start of each compilation, LabVIEW will ask you to select a compile server unless configured
otherwise.
ns
lI
na
io
at
N
3
Use the Select Compile Server dialog box to specify a compile server for the current build specification.
02
To access this dialog box, select Build from the Build Specification shortcut menu. LabVIEW displays
this dialog box by default.
2
To disable the Select Compile Server prompt, select Tools»Options to display the Options dialog box
and select FPGA Module from the Category list, then remove the checkmark from the Prompt to select
a compile server for each compilation checkbox.
ht
• Use the local compile server—Specifies that LabVIEW uses the compilation tools installed on the
local computer, called localhost.
ig
• Connect to a network compile server—Specifies that LabVIEW uses the compilation tools installed
on another computer or that LabVIEW uses localhost when authentication is required.
yr
• Compile server name—Displays the name or IP address of the computer running the compile
server.
op
• User name—Displays the name of the account that you use to log into the compile server.
• Configure—Displays the Configure Remote Compile Server dialog box.
C
• Connect to LabVIEW FPGA Compile Cloud Service—Specifies that LabVIEW uses the compilation
tools available through the LabVIEW FPGA Compile Cloud Service.
• User name—Displays the name of the account that you use to log into the LabVIEW FPGA
Compile Cloud Service.
• Configure—Displays the Configure Cloud Service dialog box.
ts
• Prompt to select a compile server for each compilation—Specifies whether LabVIEW prompts you
to select a compile server for each compilation.
en
Compiling an FPGA VI Remotely: LabVIEW FPGA Compile Cloud Service
This LabVIEW FPGA Compile Cloud Service is included in Standard Service Program (SSP) contracts
m
for no additional fee. If you have an active SSP, NI recommends that you use this service. It allows
you to offload your FPGA compilations to high-performance servers and workers in the cloud for faster
tru
compilation times. You can also execute multiple parallel compilations using this service.
ns
lI
na
io
at
N
3
02
the FPGA device. Also, the compilation tools require several GB of hard drive space, so you can save
hard drive space. By default, LabVIEW assumes the LabVIEW FPGA Compile Server is installed on the
ht
local computer.
ig
yr
op
C
1-34 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
Process Overview:
ts
1. You can create an FPGA VI on a development computer and click the Run button in LabVIEW.
2. LabVIEW submits the compile job to the compile server.
en
3. The compile server sends the compile job to an available compile worker, which compiles the
FPGA VI.
4. The compile worker submits the compiled VI back to the compile server.
m
5. The compile server submits the compiled VI back to the development computer. The FPGA VI is
ready to deploy to the FPGA target.
tru
ns
lI
na
io
at
Resource utilization—The design requires more FPGA resources than are available on the FPGA.
3
•
the loop rate you want, you must modify the application to increase the loop rate. These
modifications can change the way you create and design the FPGA VI.
Size—Relates to the actual amount of space the application uses on the FPGA. If the application
2
•
requires more hardware components than are physically available on the FPGA, the compile fails,
and the application cannot run on the FPGA.
ht
ig
yr
op
C
ts
en
m
tru
ns
lI
na
io
Use the Xilinx Options page to define the Xilinx options to use when you compile an FPGA VI. The
options you can specify vary depending on the target. In general, you do not need to adjust the options
at
on this page unless the FPGA VI fails to compile. Use the information from the Compilation Status
window to determine which options on this page might help the FPGA VI compile successfully.
N
Resources For more information about different design strategies and optimization options,
refer to the Xilinx Documentation.
3
• Use recommended settings—Specifies that the Xilinx compiler uses the options that the target
provides. By default, this checkbox contains a checkmark. Remove the checkmark to customize
Xilinx options on this page.
2
• Design Strategy—Specifies a set of Xilinx options for the application. You can select from preset
configurations to minimize the compilation time, maximize timing performance, or optimize the
ht
design area. You can override any of the options of a design strategy to create a custom
configuration.
ig
• Balanced—Selects options that balance the compilation time with the amount of effort the
Xilinx compiler uses to meet the timing and design objectives of the FPGA application.
yr
• Minimum Compilation Time—Selects options that minimize the compilation time by reducing
the mapping effort of the Xilinx compiler.
op
• Timing Performance—Selects options that maximize the timing performance of the FPGA
application.
• Area—Selects options that optimize the area usage on the FPGA.
C
• Custom—Indicates that options might not match any of the preset configurations.
1-36 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
G. Basic Optimizations
Objective: Learn common techniques to optimize FPGA performance and the compilation time.
ts
These types of optimizations are relatively easy to implement:
• Require no major changes in code architecture.
en
• Should be basic programming practice for all FPGA VIs.
m
When data is transferred across the bus between the FPGA and RT, it must be broken down into 32-bit
packets. This limitation is due to the number of data transfer lines on the bus. Therefore, if you have
tru
a front panel element that uses more than 32 bits, then that front panel element must be broken down
into several 32-bit chunks and passed along the bus piecewise. This breaking down of the data
reduces overall transfer speeds, and as such, having larger front panel objects should be avoided.
ns
Limit Front Panel Arrays
• Avoid using arrays on the front panel.
lI
• All arrays must be of fixed size.
Compile fails if the array size is larger than available FPGA resources.
na
•
When you wire an array as an input to an FPGA VI or function, the FPGA compiler creates the
equivalent of a For Loop to process each element of the array in sequence. If you wire a cluster as an
input to an FPGA VI or function, the FPGA compiler creates parallel logic for each element of the
3
cluster. The relationship between arrays and clusters is recursive, such that if you wire a cluster of
02
arrays as an input, the arrays are processed in parallel, and the array elements are processed
sequentially.
Note Performing operations on arrays can limit the maximum top-level or derived clock
2
rate. To maximize the FPGA clock rate, process single data points instead of arrays.
ht
ig
yr
op
C
ts
Bitpacked logic maintains the same information using fewer controls:
• Display binary data as an integer.
en
• The U8 numeric control can replace eight Boolean controls.
• Use a Boolean array or cluster.
• Due to the small size of Boolean controls/indicators, this is an acceptable exception to the rule of
m
avoiding arrays/clusters on the front panel.
tru
You can use functions to manipulate data in the same manner as you would otherwise.
ns
lI
na
io
at
N
Choose the smallest feasible data type for a given control or indicator.
2 02
ht
ig
yr
op
In this example, the case selector can be reduced in size from an I32 (32-bit signed integer) to an U8
(8-bit unsigned integer) while maintaining the desired case selector values.
C
1-38 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
m
tru
ns
Avoid Large Functions: Quotient & Remainder
• Consumes significant space on the FPGA:
lI
• Quotient & Remainder often used to increment based on iteration number.
Consider replacing with actual Increment function and Shift Register.
na
• io
at
N
3
2 02
ht
ig
yr
op
C
ts
en
m
tru
Additional Resources
ns
Topic Website
lI
FPGA Fundamentals: Basic of Field-Programmable Gate Arrays
na
LabVIEW FPGA Compilation Process: From Run Button to Bitfile
Module
N
1-40 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
2. Is the statement true or false?
A bitfile (.lvbitx) is generated when an FPGA VI compiles successfully.
a. True
m
b. False
tru
3. Which of the following practices are the best ones when developing FPGA VIs?
Select all that apply.
ns
a. Avoid large functions such as Quotient & Remainder, if possible.
b. Choose the smallest data types required for your application.
lI
c. Use as many front panel objects and array indicators as possible on top-level FPGA VIs.
na
io
at
N
3
2 02
ht
ig
yr
op
C
ts
en
2. Is the statement true or false?
A bitfile (.lvbitx) is generated when an FPGA VI compiles successfully.
a. True
m
b. False
tru
3. Which of the following practices are the best ones when developing FPGA VIs?
Select all that apply.
ns
a. Avoid large functions such as Quotient & Remainder, if possible.
b. Choose the smallest data types required for your application.
lI
c. Use as many front panel objects and array indicators as possible on top-level FPGA VIs.
na
io
at
N
3
2 02
ht
ig
yr
op
C
1-42 | ni.com
ts
2
en
Using FPGA I/O
m
and Timing
tru
ns
lI
na
Explore techniques for accessing and controlling I/O as well
as the timing of the FPGA VI.
io
Topics
at
A. Configuring FPGA I/O
B. Exploring I/O Types
N
Exercises
ht
ts
• Use FPGA I/O items to access I/O in the FPGA VI.
• In the NI Example Finder, navigate to
en
Toolkits and Modules»FPGA»CompactRIO»Module Specific IO.
m
tru
Inputs and outputs (I/O) on FPGA targets allow you to connect the FPGA target to other devices. FPGA
I/O resources are fixed elements of the FPGA targets that you use to transfer data among the different
parts of the system. On some FPGA targets, FPGA I/O resources correspond to lines on front panel
ns
connectors, PXI backplanes, or RTSI connectors. On other FPGA targets, FPGA I/O resources are
nodes inside FPGAs that connect the part of the FPGA designed by NI with the part of the FPGA you
design through FPGA VIs. For component-level IP (CLIP), I/O resources are nodes inside FPGAs that
lI
connect CLIP with the FPGA VI. Each FPGA I/O resource has a specific type, such as digital or analog.
An FPGA target might have multiple I/O resources of the same or different types. You can create FPGA
na
I/O items, determine the I/O resources on the FPGA target that you want to use, and then assign
unique names to the I/O resources you use.
io
Note Refer to the specific FPGA target hardware documentation for information about
supported features and I/O functionality on the FPGA target you use. Refer to Managing
at
Shared Resources for information about arbitrating I/O resources.
Resources For more information, refer to the Using FPGA I/O (FPGA Module) section from
N
ts
• Select which FPGA I/O channels you want to add.
Some developers find it simpler to see all available channels at all times, whereas others prefer to only
en
have the project contain the channels necessary for their application. Neither method creates more
efficient code than the other, so using all FPGA I/O channels is a matter of preference. You can also
use the FPGA Project Wizard to create your project. In this case, all FPGA I/O is added automatically.
m
After select to add an Existing Target for a CompactRIO target from the Add Targets and Devices
tru
dialog box, you will be prompted with the Discover C Series Modules? dialog box. Selecting Discover
will halt any current FPGA execution and then add all the channels in all the modules. If you do not
want to halt your current execution or you do not want to add all the channels in all the modules,
select Do Not Discover. You can manually add each module and channel to your Real-Time project,
ns
as shown in the following images.
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
2-4 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
4. To name your I/O, click the default name and enter a meaningful name for your application.
5. Click OK to add the I/O to the project.
en
m
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
ts
•
• FPGA I/O Property Node—Reads or sets property attributes of a specific channel or C Series
en
module.
m
tru
ns
lI
na
io
Demonstration: Placing I/O Nodes
at
N
3
2 02
ht
ig
yr
op
C
2-6 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
The I/O types you can access and use with your FPGA are the following:
• Digital Line—Writes and/or reads Boolean value to/from digital line.
en
m
tru
• Digital Port—Writes and/or reads unsigned integer value to/from digital port (grouping of digital
lines).
ns
lI
•
•
R Series—Integer values
na
Analog I/O—Writes or reads data to/from an analog channel.
• Other
3
• Motion
02
• CAN
2
ht
ig
yr
op
C
ts
If the digital I/O line or port is bidirectional and you want to change the direction of the line or port
from the FPGA VI, use the I/O Method Node and select Set Output Enable method.
en
m
tru
Creating Counters from Digital I/O
Counters can range from simple event counters to complex signal measurements with multiple inputs
and outputs. You can build a simple event counter with the FPGA I/O Method Node function in a While
ns
Loop. For example, you can use the Wait on Rising Edge method to wait for a rising edge to occur on
a digital input terminal.
lI
When the FPGA I/O Method Node detects an edge, the block diagram increments the counter value
and stores the counter value in a shift register on the While Loop. You can use a front panel indicator
or local variable to view the counter value.
na
Note The I/O resources available and the associated methods vary by target and
io
configuration. Refer to the specific FPGA target hardware documentation for information
about available methods and I/O resources.
at
You can also build more advanced counters from the FPGA I/O functions. For example, an application
might require a counter with independent count up, count down, and gate inputs and an output.
N
3
2 02
ht
ig
yr
2-8 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
•
(voltage, ohms, etc.).
en
m
tru
If the FPGA target you use includes analog input resources, you can configure an FPGA I/O Node to
read an analog input value. If you configure the FPGA I/O Node to read an analog input, the FPGA I/O
Node might initiate a conversion, wait for the result, and then return the binary representation of the
ns
voltage as a signed integer or fixed-point number. The analog input process and the resulting data type
vary by FPGA target. For many FPGA targets, you create the FPGA VI to use the data returned by the
analog input FPGA I/O Node for operations within the FPGA VI. You can also pass the data back to
lI
the host VI and, if applicable, convert the data to a voltage or other physical quantity if you have a
transducer attached to the FPGA target analog input.
na
The equation you use to convert the binary representation to a physical quantity depends on the FPGA
target and transducer. For example, with an NI PXI-7831R device, use the following equation to
io
convert the binary representation to voltage: Input Voltage = (Binary Code / 32768) x 10.0 V.
Resources For more information, refer to the specific FPGA target hardware
at
documentation.
N
3
2 02
ht
ig
yr
op
C
ts
en
m
tru
All R Series multifunction devices have dedicated ADCs and digital-to-analog converters (DACs) on
every analog input/output channel, making it possible to sample/update all channels simultaneously or
at different rates. With independent ADCs, you can sample every channel on the device at the
ns
maximum rate (up to 1 MS/s). You can program the independent DACs to update analog output
channels at rates up to 1 MS/s.
lI
na
io
at
N
3
2 02
ht
ig
yr
op
By using a LabVIEW FPGA Analog Input I/O Node that is reading from all eight channels of the R Series
device in the same While Loop, the program samples from all eight channels simultaneously. The lower
C
loop running in parallel uses the LabVIEW FPGA Analog Output I/O Node and updates all eight analog
output channels at 1 MS/s.
2-10 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
• Analog Input and Analog Output modules use fixed-point data type.
en
• Fixed-point data type:
• Provides some of the flexibility of floating-point data type.
• Maintains the size and speed advantages of integer arithmetic.
m
tru
ns
lI
Using CompactRIO I/O
na
io
Different modules can have:
Fixed-point configurations
at
•
The fixed-point data type is a more efficient (for FPGA size and speed) implementation of floating-point
02
data than the DBL/SGL data type. Different modules have different fixed-point configurations because
each module data has different ranges and resolutions. Some I/O nodes return scaled and calibrated
fixed-point values. The presented example shows that the data type of each of these three different
2
ts
en
m
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
2-12 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
You can right-click the FPGA I/O Node on the block diagram and select Show Error Terminals from the
shortcut menu to add standard LabVIEW error in and error out parameters to the function. If an error
occurs, you might receive incorrect data. Add error terminals to make sure the data you receive is
en
valid. FPGA targets might report errors differently.
Resources For more information, refer to the specific FPGA target hardware
m
documentation.
tru
ns
lI
na
io
at
Note Adding error in and error out parameters increases the amount of space the function
uses on the FPGA target. The error in and error out parameters can also cause slower
N
Showing error terminals and processing errors uses FPGA resources. When resources are tight:
02
• Use sequence structures for data flow. This has minimal cost on the FPGA.
• Show error terminals only for modules whose functions are critical to system operation.
• Show terminals only once per module if multiple calls are made to the module. The exception to
2
this rule is for modules that have specific errors. Checking once allows you to check for general
errors.
ht
• Do not pass error clusters through the program or display the error cluster on the front panel.
• Unbundle the source and/or code items and handle the errors immediately.
ig
yr
op
C
ts
•
en
• CompactRIO modules and USB R Series
• Return fixed-point data in engineering units (voltage, ohms, etc.)
m
Resources For more information regarding module-specific errors, refer to the
CompactRIO Error Codes (FPGA Interface) topic in LabVIEW Help. Checking for errors
tru
once-per-module is sufficient for most applications.
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
2-14 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
m
tru
ns
lI
na
io
at
N
The Timing palette contains most of the FPGA timing Express VIs, except those related to the Timed
Loop. Timing control is critical to your FPGA application. The timing Express VIs include the Loop
Timer, Wait, and Tick Count Express VIs.
3
02
Loop Timer Express VI—Use the Loop Timer Express VI to control a For Loop or While Loop and set
the iteration rate of the loop. A common use of the Loop Timer Express VI is to control the acquisition
or update rate of an analog or digital I/O function.
2
Wait Express VI—Adds an explicit delay between two operations on the FPGA. Use the Wait Express
VI to control the pulse length of a digital output or add a trigger delay between the trigger signal and
ht
Tick Count Express VI—Returns the current value of the FPGA clock. Use the Tick Count Express VI
ig
Rollover Size of Internal Counter determines the maximum time the timer can track.
ts
en
m
tru
ns
Consider the possibility for the counter to rollover, meaning that it will go back to 0 after it reaches
its maximum count.
Each timing Express VI has a configuration dialog box that appears when you first add the VI to the
lI
block diagram or when you right-click the VI and select Properties. The dialog box allows you to
configure the timing units and the size of the internal counter. The available Counter Units include
na
ticks, a single clock cycle, the length of which is determined by the clock rate for which the VI is
compiled, microseconds (µs), and milliseconds (ms). The Size of Internal Counter value determines the
maximum time the timer can track. The free running counter rolls over when it reaches the maximum
io
of Size of Internal Counter specified in the configuration dialog box. To save space on the FPGA, you
should use the smallest Size of Internal Counter possible for the FPGA VI.
at
Tick Period:
N
•
02
takes longer to execute than the specified interval, the Loop Timer Express VI returns immediately and
establishes a new reference time stamp for subsequent calls. To manage execution rates with the
ht
Loop Timer Express VI, place the Loop Timer Express VI in the first frame of a Flat Sequence structure
or a Stacked Sequence structure and put the rest of the code in subsequent frames.
ig
yr
op
C
2-16 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
• mSec—milliseconds
en
Size of Internal Counter:
• 32 Bit
• 16 Bit
m
• 8 Bit
tru
Size of Internal Counter determines the maximum time a timer can track. To save space on the FPGA,
use the smallest Size of Internal Counter possible.
ns
lI
na
io
at
Second iteration:
02
• Adds Count to initial time and waits until Count has elapsed from the initial recorded time.
• Executes the code in the next frame after Count has elapsed.
2
ht
ig
yr
op
Subsequent iterations:
• Loop Timer continues to increment the time record it initiated upon the first call.
C
ts
The Loop Timer Express VI functionality here is like the Wait Until Next ms Multiple function that you
en
may be familiar with already in regular LabVIEW on Windows.
The second execution adds timer count to the initial time and waits until count has elapsed.
m
If Loop Timer is parallel to code in the loop (meaning no sequence structure):
tru
• The first iteration is not guaranteed to be synchronized with the desired timing.
• Code in a loop can execute twice within the first desired loop time.
• Subsequent iterations match the desired timing synchronization.
ns
If an execution instance is missed, such as when the logic in the loop takes longer to execute than the
specified Count:
lI
• Loop Timer returns immediately and establishes a new reference time stamp for subsequent calls.
• No delay.
na
io
at
N
3
2 02
In the presented example, the Loop Express VI behavior is not the same as the Wait Until Next ms
ht
Multiple function.
1. Count = 100
ig
2. For the first three iterations, the code execution time is less than 100.
yr
3. On the fourth iteration, the code execution time is longer than Count (100). Therefore, on the next
iteration, the Loop Timer Express VI detects that an execution instance was missed, returns
immediately, and establishes a new reference time stamp for subsequent calls.
op
If the time specified by the Count is less than the time it takes the FPGA target to execute the code
in the While Loop, the Loop Timer VI does not affect the timing of the While Loop.
C
2-18 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
• You can configure the data rate at which the NI-9234 module acquires and returns data.
• Static/Programmatic Configuration
en
• Module Properties dialog box
• FPGA I/O Property Node
m
tru
ns
lI
na
io
at
N
3
02
Note To achieve the maximum data rates for the 9234, FPGA programming is required.
C
ts
Loop Condition Terminals
en
When programming the FPGA you can connect a False constant to the Loop Condition Terminal to
have that code execute indefinitely on the FPGA or until it is powered off. You need to take into
account that there will not be a way to stop that code from executing if you do so, other than removing
power from your device.
m
tru
ns
lI
While Loop Iteration Terminal Maximum na
io
• The iteration terminal count will keep outputting 2,147,483,647 once it reaches this value.
• If you need a counter to rollover when it reaches its maximum value, you should implement your
at
own counter.
N
3
2 02
ht
ig
yr
op
C
2-20 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
Requirements
To complete this exercise, it is necessary to have access to the following hardware and software.
en
Software:
• LabVIEW 2023 Q3 (32-bit)
m
• NI-DAQmx 2023 Q3 (32-bit)
LabVIEW Real-Time Module 2023 Q1 (32-bit)
tru
•
ns
Hardware:
• An NI CompactRIO from either the 904x or 905x product lines
lI
• USB Type C or RJ45 Ethernet connection
• NI-9211 Thermocouple Input C Series Module
•
• Windows 10 PC na
NI-9474 Digital I/O C Series Module
io
Scenario
at
You are presented with a LabVIEW project that has been started for you which you will complete
throughout various exercises in this course. Review the design requirements for our fan control and
monitoring project and then proceed to the implementation section.
N
The application requirements state that this application must acquire the fan acceleration data at a
rate of 10.240 kHz. In this exercise, you will implement a process to acquire the tachometer and
3
acceleration signal from the NI 9234 on the FPGA at a loop rate of 10.240 kHz. This module uses the
02
Functional Requirements for Fan Embedded Control and Monitoring Application Using LabVIEW
Real-Time and LabVIEW FPGA:
2
• Control the fan speed using a PID control loop—This application must read the user-specified
fan speed setpoint, acquire the tachometer signal, calculate the actual fan speed, and use a
ht
PID algorithm to calculate the analog voltage level to output to set the fan speed to the
user-specified setpoint. This entire control algorithm must execute at a rate of 5 kHz. The PID
ig
loop period must be 200 microseconds with a maximum jitter of 10 microseconds. The fan
speed control is critical because you must protect the fan, so the fan speed control algorithm
yr
of 10.240 kHz.
• Analyze fan acceleration data—This application must convert the acceleration data to units of
g and determine if the acceleration has exceeded the maximum threshold.
C
Lesson 2
set all outputs to a safe level to turn off the fan. The safe state logic is critical because you must protect the fan, so the safe state
logic should be implemented in hardware circuitry for maximum reliability and safety. Failure conditions have the following reasons:
|
m
ni.com
tru
• NI 9234 analog input module or NI 9263 analog output module outputs an error.
• If the fan acceleration exceeds the maximum threshold, then implement safe state logic, log the acceleration waveform to file, and
display the latest over-limit acceleration waveform to the user interface on the Windows PC—Each acceleration waveform must
ns
contain 2 seconds of data acquired at 10.24 kHz. The application must create a separate log file each time the fan acceleration
exceeds the maximum threshold.
lI
You will create the VI and logic to process the signals specified in the communication diagram.
Figure 2-1. Fan Control—Communication Diagram
na
io
at
N
3
2 02
ht
y rig
op
C
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
• The user interface on the Windows PC must allow the user to set the following,
as shown in Figure 2-2:
• Setpoint for the speed (RPM) of the fan
• PID control configuration for the control algorithm controlling the fan speed
• Maximum acceleration threshold (g)
ts
• Maximum fan speed threshold (RPM)
Run/stop the fan control process
en
•
m
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
• The user interface on the Windows PC must also display the following,
as shown in Figures 2-3 and 2-4:
• Current FPGA PID Loop state
• Actual fan speed (RPM)
• Current acceleration (grms)
ts
• Latest fan acceleration waveform (g) that exceeded the maximum acceleration threshold
Actual FPGA PID control loop period (ticks)
en
•
m
Figure 2-3. User Interface – Data Monitoring
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
2-24 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
m
tru
ns
lI
na
io
at
N
3
Note The first few exercises for the fan control and monitoring project will use the FPGA
02
VI front panel for control of the application. Later exercises will either use the UI shown
above for control or a modified RT VI front panel.
2
ht
ig
yr
op
C
Implementation
1. From the C:\Exercises\FPGA\Acquire Tachometer and Acceleration Signals directory,
open [FPGA] Fan Control (prototype) [cRIO-9056].lvproj.
2. Configure the CompactRIO target:
a. In Project Explorer, right-click the cRIO RT target and select Properties.
ts
b. In the General category, set the IP Address to the IP address of your cRIO.
en
c. Click OK.
3. Rename Mod1/AI0 to Tach.
a. Expand cRIO-9056»Chassis»FPGA Target»Mod1. Right-click Mod1/AI0 and select Rename.
m
This FPGA I/O channel acquires the tachometer signal.
4. In Project Explorer, right-click cRIO-9056»Chassis and select Deploy to deploy the chassis
tru
settings.
5. Save the project.
ns
Create the FPGA VI
1. In Project Explorer, right-click the FPGA target and select Add»File.
2. Navigate to C:\Exercises\FPGA\Acquire Tachometer and Acceleration Signals\FPGA Main.vi
lI
directory.
na
3. Click Add File.
4. In Project Explorer, double-click FPGA Main.vi to open it.
5. Notice that the front panel of the VI contains some decorations that will help you organize the
io
controls and indicators of the FPGA VI as you develop it.
at
N
3
2 02
ht
ig
yr
op
C
2-26 | ni.com
ts
en
6. Create the block diagram, as shown in Figure 2-5, to acquire and time signals from channels on the NI 9234 module.
m
2 3 4
tru
ns
1
lI
5
na
7
at
N
3
© National Instruments Corporation
02
1 Sequence structure—Right-click the Sequence structure and select Add Frame After to add additional frames.
2 Data Rate—Configure the acquisition data rate of the NI 9234 module. Place down an FPGA I/O Property Node. Right-click it and select
2
Select Item»FPGA Target»Mod1. Click Property and select Data Rate. Right-click the input and select Create»Control.
3 Input Configuration—Configure the input configuration of the Tach and Mod1/AI1 channels of the NI 9234 module. Right-click the
corresponding FPGA I/O Property Node and Select Item»FPGA Target»Mod»Tach or select Item»FPGA Target»Mod1»Mod1/AI1.
ht
y
op
C
Lesson 2 Using FPGA I/O and Timing
7. Rearrange the front panel, as shown in Figure 2-6, to organize the controls and indicators.
ts
en
m
tru
ns
lI
na
io
at
N
3
2 02
8. Set the Data Rate control to 10.240 kS/s (NI 9234), then right-click it and select
Data Operations»Make Current Value Default to set the default value of this control when you
ht
2-28 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
Synchronization Considerations
ts
• Some applications using C Series I/O modules require a high level (<100 ns) of synchronization
between channels.
en
• Vibration or sound measurement
• Multiple types of measurement
m
Synchronizing On-Demand C Series Modules
tru
On-Demand Modules Use the Loop Timer VI to time their loop rate.
Examples:
ns
• Digital modules (NI-9474, 9401)
• Analog modules with a SAR ADC (NI-9215, 9263)
lI
• Multiplexed modules (NI-9211, 9207)
SAQ ADC
na
Successive approximation register (SAR) analog-to-digital (ADC).
The type of ADC that an analog C Series module uses can be found in its
specifications.
io
• Place all channel reads or updates in the same I/O node.
at
• The maximum loop rate possible is limited by the slowest channel in the FPGA I/O node.
• Digital channels can execute in one click tick.
• Analog channels require multiple clock ticks.
• Each additional channel in multiplexed modules requires additional clock ticks.
ts
en
m
tru
ns
Synchronizing Delta-Sigma C Series Modules
lI
Delta-Sigma Modules Many modules designed for high-speed dynamic acquisition use
delta-sigma ADCs. Internally timed and use data rate property to set their
loop rates.
na
io
Examples:
• NI 923x
at
• You can synchronize multiple delta-sigma modules and different delta-sigma models.
• Modules must use the same primary timebase source.
Modules must start acquisition at the same time.
2
2-30 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
1. Set Data Rate property node for each module to same value.
2. Use the same I/O node to start all modules.
en
3. Place all channels in the same I/O node.
m
tru
ns
lI
na
io
at
N
3
2 02
ht
ts
Use the Wait Express VI to create a delay between events in an FPGA VI. For example, you might
want to create a delay between a trigger and a subsequent output. You can place the LabVIEW code
for the trigger in the first frame of a sequence structure. Then place the Wait Express VI in the
en
following frame. Finally, place the LabVIEW code for the output in the last frame of the sequence
structure. You can also create a series of delays using multiple Wait VIs in a sequence structure, as
shown in the following block diagram.
m
tru
ns
lI
Wait Express VI Configuration
na
io
The Express VI will provide a delay for a certain time interval before the output data dependence
becomes valid.
at
• Counter Units
N
3
2 02
ht
2-32 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
• Returns the value of a free-running FPGA counter in the units specified.
• Use Tick Count Express VI to measure time between events.
en
Examples:
• Measure the time between edges on a digital signal.
m
• Determine the execution time of a section of code.
tru
ns
Use Cases to Measure Time between Events
lI
na
io
at
N
3
Use the Tick Count Express VI to measure the time between events, such as edges on a digital signal.
You can use the Tick Count Express VI when you need to determine the period, pulse width, or
02
frequency of an input signal or if you want to determine the execution time of a section of LabVIEW
code.
2
For example, to determine the amount of time it takes a function or a section of LabVIEW code to
execute, use a sequence structure with two Tick Count Express VIs, as shown in the following block
diagram. Place one Tick Count Express VI in the first frame of the sequence structure. Then place the
ht
LabVIEW code you want to measure in the second frame of the sequence structure. Finally, place the
other Tick Count Express VI in the last frame of the sequence structure. You can then calculate the
ig
difference between the results of the two Tick Count Express VIs to determine the execution time.
Subtract one from the result of the calculation to compensate for the execution time of the Tick Count
yr
Express VI.
op
C
The Tick Count Express VI has an internal counter to track time. The internal counter for each Tick
Count Express VI you place on the same block diagram shares the same start time. Therefore, every
Tick Count Express VI that uses the same values for the Counter Units and Size of Internal Counter
options tracks the same time. For example, if you call two Tick Count Express VIs that use the same
Configure Tick Count options at the same time, they return the same Tick Count value.
ts
The Tick Count Express VI returns an integer value in Counter Units. The Tick Count value cannot
represent any fractional time periods that might occur when Counter Units is configured for uSec or
en
mSec. Configuring Counter Units for uSec or mSec can result in timing measurements that have an
accuracy of ±1 Counter Unit value. For example, you can configure the Tick Count Express VIs in the
block diagram above to measure time in milliseconds. If the first Tick Count Express VI executes at
m
47.9 milliseconds, Tick Count returns a value of 47. If the second Tick Count Express VI executes at
53.2 milliseconds, Tick Count returns a value of 53. Although this example has a 5.3-millisecond
delay, the difference between the returned values is 6 milliseconds.
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
2-34 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
Timestamp measurements are done in parallel because of the way the FPGA code is implemented. If
any new code is not made within the same combinatorial path as another set of code, the code
execution times are independent from one another. Because of this behavior, whenever you add code
en
to an FPGA VI for benchmarking, it has no effect on the loop execution time, provided that the code
you are benchmarking takes longer to execute than the three ticks required to obtain and observe the
loop rate.
m
tru
ns
lI
na
By placing a Feedback Node inside a subVI, you can now easily place that subVI in any loop. The
io
Feedback Node inside the subVI allows the subVI to access a value from the previous iteration of the
loop.
at
You cannot do this with a shift register. To copy the shift register code to a different loop, you must
manually create another shift register in the other loop and copy the rest of the code. In contrast, by
N
using a feedback node inside a subVI, you only have to place the subVI inside the other loop.
3
2 02
ht
ig
yr
op
C
ts
Requirements
To complete this exercise, it is necessary to have access to the following hardware and software.
en
Software:
• LabVIEW 2023 Q3 (32-bit)
m
• NI-DAQmx 2023 Q3 (32-bit)
• LabVIEW Real-Time Module 2023 Q1 (32-bit)
tru
• LabVIEW FPGA Module 2023 Q1 (32-bit)
• NI CompactRIO 2023 Q3 (32-bit)
ns
Hardware:
• An NI CompactRIO from either the 904x or 905x product lines
lI
• USB Type C or RJ45 Ethernet connection
• NI-9211 Thermocouple Input C Series Module
•
•
NI-9474 Digital I/O C Series Module
Windows 10 PC na
io
Scenario
Add benchmarking code to calculate the actual loop period of different sorting algorithms. The
at
exercise aims to compare the effectiveness of various sorting algorithms and identify the fastest one
for sorting a large dataset. You will create the VI and logic to process the signals specified in the
N
communication diagram.
3
2 02
ht
ig
yr
op
C
2-36 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
Benchmarking
en
m
tru
ns
lI
Figure 2-7. Fan Control—Communication Diagram
na
io
at
N
3
02 2
ht
rig y
op
C
© National Instruments Corporation | 2-37
Lesson 2 Using FPGA I/O and Timing
Implementation
1. From the C:\Exercises\FPGA\Benchmark the Loop Period directory, open
[FPGA] Fan Control (prototype) [cRIO-9056].lvproj.
2. Configure the CompactRIO target:
a. In Project Explorer, right-click the cRIO RT target and select Properties.
ts
b. In the General category, set the IP Address to the IP address of your cRIO.
c. Click OK.
en
3. Add the Get Loop Period (tick) subVI to the project:
a. Right-click the cRIO-9056»Chassis»FPGA Target»Support VIs virtual folder and select
m
Add»File.
b. Navigate to C:\Exercises\FPGA\Benchmark the Loop Period\Support VIs\
tru
Get Loop Period (tick).vi.
c. Click Add File.
4. Explore the Get Loop Period (tick) subVI:
ns
a. Double-click Get Loop Period (tick).vi in Project Explorer to open the subVI. Go to the block
diagram.
b. Explore the Tick Count function. Double-click the Tick Count function. Notice that the counter
lI
units are set to Ticks. Based on the Size of the Internal Counter, what is the maximum number
of ticks that this function can internally count before it rolls over back to 0?
na ________ ticks
If the code you are benchmarking takes longer than the maximum value the Tick Count
io
function can handle, the elapsed time will be much lower than expected due to rollover. Based
on the maximum number of ticks, what is the maximum amount of time that can elapse
between calls to the Tick Count function before rollover occurs?
at
________ seconds
N
c. Notice the Feedback Node. Like a shift register, you can use a Feedback Node to store data
from previous block diagram executions or loop iterations. When this subVI is placed inside a
loop, it will use the Feedback Node to calculate the difference between the tick counts of the
3
Execution. Notice that Reentrancy is set to Preallocated clone reentrant execution. This means
that multiple instances of this subVI (e.g., in two different loops) execute simultaneously and
maintain their own state. FPGA subVIs are reentrant by default.
2
ht
ig
yr
op
C
2-38 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
5. Modify the block diagram, as shown in Figure 2-8, to add benchmarking code to the acquisition
loop.
ts
en
m
tru
ns
lI
na
io
at
N
1
3
2 02
ht
1 Get Loop Period (tick) VI—From Project Explorer, drag the FPGA Target»Support VIs»Get Loop
ig
Period (tick).vi to the block diagram. Right-click the output and select Create»Indicator.
Rename the indicator to Acquisition Loop Period (tick).
yr
6. On the front panel, move the new Acquisition Loop Period (tick) indicator to the Monitoring
Values»General section.
op
Test
1. Execute the FPGA Main VI in simulation mode:
a. Right-click the FPGA Target and select Select Execution Mode»Simulation (Simulated I/O).
b. Run the VI. Verify that the VI executes as expected.
2. Compile the FPGA Main VI:
ts
a. Right-click the FPGA Target and select Select Execution Mode»FPGA Target.
en
b. Click the Run button to start the compilation.
c. While the FPGA Main VI is compiling, calculate and write down your prediction of what the
loop period should be below.
m
Loop Period = ___________________ ticks
tru
Note The Loop Period of this loop is determined by the acquisition rate (kilosamples per
second) set by the Data Rate property. By default, the FPGA uses a 40 MHz clock, which
has means there are 40,000,000 ticks per second.
ns
d. When FPGA Main finishes compiling, run the VI. Compare your predicted loop period to the
actual result.
lI
Quiz
na
1. Will you need to benchmark any loops in an FPGA VI in your own application back at your job?
2. If so, what unit of time is most appropriate for the loop period?
io
Circle all that apply.
at
• Milliseconds
• Microseconds
N
• Nanoseconds
Your answer determines whether the Counter units of the Tick Count function should be mSec,
uSec, or Ticks.
3
Your answer determines whether the Size of internal counter of the Tick Count function should be
8 Bit, 16 Bit, or 32 Bit.
4. If you need to benchmark the period of a loop in your own application back at your job, you can
2
reuse the Get Loop Period (ticks) subVI. and modify the configuration of the Tick Count function
if necessary.
ht
ig
yr
op
C
2-40 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
Quiz—Answers
1. Based on the Size of the Internal Counter, what is the maximum number of ticks that this function
can internally count before it rolls over back to 0?
The Size of the Internal Counter is 32-bit.
Therefore, the maximum number of ticks before rollover is:
ts
2^Size of Internal Counter = 2^32 = 4,294,967,296 ticks.
2. If the code you are benchmarking takes longer than the maximum value Tick Count can handle,
en
the elapsed time will be much lower than expected due to the rollover. Based on the maximum
number of ticks, what is the maximum amount of time that can elapse between calls to the Tick
Count function before rollover occurs?
m
By default, the FPGA uses a 40 MHz clock, which has 40,000,000 ticks per second. Therefore,
each tick lasts 25 nanoseconds. Therefore, the maximum amount of time that can elapse between
tru
calls to the Tick Count function before the rollover occurs is:
(Maximum number of ticks before rollover - 1) * Time per tick =
(4,294,967,296 ticks - 1) * 25 nanoseconds = 107 seconds.
ns
3. While the FPGA Main VI is compiling, calculate and write down your prediction of what the loop
period should be below.
lI
This loop is timed by the Data Rate property node, which is set to 10.240 kS/s.
Loop Period = 1 / 10,2000 = 0.00009765625 seconds = 97.65625 μs Loop Period (ticks) =
Loop Period (seconds)/number of seconds per tick =
na
0.00009765625 seconds/0.000000025 seconds = 3,906 to 3,907 ticks.
ts
2. Wait Express VI b. Use to benchmark execution speeds.
en
3. Tick Count Express VI c. Use to control loop execution rate.
m
2. What is a potential drawback of using an 8-bit counter instead of a 32-bit counter?
e. Less FPGA resources used.
tru
f. 32-bit clocks are slower.
g. Maximum time the timer can track is not large enough for the application.
ns
3. Is the statement true or false?
lI
If you place a Loop Timer Express VI inside a While Loop, the Loop Timer Express VI will wait
during every iteration of the While Loop.
a. True
b. False na
io
at
a. True
a. False
3
02
5. Which of the following do you need to synchronize an acquisition of analog input channels from
multiple delta-sigma C Series modules?
Select all that apply.
2
ts
2. Wait Express VI a. Use to create delays between events.
en
3. Tick Count Express VI b. Use to benchmark execution speeds.
m
2. What is a potential drawback of using an 8-bit counter instead of a 32-bit counter?
a. Less FPGA resources used.
tru
b. 32-bit clocks are slower.
c. Maximum time the timer can track is not large enough for the application.
ns
3. Is the statement true or false?
lI
If you place a Loop Timer Express VI inside a While Loop, the Loop Timer Express VI will wait
during every iteration of the While Loop.
a. True
b. False na
io
at
a. True
b. False
3
02
5. Which of the following do you need to synchronize an acquisition of analog input channels from
multiple delta-sigma C Series modules?
Select all that apply.
2
2-44 | ni.com
ts
3
en
Signal
m
Processing in
tru
LabVIEW FPGA
ns
lI
na
io
Explore data types, methods and built-in or external
at
Topics
A. Using Fixed-Point Data Type
3
Exercises
2
ts
• Represent rational numbers within specified range.
• Sizes between 1-64 bits.
en
• Can be configured as signed or unsigned.
The fixed-point data type provides some of the flexibility of the floating-point data type but also
m
maintains the size and speed advantages of integer arithmetic. By default, each operation on the
fixed-point data type generates a fixed-point result that is large enough to hold all possible output
values specified by the input types.
tru
Note FPGA Signal Generation VIs and some functions do not support the fixed-point data
type.
ns
Caution If you wire a fixed-point number to an integer, you might lose fractional bits.
lI
Using Fixed-Point Data Types
The range of values and resolution depends on three factors:
•
•
Sign Encoding
Word Length na
io
• Integer Word Length
at
Fixed-point is a collection of data types with different ranges of values. The range is defined by the
minimum value, maximum value, and delta.
N
Delta—Smallest change in value that can be represented with the given fixed-point configuration.
3
Fixed-Point Terminology
02
Sign Encoding The option that determines whether the fixed-point data is signed (±) or
2
unsigned (+).
ht
Word Length The total number of bits used for the fixed-point data.
ig
yr
Integer Word Length The number of bits used in the integer portion of the fixed-point data.
op
1 7
ts
en
5 6
m
3
tru
4
1 Overflow Status—Shown when the Include Overflow Status checkbox is enabled in the Numeric
Properties dialog box. To determine whether overflow occurs, you can configure a fixed-point
number to include an overflow status. When you include an overflow status in a fixed-point
ns
number, LabVIEW allocates additional storage space to track whether the overflow occurred with
that fixed-point number. After you configure a fixed-point number to include an overflow status,
you can display an overflow status LED on fixed-point controls, constants, and indicators. This
lI
LED lights up when the overflow status of the fixed-point number is TRUE. You can also use the
Fixed-Point Overflow? function to determine the overflow status of a fixed-point number. Use the
Fixed-Point functions to manipulate the overflow status of a fixed-point number.
2
3 na
Sign Encoding—The setting that specifies whether the fixed-point value is signed or unsigned.
If you select signed, the sign bit is always the first bit in the bit string that represents the data.
Word Length—The total number of bits in the bit string that LabVIEW uses to represent all
possible values of the fixed-point data. LabVIEW accepts a maximum word length of 64 bits.
io
Certain targets might limit data to smaller word lengths. If you open a VI on a target and the VI
contains fixed-point data with larger word lengths than the target can accept, the VI contains
at
broken wires. Refer to the documentation for a target to determine the maximum word length the
target accepts.
4 Integer Word Length—The number of integer bits in the bit string that LabVIEW uses to represent
N
all possible values of the fixed-point data, or, given an initial position to the left or right of the
most significant bit, the number of bits to shift the binary point to reach the most significant bit.
The integer word length can be larger than the word length and can be positive or negative.
5 Minimum—Minimum value that can be represented.
3
3-4 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
0.00XXXXXX, where the X’s represent data stored in the 6-bit word.
If the integer word length is greater than the word length, then the fixed-point data will move to the
en
left of the decimal point, with zeros padding the distance between the integer word and the decimal
point. For example, <±, 6, 8> would result in XXXXXX00.0, where the X’s represent the data
stored in the 6-bit word.
m
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
Fixed-Point Configuration
ts
en
m
tru
ns
lI
na
Use the Fixed-Point Configuration options on the Properties dialog box to increase or decrease the
io
resources a function uses. Right-click a Numeric constant, control, indicator, or function that accepts
fixed-point data and select Properties from the shortcut menu to display the Properties dialog box.
at
When you set the range on inputs, the FPGA Module propagates the range throughout the block
diagram. The propagation reduces resources when possible. The FPGA Module does not propagate
N
through subVIs, so coercion dots appear on the inputs of subVIs if the range is different than the range
being propagated.
3
The Data Type page of the Numeric Properties dialog box will be slightly different for indicators.
Specifically, it includes an Adapt to Source checkbox. This will modify the data type of the indicator
02
When performing fixed-point arithmetic, the output fixed-point configuration must adapt to the input
fixed-point configuration to avoid data loss.
ht
ig
yr
op
C
3-6 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
Fixed-Point Arithmetic
Fixed-point data is limited to 64 bits, so if the resulting output requires more than 64 bits, precision
may be lost.
LabVIEW type propagation strictly deals with the ranges of the wires and not so much the fixed-point
ts
representation necessary to hold those ranges. In other words, LabVIEW calculates and propagates
the ranges of values each wire will have to pass along. LabVIEW then calculates the representation
that is as small as possible but will hold that value without losing any data.
en
Arithmetic Operations
m
• Addition
• Subtraction
tru
• Multiplication
• Division
ns
Addition—The integer word length of the output will be one bit longer, resulting in the word length
increasing by one as well. The decimal length does not change.
lI
• <±, A, B> + <±, A, B> = <±, A+1, B+1>
na
io
at
In the presented example, the integer word length increases by one to accommodate the maximum
value. Since the integer word length increases, the word length must increase as well so that no
N
accuracy is lost.
<±,10,7> + <±,10,6> = ?
3
To accommodate both configurations without losing any accuracy, there must be 7 integer bits and 4
02
If one input is signed and the other is unsigned, then the word length and integer word length will
increase by one more bit.
ht
ig
yr
op
C
Subtraction—The output representation follows the same guidelines as in the case of addition. The
output will be signed, regardless of whether the inputs were signed or unsigned.
• <+, A, B> - <+, A, B> = <±, A+1, B+1>
ts
en
Multiplication—For the integer value of the output to accommodate the largest possible value of each
m
operand, the integer word length must increase to match the sum of the integer word lengths of the
inputs. For the resolution of the output to accommodate the highest resolution of both inputs, the
tru
decimal word length must also increase. Thus, the word length of the output must increase to match
the sum of the word lengths of the inputs.
• <+, A, B> * <+, C, D> = <+, A+C, B+D>
ns
lI
na
Division—Inputs can have different ranges of values. Signed and unsigned division result in different
io
ranges of values for the out.
• Signed: <±, A, B> / <±, C, D> = <±, A+C+1, B+C-D+1>
at
3-8 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
m
tru
ns
lI
na
io
Adapt to Source Set whether the configuration settings for the output value adapt to the input
at
values you wire to the function. For fixed-point data, LabVIEW automatically
sets the Fixed-Point Configuration settings to avoid data loss if possible.
N
Adapt to Source is enabled by default to avoid data loss from the function. Typically, you can let all
functions keep Adapt to source enabled, test the code, and then compile it on the FPGA. In many
2
situations, you can avoid overflow by placing a checkmark in the Adapt to source checkbox in the
configuration dialog box of the function. If you place a checkmark in this checkbox, LabVIEW attempts
ht
to adjust the width and range of the output data type such that neither overflow nor rounding occurs.
However, this adjustment is not possible in all situations. For example, if a function involves division,
ig
If the compile fails due to a lack of FPGA resources (space), then you can try to modify your fixed-point
yr
code to use fewer FPGA resources. For example, if you know the expected minimum and maximum
input values for a function will be smaller than the min/max range of the input wire fixed-point
op
configuration (e.g., you know that the AI0 input wire for a Multiply function for your application will
always be between -1 and +1, but the AI0 input wire has a range of -8 to 8), you could potentially
disable "Adapt to source" and decrease the word length (and integer word length) of the output data
C
type to values that reflect your expected Range and Desired Delta of the function output. Then you
should set the appropriate Overflow Mode and Rounding Mode.
Rounding Occurs when the precision of the input value or the result of an operation is
greater than the precision of the output type.
ts
Rounding Mode Options
Truncate—Removes fractional bits and therefore does not require any additional hardware
en
•
resources. However, this mode produces the largest mean error for most data streams. This mode
is the default for integer operations.
Round Half-Up—Rounds the value to the nearest value that the output type can represent. If the
m
•
value lies directly between two such values, LabVIEW rounds to the higher of the two by adding
half the least significant bit to the value and then truncating. This method has a higher impact on
tru
performance than the Truncate method but produces a more accurate result.
• Round Half-Even—Rounds the value to the nearest value that the output type can represent. If the
value lies exactly between two such values, LabVIEW checks the value of the bit that becomes
ns
the least significant bit after rounding. If the bit is zero, then LabVIEW rounds to the lower of the
two valid values; otherwise, it rounds to the higher value. This mode has the highest impact on
performance, but it is more accurate than the Truncate method, and it eliminates the bias toward
lI
the higher value that can occur when you perform multiple Round Half-Up operations. This is the
default option.
• Wrap—Discard significant bits of the output value until it falls within the specified range.
• Saturate—Coerce the output value to the maximum or the minimum, depending on which value
3
was exceeded. This option has a higher impact on performance than the Wrap method. This is the
default option.
02
Configurations Considerations
2
As a rule of thumb, rounding half-even and saturation overflow modes typically render the most
desirable results. Rounding usually gives an overall more accurate fixed-point representation of the
input number. Saturation prevents outputs from jumping between the top and bottom of the FXP range
ht
when input numbers are outside FXP bounds. The only drawback is that rounding half-even and
saturation modes requires slightly more field-programmable gate array (FPGA) logic compared to the
ig
3-10 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
precision on each of the wires. Logging the min/max of each floating-point wire can help with
these decisions. Run your fixed-point code using the tests you devised for the floating-point code
en
to ensure it is good enough. It will not match perfectly. You should also include tests for boundary
conditions, which can be a common source of errors. A boundary condition is a value that is above
or below a set maximum. For example, if a requirement calls for a maximum value, then you should
m
test [maximum value +1], [maximum value –1], and maximum value in your fixed-point code.
3. Finally, compile and test your fixed-point algorithm on the FPGA.
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
ts
Requirements
To complete this exercise, it is necessary to have access to the following hardware and software.
en
Software:
• LabVIEW 2023 Q3 (32-bit)
m
• NI-DAQmx 2023 Q3 (32-bit)
LabVIEW Real-Time Module 2023 Q1 (32-bit)
tru
•
ns
Hardware:
• An NI CompactRIO from either the 904x or 905x product lines
lI
• USB Type C or RJ45 Ethernet connection
• NI-9211 Thermocouple Input C Series Module
•
•
NI-9474 Digital I/O C Series Module
Windows 10 PC na
io
Scenario
at
You must read values from a CompactRIO analog input channel that returns fixed-point data. You must
implement fixed-point math on this data. You also know that the analog input channel is expected to
return values between -2 and 2. In this exercise, the fixed-point math algorithm scales the data by a
N
constant value of 5. However, other fixed-point algorithms can involve many more operations and
grow the number of bits used by the fixed-point data type to be larger.
3
2 02
ht
ig
yr
op
C
3-12 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
Implementation
Fixed-Point Configuration
1. From the C:\Exercises\FPGA\Using Fixed-Point Data Type directory, open
Fixed-Point.lvproj.
ts
2. Configure the CompactRIO Network Settings:
a. Right-click the CompactRIO target in Project Explorer and select Properties.
en
b. In the General category, set the IP Address to the IP Address of your CompactRIO target.
3. In the Project Explorer window, cRIO-9056»Chassis»FPGA Target is set to execute FPGA VIs on
m
the development computer with simulated I/O.
4. In Project Explorer, double-click cRIO-9056»Chassis»FPGA Target and open
tru
Fixed-Point Configuration.vi.
5. Examine the block diagram:
a. Press <Ctrl-H> to show the Context Help window. Hover your mouse pointer over the
ns
fixed-point wires to see their fixed-point configuration.
b. Notice the In Range and Coerce function. This function coerces the FPGA I/O Node output to
simulate an analog input channel that returns values between -2 and 2.
lI
6. Run the VI and notice that the Simulated AI0 indicator will always return a value between -2 and 2.
na
io
at
N
3
2 02
ht
ig
yr
op
C
7. Modify the block diagram, as shown in Figure 3-1, to scale the simulated AI0 value by 5.
Figure 3-1. Fixed-Point Configuration VI Block Diagram
ts
en
m
1
tru
2
ns
3
lI
1 Multiply function—Wire the x input first. Right-click the y input and select Create»Constant.
2
na
Fixed-point constant—Configure the fixed-point constant to represent a value of 5. Right-click the
constant and select Properties. On the Data Type tab, notice that the Word Length is 24 bits.
However, you do not need 24 bits to represent a constant value of 5, so you should modify the
fixed-point configuration to use the minimum number of bits required to represent a value of 5.
io
3 Fixed-Point Constant Configuration section—Set the following values.
• Encoding: Unsigned
at
the output of the Multiply function and select Create»Indicator. Rename the indicator to Result.
3
Result indicator, and observe their fixed-point configurations in the Context Help window.
b. Notice that the Multiply function automatically increased the size of its output fixed-point
configuration based on the fixed-point configuration of its inputs. The x input has a fixed-point
2
9. Run the VI several times and verify that the Result is equal to Simulated AI0 multiplied by 5.
10. At this point, you would normally be ready to compile your fixed-point algorithm on the FPGA. In
ig
the previous steps, you allowed the Multiply function to automatically grow the size of the
fixed-point configuration, which helps avoid data loss. This is the safest method to use when
yr
creating a fixed-point algorithm. However, letting functions automatically grow the size of the
fixed-point configuration uses up more FPGA resources and might cause a compilation to fail.
op
If your compilation fails due to a lack of FPGA resources, then try to modify the fixed-point
configurations in your algorithm to use less space.
C
3-14 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
•
en
• Constant value of y input: 5
Because the y input is a constant of 5, we can predict the expected range of the Multiply function
output:
m
• Expected minimum of output (-2 × 5): -10
• Expected minimum of output (-2 × 5): -10
tru
2. Configure the Multiply function to use the minimum number of bits to represent the expected
output:
a. Right-click the Multiply function and select Properties.
ns
b. On the Output Configuration tab, disable the Adapt to source checkbox.
c. Decrease the Integer Word Length to the smallest number of bits that can still represent the
lI
expected minimum and maximum output values of -10 and 10.
d. Decrease the Word Length to the smallest number of bits that can still represent the original
delta of 9.536743E-7.
na
e. Verify that the configuration is set to the following values:
• Sign encoding: Signed
io
• Word length: 25 bits
Integer word length: 5 bits
at
•
g. Notice that the Multiply function has a blue coercion dot on its output terminal. The blue
02
coercion dot indicates that you have set the fixed-point configuration of the output differently
from the default.
3. Modify the Result indicator to update its fixed-point configuration:
2
4. Run the VI several times and verify that the Result is still equal to Simulated AI0 multiplied by 5.
The result should still be accurate even though we have decreased the number of bits used by the
yr
ts
condition.
c. Go to the front panel.
en
d. Right-click the Result indicator and select Visible Items»Overflow Status LED. You should now
see an LED on the indicator that is lit whenever an overflow condition occurs.
e. Run the VI until you see the Overflow Status LED illuminate.
m
Overflow occurs when the result of the Multiply function is outside the range of values of its
output configuration. In this case, you have configured the Multiply output to have a minimum
tru
and maximum of -16 and 16 and to saturate at those values if overflow occurs.
7. Save and close the VI and project when finished.
ns
End of Exercise 3-1
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
3-16 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
LabVIEW FPGA supports the single-precision floating-point (SGL) data type in FPGA VIs.
en
m
Benefits
tru
• Easier to rapidly prototype.
Caveats
ns
• Requires significantly higher FPGA resource usage than fixed-point data type for some operations.
• Most functions cannot perform floating-point operations inside SCTL.
lI
The single-precision floating-point data type is supported in LabVIEW FPGA 2012 or later.
Double-precision floating point is not supported in LabVIEW FPGA, so DBL calculations can only be
done on the host computer.
na
The single-precision floating-point (SGL) data type provides more accuracy than a 24-bit fixed-point
io
data type but reduces overall performance due to the increased latency of functions and the large
number of FPGA resources that it uses for some functions. There is no extra overhead (for SGL when
compared to fixed-point) in functions that just move data, such as Memory Read/Write, Index Array,
at
and Feedback nodes. However, all the math functions (add, multiply, etc.) will introduce additional
overhead when using the SGL data type, some more than others.
N
For example, an Add is on the order of 10x more resource usage, but a Multiple might be closer in
resource usage. Evaluate your usage of numeric data types to determine which data type is the best
3
Most functions cannot perform single-precision floating-point operations inside a Single-Cycle Timed
Loop because they require more than one clock cycle to execute, but they do not have handshaking
signals.
2
• Free the RT processor to perform other operations and use single-precision floating-point
conversions with I/O.
ig
• Operate on data from multiple inputs or outputs that return different fixed-point data types.
You need to represent very large and very small numbers in the same data path, such as with
yr
•
accumulators.
• You need to rapidly prototype.
op
The most common reason to use SGL floating-point is to rapidly prototype and implement your
algorithms and logic. If your code successfully compiles and meets requirements, then you do not need
C
to use fixed-point.
Performing I/O conversion to the FPGA frees processing on the host computer, especially in real-time
systems. If you have FPGA resources available, perform fixed-point I/O to single-precision
floating-point data conversions on the FPGA to free the host processor to perform other operations,
such as meeting real-time requirements.
Convert heterogeneous data paths into the SGL data type in order to handle them with common code.
ts
This conversion is useful in situations where you want to operate on data from multiple inputs that
return different fixed-point data types.
en
Use single-precision floating-point to get functional hardware designs quickly. Convert to fixed-point
as necessary to optimize FPGA performance or resource usage.
m
Performing I/O conversion to the FPGA frees processing on the host computer, especially in real-time
systems. If you have FPGA resources available, perform fixed-point I/O to single-precision
tru
floating-point data conversions on the FPGA to free the host processor to perform other operations,
such as meeting real-time requirements.
ns
For example, you might receive a voltage value as a fixed-point data type, convert the voltage value
into a useful engineering unit value, convert the fixed-point data type to a single-precision data type,
and send it to the host. The host processor now does not need to use any CPU resources for this
lI
algorithm and conversion.
na
io
at
Operate heterogeneous data paths into the SGL data type in order to handle them with common code.
N
This conversion is useful in situations where you want to operate on data from multiple inputs that
return different fixed-point data types.
3
The figure of the FPGA VI shows an NI cRIO-9104 as it acquires data from two modules, converts it
to the SGL data type, and writes the data to a DMA FIFO.
2 02
ht
ig
yr
op
C
3-18 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
Represent very large and very small numbers in the same data path, such as with accumulators.
ts
en
To rapidly prototype, you need to:
• Use floating-point to get functional hardware designs quickly.
m
• Convert to fixed-point later as necessary to optimize FPGA performance or resource usage.
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
ts
Requirements
en
To complete this exercise, it is necessary to have access to the following hardware and software.
Software:
m
• LabVIEW 2023 Q3 (32-bit)
• NI-DAQmx 2023 Q3 (32-bit)
tru
• LabVIEW Real-Time Module 2023 Q1 (32-bit)
• LabVIEW FPGA Module 2023 Q1 (32-bit)
ns
• NI CompactRIO 2023 Q3 (32-bit)
Hardware:
lI
• An NI CompactRIO from either the 904x or 905x product lines
• USB Type C or RJ45 Ethernet connection
•
Scenario
at
This exercise aims to perform inline signal processing to your acquired signals to be able to represent
your acquisition on the screen using the engineering units expected for each type of measurement.
N
You will create the VI and logic to process the signals specified in the communication diagram.
3
2 02
ht
ig
yr
op
C
3-20 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
Tach –> RPM
Voltage –> g
Signal Processing
en
m
tru
•
ns
lI
Figure 3-2. Fan Control—Communication Diagram
na
io
at
N
3
02 2
ht
rig y
op
C
© National Instruments Corporation | 3-21
Lesson 3 Signal Processing in LabVIEW FPGA
Implementation
1. From the C:\Exercises\FPGA\Process Tachometer and Acceleration directory, open
Fan Control (prototype) [cRIO-9056].lvproj.
2. Configure the CompactRIO target:
a. In Project Explorer, right-click the cRIO RT target and select Properties.
ts
b. In the General category, set the IP Address to the IP address of your cRIO.
c. Click OK.
en
3. Add an existing Tachometer library to the project:
a. In Project Explorer, navigate to cRIO-9056»Chassis»FPGA Target»Support VIs.
m
b. Right-click Support VIs, select New»Virtual Folder, and name it Tachometer.
c. Right-click the Tachometer virtual folder and select Add»File.
tru
d. Navigate to
C:\Exercises\FPGA\Tachometer Library\Tachometer\Tachometer(SGL).lvlib.
e. Click Add File.
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
3-22 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
m
tru
1
ns
lI
na 2
io
at
3
N
3
02
1 Convert the raw tachometer voltage signal into fan speed (RPM):
2
• From Project Explorer, drag the Get Tach RPM (FPGA).vi from the FPGA Target»Support VIs»
Tachometer»Tachometer (SGL).lvlib directory to the block diagram.
2 Scale the accelerometer voltage signal into units of acceleration (g):
ht
• The Sound and Vibration Signal Simulator accelerometers have a sensitivity of 175 mV/g and
the FPGA I/O Node returns the signal in units of V. Use the To Single Precision Float function
ig
to convert the fixed-point data type to the easier-to-use single-precision floating-point data
type. Use the Divide function to scale from units of V to g.
yr
6. Set the default value of the Max Acceleration Threshold control to 0.75:
a. On the front panel, set the Max Acceleration Threshold (g) control to 0.75.
b. Right-click the control and select Data Operations»Make Current Value Default.
7. Arrange the front panel, as shown in Figure 3-4.
ts
Figure 3-4. FPGA Main VI Front Panel Diagram
en
m
tru
ns
lI
na
io
at
N
3
02
3-24 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
by looking at the indicator values, execution highlighting, single-stepping, probes, and other
tools. In this mode, the FPGA I/O Nodes will output random data.
en
End of Exercise 3-2
m
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
ts
Configurable, prebuilt, optimized, tested, and documented functions to perform common tasks:
• Mathematics
en
• Measurements
• Control, PID
• Filtering
m
• Signal Processing
High Throughput Math
tru
•
Use the FPGA Math & Analysis VIs and Functions to perform math, analysis, and control operations
in FPGA VIs. This palette provides functions not available elsewhere on the FPGA palette. Using these
ns
functions instead of writing the algorithm yourself will save development and support time. This
palette is specific to FPGA targets. The configuration and behavior of these functions will differ from
their Windows counterparts.
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
3-26 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
m
tru
ns
lI
na
A Feedback Node is analogous to a z^(-1) block in feedback control theory and digital signal
io
processing.
at
Feedback Nodes may be visually depicted as Z-Transform primitives on the FPGA Block Diagram.
Some LabVIEW functions (pale yellow background) offer configuration options or optional nodes.
N
Context menu options for this primitive include Direction, Appearance, Show Enable Terminal, and the
ability to move the node in or out layers of loops. The Z Transform Delay primitive is the only primitive
in the FPGA analysis palette.
3
The programmer should also be aware of the Discrete Delay node available in the
02
FPGA Math & Analysis VIs»High Throughput»Basic Elements palette. Nodes in the high throughput
palette are covered in a later section and in more depth in a separate course.
2
ht
ig
yr
op
C
Non-Configurable Express VI
Some Analysis VIs are non-configurable Express VIs, which can be shown as Express VIs on the block
diagram. As the name implies, they do not contain configuration dialog boxes, so nothing happens if
you double-click the node. In most cases, the additional functionality provided by these nodes adapts
the output data type to facilitate the input data type(s). As with all LabVIEW Express VIs, including
ts
the fully configurable Express VIs, you can right-click the node and select Convert to subVI to view
the underlying implementation. However, after you convert the express VI to LabVIEW code, the
en
output data type no longer adapts to the input data types.
m
tru
ns
lI
Configurable Express VI
na
io
at
N
3
2 02
ht
ig
yr
op
C
3-28 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
m
tru
ns
lI
na
io
at
N
3
02
The VIs in the FPGA Math & Analysis Palette with the blue background (analysis) or purple background
(High-Throughput Math) are fully configurable Express VIs, but they are specific to FPGA targets and
not available on Windows or RT platforms. Express VIs consume input data and generate output data,
2
and they also change their run-time behavior based on parameters configured at edit time. The
parameters are configured by double-clicking the node to launch its configuration dialog box. The
configuration dialog depends on the VI selected. In general, most configurable Express VIs in the
ht
analysis palette allow the programmer to configure the node execution mode. The execution mode
determines if the generated code is optimized for use within a Single Cycle Timed Loop or not. There
ig
are special considerations for operating these nodes inside a Single Cycle Timed Loop.
yr
There are additional configuration options in most of the high throughput math nodes. For example,
you can configure the encodings, word lengths, and integer word lengths of the input and output
terminals, whether to add internal registers for function inputs and/or outputs, and the minimum
op
number of cycles between two successive values of valid input data. Throughput and latency may
change with data types. You cannot generate graphical code from high throughput math nodes.
C
ts
Use the Xilinx IP functions to implement different Xilinx IP in an FPGA VI. LabVIEW implements these
functions using the IP Integration Node. The names and descriptions for these functions come from
en
Xilinx IP data sheets, available on the Xilinx website at www.xilinx.com.
The Xilinx IP palette varies by target and displays only Xilinx IP functions that your FPGA device
m
supports. Not all FPGA device families support all Xilinx IP. Refer to the Xilinx IP data sheets for
information about FPGA device family support.
tru
ns
lI
Some of the Xilinx IP requires licensing from Xilinx. You can find the licensing information in the
na
Context Help window for a specific Xilinx IP. To import a license, place the .lic file in one of the
following default directories, depending on your specific FPGA target:
• Xilinx ISE—C:\NIFPGA\programs\XilinxY_Z\ISE\coregen\core_licenses, where XilinxY_Z is
io
the current version of the Xilinx compilation tool for ISE for your FPGA target.
• Xilinx Vivado—C:\NIFPGA\programs\VivadoA_B\data\ip\core_licenses, where VivadoA_B is
at
the current version of the Xilinx compilation tool for Vivado for your FPGA target.
To compile VIs containing licensed IP, ensure that the license exists on the computer.
N
Note You should have the Xilinx compilation tools installed on the local computer to
3
configure these functions. Refer to the Xilinx Compilation Tools Readme for instructions on
installing Xilinx compilation tools for LabVIEW. If you move Xilinx IP generated on a given
02
FPGA target to another FPGA target, you may need to regenerate the Xilinx IP.
2
ht
ig
yr
op
C
3-30 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
m
tru
ns
lI
na
io
at
N
3
2 02
ht
Note You need a separate Xilinx license to use some of the Xilinx CORE Generator IP.
ig
yr
op
C
ts
• Must ensure that IP meets the requirements of IP Integration Node.
en
m
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
3-32 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
4. Use the CLIP items in an FPGA VI.
en
m
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
Additional Resources
Topic Website
ts
Using the Single-Precision Floating-Point Data Type
en
LabVIEW Help
Functions that Support the Single-Precision Floating-Point Data Type in
FPGA VIs (FPGA Module)
m
Using the IP Integration Node
tru
ni.com
Importing External IP Into LabVIEW FPGA
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
3-34 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
2. Which of the following are parameters used to define the range of values that are represented by
a fixed-point number?
m
Select all that apply.
a. Rounding Mode
tru
b. Sign Encoding
c. Word Length
d. Integer Word Length
ns
lI
3. Which of the following third-party FPGA IPs can you reuse in your FPGA VIs?
Select all that apply.
a. Xilinx CORE Generator IP
na
b. Third-Party IP synthesis files that meet the requirements of IP Integration Node
c. CLIP
io
at
4. Which of the following corresponds to the element used to access items from a CLIP node?
a. Verilog Node
N
b. IP Integration Node
c. CORE Generator
3
d. CLIP IO Node
2 02
ht
ig
yr
op
C
ts
en
2. Which of the following are parameters used to define the range of values that are represented by
a fixed-point number?
m
Select all that apply.
a. Rounding Mode
tru
b. Sign Encoding
c. Word Length
d. Integer Word Length
ns
lI
3. Which of the following third-party FPGA IPs can you reuse in your FPGA VIs?
Select all that apply.
a. Xilinx CORE Generator IP
na
b. Third-Party IP synthesis files that meet the requirements of IP Integration Node
c. CLIP
io
at
4. Which of the following corresponds to the element used to access items from a CLIP node?
a. Verilog Node
N
b. IP Integration Node
c. CORE Generator
3
d. CLIP IO Node
2 02
ht
ig
yr
op
C
3-36 | ni.com
ts
4
en
Inter-Process
m
Communication
tru
in LabVIEW
ns
lI
FPGA io
na
at
N
Topics
02
Exercises
Exercise 4-1 Transfer Latest Values to PID Loop
ig
yr
op
C
C
op
yr
ig
ht
202
3
N
at
io
na
lI
ns
tru
m
en
ts
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
Common Architecture
ts
In a typical data acquisition system, you may see architectures similar to what is shown here as a
common architecture example. Essentially, the main parts of an embedded data acquisition system
en
will include the acquisition loop, the data processing loop, and a communication loop to share data
with the RT and host.
m
tru
ns
lI
na
io
Parallel Loops with Different Sampling Rates
at
N
3
2 02
ht
The presented loops run in parallel because there are no shared resources between the two loops.
ig
Parallel operations are a very powerful concept in current computer architecture. In a standard
processor-based configuration, parallel operations are not truly parallel. In processor-based
yr
architectures, programs running on the processor are sliced into many fragments and interleaved with
code fragments from other processes. The operating system then decides which processes are most
op
ts
en
m
tru
ns
Another advantage of running code in parallel is that some sections of code can run faster than others.
One set of code in a loop can severely limit the speed of another piece of code. In this application, the
analog output runs 35 times slower than the digital input. This can become particularly critical if the
lI
code is arranged such that the digital line corresponds to an emergency stop switch and the
recognition of the response has to happen immediately.
na
38 ticks = Read Connector0/AO0 control (1 tick) + FPGA I/O node
(AO0 takes ~35 ticks) + While Loop overhead (2 ticks)
io
• Separate functions to allow DI to run independently of AO.
at
The code is divided into two parallel operations. The loop on the left-hand side runs at the same analog
ig
output-limited rate of about 1 MHz. However, the code of the right-hand side loop can run at a rate
of 10 MHz, or 10 times faster. Often, when code runs too slowly, you can separate the code into
parallel operations to prevent unrelated processes from interfering with each other.
yr
4 ticks = FPGA I/O node (DIO0takes 1 tick) + write to stop indicator (1 tick) +
While Loop overhead (2 ticks)
C
4-4 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
m
tru
ns
lI
na
io
at
N
3
However, you can use LabVIEW channel wires to pass data between parallel processes in LabVIEW
02
RT and FPGA.
2
ht
ig
yr
op
C
ts
To store and access latest data on the FPGA, use the following items:
• Local and Global Variables
en
• Memory Items
• Register Items
• Register Wires
m
Exploring Global and Local Variables
tru
Variables
• Block diagram elements that allow you to access or store data in the flip-flops of the FPGA.
ns
Store only the latest data you write to it.
• Do not need every value you acquire.
lI
• Do not need extra code to discard unused values.
Local Variables
at
To create a local variable, right-click a control or indicator on the block diagram and select
Create»Local Variable.
ht
If you use this approach, you may find yourself creating controls and indicators only for data sharing
ig
within the VI they are on. Create a coding convention to help you distinguish such controls and
indicators from those that are meant for passing data in and out of VIs.
yr
op
C
4-6 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
Transfer tag data between parallel loops running in the same FPGA VI.
ts
en
m
tru
You can use local variables to stop multiple parallel loops with a single front panel control.
Global Variables
ns
• Accessible across multiple FPGA VIs.
• To create a global variable, go to the Functions palette and select Structures»Global Variable.
lI
• If you created a control or indicator only to use a local variable, consider replacing it with a global
variable instead to decrease FPGA resource usage.
na
io
Replacing the local variable and corresponding control or indicator with a global variable will save
at
FPGA resources by eliminating the need for the FPGA resources that implement the control/indicator
on the front panel.
N
Memory Items
02
•
ig
yr
op
C
ts
Two options for creation:
• Target-Scoped
en
• VI-Defined
When using a memory item, data is overwritten on subsequent writes, so no additional code is needed
m
to remove the value before another write can occur.
tru
• Accessible by any VI running on the FPGA target.
• Use to store data that is accessed by multiple VIs.
ns
Creation Process
1. Right-click the FPGA Target.
lI
2. Select New»Memory.
The Memory Properties dialog box launches.
na
• io
at
N
3
2 02
ht
ig
yr
op
C
4-8 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
• Look-Up Table—Stores the memory item in look-up tables available on the FPGA.
en
• Block Memory (default value)—Stores the memory item using embedded blocks of memory on
the FPGA.
• DRAM—Memory external to the FPGAs, available only on some targets.
m
tru
ns
lI
na
io
at
N
3
2 02
• You do not have enough logic resources available to use look-up tables.
• Accessing memory in a single-cycle timed loop and need to read data from memory in the same
cycle as the one in which you give the address.
op
• The amount of memory needed is smaller than the minimum amount of embedded block memory
on the FPGA.
You do not have enough free embedded block memory on the FPGA.
C
Check the hardware documentation for information regarding the amount of block memory available
on your FPGA.
ts
•
• End Address—The high end of the memory item interval you want to populate.
en
• Value—The constant LabVIEW enters the memory item if you select Constant from the Mode
drop-down menu.
• Slope—Slope of the line LabVIEW enters the memory item if you select Linear from the Mode
m
pull-down menu.
• Apply—Displays the initial values in the Graph Preview and Data Value tabs.
tru
• Graph Preview—Displays the current contents of the memory item in a waveform graph.
• Data Values—Displays the current contents of the memory item.
• Reset to Default Values—Resets the contents of the memory item to the default value for the data
ns
type contained in the memory item.
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
4-10 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
m
tru
ns
lI
na
io
Memory Write and Read
at
ts
en
m
Exploring Register Items
tru
• Only the most recent data is stored.
• Target-scoped and VI-defined options for creation.
ns
Target-Scoped
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
4-12 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
VI-Defined
ts
en
m
tru
ns
lI
na
Use register items to store data when you need to access that data from multiple clock domains or
from different parts of your design and you need to write reusable code.
io
In the FPGA Register Properties dialog box, select Initial Value from the Category list to display this
page. Use this page to initialize a register item. You can enter an initial value or call an initialization VI
at
Note You should use an initialization VI if you have specified custom control as the data
type for the register item.
ts
VI Path—Specifies the path to the initialization VI.
en
•
• New VI from Template—Creates an instance of a template VI, saves the VI to the location you
specify in the Name the New Initialization VI dialog box, and opens the VI. You must close the
FPGA Register Properties dialog box to edit the VI.
m
• Open VI—Opens the VI you specify in the VI Path field. You must close the FPGA Register
Properties dialog box to edit the VI.
tru
• Run VI—Runs the VI you specify in the VI Path field. LabVIEW then imports the output value into
the register item and displays the corresponding value in the Initial Value field.
Initial Value—Indicates the initial value of the register item. If you do not select an initialization VI,
ns
•
use this control to specify an initial value.
lI
• Only share one element (a memory item can share a block of elements)
•
•
na
Register items store scalars; Memory items store arrays.
Register items access or store data in the registers of the FPGA.
Register items do not consume block memory, which is the most limited type of FPGA resource.
io
Use register items to store data when you need to access that data from multiple clock domains
at
(multiple SCTLs using different FPGA clocks, e.g., share data between an SCTL using a 60 MHz clock
and an SCTL using an 80 MHz clock) or from different parts of your design and you need to write
reusable code. Register items consume fewer FPGA logic resources than FIFOs, and they do not
N
consume block memory, which is the most limited type of FPGA resource.
Note Register items do not support type definitions. If your application requires you to use
3
resource conflicts. If you configure a VI-defined register item in a reentrant FPGA VI, LabVIEW
creates a separate copy of the register item for each instance of the VI.
ht
• Target-scoped register items: Use target-scoped register items if you want the register item to
be visible and configurable from the Project Explorer window. Target-scoped register items are
available within any FPGA VI under the same target in the Project Explorer window.
ig
yr
op
C
4-14 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
Requirements
en
To complete this exercise, it is necessary to have access to the following hardware and software.
Software:
m
• LabVIEW 2023 Q3 (32-bit)
• NI-DAQmx 2023 Q3 (32-bit)
tru
• LabVIEW Real-Time Module 2023 Q1 (32-bit)
• LabVIEW FPGA Module 2023 Q1 (32-bit)
ns
• NI CompactRIO 2023 Q3 (32-bit)
Hardware:
lI
• An NI CompactRIO from either the 904x or 905x product lines
• USB Type C or RJ45 Ethernet connection
•
•
na
NI-9211 Thermocouple Input C Series Module
NI-9474 Digital I/O C Series Module
Windows 10 PC
io
•
Scenario
at
This exercise aims to use the recently introduced methods to transfer data between the FPGA loops.
N
3
2 02
ht
ig
yr
op
C
Implementation
1. From the C:\Exercises\FPGA\Transfer Acquired Data to PID Loop directory, open
[FPGA] Fan Control (prototype) [cRIO-9056].lvproj.
2. Configure the CompactRIO target:
a. In Project Explorer, right-click the cRIO RT target and select Properties.
ts
b. In the General category, set the IP Address to the IP address of your cRIO.
en
c. Click OK.
3. Examine the communication diagram for the FPGA component of this project:
a. From Project Explorer, double-click
m
My Computer»Documentation»Fan Control - Communication Diagram.pdf.
b. View the FPGA component in the communication diagram.
tru
c. What data needs to be transferred between the loops?
__________________________________________________________
d. What type of data communication and implementation should be used for each of the following
ns
data? Write your choices in Table 4-1.
lI
Data to Transfer Transfer Type Implementation
(Tag/Message/Stream) (Register Memory, FIFO,
Fan Speed
na Local Variable, Global Variable)
io
Max Acceleration
at
Input Error
N
4-16 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
Complete the following steps to create VI-Defined Register Configuration items and edit those to have
the result shown in Figure 4-1.
5. Create a Fan Speed (RPM) Register item.
a. From Project Explorer, open FPGA Main.vi.
b. Place a VI-Defined Register Configuration on the block diagram in the first frame of the
ts
Sequence structure. Double-click it and select Configure.
c. In the General category, set Name to Fan Speed (RPM).
en
d. In the Data Type category, set Data Type to SGL.
e. In the Initial Value category, set Initial Value to 0.
m
6. Create an Input Error Register item.
Repeat the procedure of the previous step with the following edits:
tru
• Name: Input Error
• Data Type: Boolean
• Initial Value: 0
ns
7. Create a Max Acceleration Exceeded Register item.
Repeat the procedure of the previous step with the following edits:
• Name: Max Acceleration Exceeded
lI
• Data Type: Boolean
na
• Initial Value: 0
8. Verify that the first frame of the Sequence structure should look like Figure 4-1.
Figure 4-1. FPGA Main VI—First Frame of Sequence Structure
io
at
N
3
2 02
ht
ig
yr
op
C
Lesson 4
Figure 4-2. FPGA Main VI Block Diagram—Acquisition Loop
|
m
ni.com
ns
2
lI
na
io
at
N
3 3
2 02
1 Write to the Input Error Register—Place a Register Method Node on the block diagram. Right-click it and select
Select Register VI::Input Error. Right-click it again and select Select Method»Write. Wire as shown in Figure 4-2.
ht
2 Write to the Fan Speed (RPM) Register—Place a Register Method Node on the block diagram.
Right-click it and select Select Register»VI::Fan Speed (RPM).
rig
3 Write to the Max Acceleration Exceeded? Register—Place a Register Method Node on the block diagram.
Right-click it and select Select Register»VI::Max Acceleration Exceeded?.
y
op
C
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
10. Add files that you will use in a Fan Speed Control Loop to the project.
a. In Project Explorer, double-click FPGA Target»Support VIs. Right-click Support VIs and select
Add»File.
b. Navigate to the C:\Exercises\FPGA\Transfer Acquired Data to PID Loop\support
directory and hold <Ctrl> down to select PID (SGL).vi, Analyze Fan Speed (FPGA).vi,
ts
PID Control Loop - Partial.vi, and click Add File.
c. Right-click FPGA Target and select New»Virtual Folder. Rename it to Type Definitions.
en
d. Double-click FPGA Target»Type Definitions. Right-click Type Definitions and select Add»File.
e. In Project Explorer, double-click FPGA Target»Support VIs. Right-click Support VIs and select
Add»File.
m
• Navigate to the C:\Exercises\FPGA\Transfer Acquired Data to PID Loop\controls
directory and hold <Ctrl> down to select Control Configuration.ctl and FPGA state.ctl,
tru
then click Add File.
11. Copy a partially completed Fan Speed Control Loop into your FPGA Main VI.
a. In Project Explorer, double-click FPGA Target»Support VIs»PID Control Loop - Partial VI
ns
to open it.
b. Select everything on the block diagram and copy into your FPGA Main VI block diagram.
lI
c. Verify that your FPGA Main VI block diagram looks similar to Figure 4-3.
na
io
at
N
3
2 02
ht
ig
yr
op
C
Lesson 4
Figure 4-3. FPGA Main VI with Partially Completed Fan Speed PID Control While Loop
|
m
ni.com
ns
1 4
5
lI
na
io
at
N
3
02
1 State Machine Design Pattern—Notice that this While Loop uses a state machine design pattern. The FPGA State enum contains the
2
two states in this state machine: Safe State and Control (PID). If the Change State control is set to TRUE, the state machine will transition
to the state specified by New FPGA State control. However, if the output of the Compound Arithmetic function is TRUE, the state
machine will always transition to Safe State.
ht
2 Change State Boolean control—Change State Boolean control is set to a Latch mechanical action. Therefore, if this Boolean control is
set to TRUE, LabVIEW will read the TRUE value from the control and then reset the control back to its default value of FALSE.
3 Stacked Shift Register—The top element of the stacked shift register outputs the value sent to the shift register during the previous
rig
iteration of the While Loop. The bottom element of the stacked shift register outputs the value sent to the shift register during the
iteration before the previous iteration of the While Loop. Notice that the Control (PID) case of the Case structure is able to use the stacked
shift register to determine if the state machine is transitioning from the Safe State to the Control (PID) state.
4 Analyze Fan Speed (FPGA) subVI—Similar functionality to the subVI used in the Acquisition Loop.
y
5 Get Loop Period (tick) subVI—This is the same subVI used in the Acquisition Loop VI. This subVI is reentrant.
op
C
ts
en
13. Modify the block diagram, as shown in Figure 4-4, to create the Fan Speed PID Control Loop.
m
tru
3
ns
lI
4
5
na
1
2
Select Register»VI::Fan Speed (RPM)—Right-click it again and select Select Method»Read. Wire as shown in Figure 4-4.
02
2 Read tag data from Input Error Register and Max Acceleration Exceeded Register—Place a Register Method Node on the block diagram.
Right-click it and select Select Register»VI::Input Error and Select Register»VI::Max Acceleration Exceeded.
3 Loop Timer Express VI—This function sets the loop period for the Fan Speed PID Control While Loop. In the Configure Loop Timer
window of this Express VI, set Counter units to uSec and Size of internal counter to 32 Bit.
2
4 PID (SGL) subVI—In Project Explorer, drag the FPGA Target»Support VIs»PID (SGL) VI to the block diagram. This subVI implements a
PID algorithm using the SGL data type.
ht
5 FPGA I/O Node—In Project Explorer, drag the Mod2/AO0 FPGA I/O item to the block diagram. The PID (SGL) subVI determines the
voltage value to write to this analog output channel to achieve the specified fan speed setpoint.
rig
| 4-21
y
op
C
Lesson 4 Inter-Process Communication in LabVIEW FPGA
14. Modify the Safe State case of the Case structure as shown in Figure 4-5.
ts
en
m
tru
ns
15. Arrange the front panel as shown in Figure 4-6.
lI
Figure 4-6. Completed Front Panel
na
io
at
N
3
2 02
ht
ig
yr
op
C
16. Set all the front panel control values to match Figure 4-6.
Select Edit»Make Current Values Default to set the default value of all the front panel controls.
17. Save the VI and the project.
4-22 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
Note If you are taking a vILT training and using virtual machines, you will not be able to
perform the below mentioned steps.
ts
a. Right-click the FPGA Target and select Select Execution Mode»Simulation (Simulated I/O).
en
b. Run the VI.
c. Click the Change State control and look at the indicator values, execution highlighting,
single-stepping, probes, and other tools to verify that the FPGA Main VI correctly transitions
m
into the Control (PID) and Safe State states by setting the New FPGA State control.
tru
1. Set the front panel controls back to the values shown in Figure 4-4.
2. Compile the FPGA VI:
ns
a. Right-click the FPGA Target and select Select Execution Mode»FPGA Target.
b. Run the VI.
lI
c. When finished compiling, run the VI on the FPGA target.
d. Verify that the PID Loop Period (tick) indicator displays 8000 ticks, which is the number of
control.
3. Test the Control (PID) State: na
ticks that corresponds to the Requested PID Loop Period (us) of 200 us on the front panel
io
a. On the Sound and Vibration Signal Simulator, set the FAN SPEED CONTROL switch to BNC.
b. Set the Fan Speed Setpoint (RPM) to 0.
at
c. Set the New FPGA State control to Control (PID). Click the Change State Boolean control. The
FPGA should now be running the Control (PID) state.
N
d. Change the value of the Fan Speed Setpoint (RPM) control to something between 1000 and
5000, and verify that the Fan Speed (RPM) indicator.
3
exceeds 2,000 RPM, the fan turns off and the Current FPGA State indicator changes from
Control (PID) to Safe State.
ht
ts
en
m
tru
Channel wire endpoints are nodes where a channel wire terminates. By connecting a channel writer
endpoint to a reader endpoint using a channel wire, you build a channel. The channel wire endpoints
ns
operate on the channel in the following way: the writer endpoints write data to the channel, and the
reader endpoints read data from the channel. You can use the channel wire endpoints to write or read
data between parallel sections of code. LabVIEW provides several channel templates. Each template
lI
expresses a different communication protocol to use between the writers and readers. Choose which
channel template to use based on your communications needs.
4-24 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
Endpoint Description
Read With Abort Reads a value from a Tag channel or signals the channel to abort.
ts
This endpoint is the same as the Read endpoint except that it has
an abort input and an aborted? output. You can use the abort
en
capability of the Tag channel to close a channel abruptly, ignoring
any data left in the channel buffer. You must use this endpoint
together with the Write With Abort endpoint.
m
Write Writes a value to a Tag channel.
tru
Write With Abort Writes a value to a Tag channel or signals the channel to abort. This
endpoint is the same as the Write endpoint except that it has an
abort input and an aborted? output. You can use the abort capability
ns
of the Tag channel to close a channel abruptly, ignoring any data left
in the channel buffer. You must use this endpoint together with the
Read With Abort endpoint.
lI
Channel Wires: Tag Data Template
•
• na
The process of sharing value is similar to that of a global or local shared variable.
Tag channel is used to share a single value among multiple readers and/or writers.
io
• Writer overwrites the existing value in the channel to ensure the reader always gets the latest
value.
at
N
3
2 02
ht
ig
yr
op
C
Use the Tag channel to share a single value among multiple readers and/or writers. Sharing the value
is similar to sharing a global or network-shared variable. Each time a writer endpoint writes a value to
the channel, the value overwrites the existing value in the channel to ensure that the reader endpoints
always read the latest value.
ts
Endpoint Description
en
Read Scheduled Reads a value from a Tag channel at a scheduled time.
m
Read With Abort Reads a value from a Tag channel or signals the channel to abort.
tru
Write Scheduled Writes a value to a Tag channel at a scheduled time.
Write With Abort Writes a value to a Tag channel or signals the channel to abort.
ns
This endpoint is the same as the Write endpoint except that it has
an abort input and an aborted? output.
lI
The Read With Abort and Write With Abort are similar to Read and Write endpoints, respectively. The
only difference is that they have an abort input and an abort output. The abort capability of the Tag
na
channel can be used to close a channel abruptly, ignoring any data left in the channel buffer. The Read
with Abort and Write with Abort endpoints must be used together.
io
The following details apply when you use this object in an FPGA VI:
• Single-Cycle Timed Loop is not supported.
at
• This endpoint supports only fixed-sized one-dimensional arrays of supported data types. This
endpoint does not support variable-sized arrays even if the array resolves to a single size at compile
N
time.
• This endpoint does not support LabVIEW classes.
3
Note The mentioned details are subject to change with each version of the LabVIEW FPGA
02
Module.
Note A channel terminal of a non-reentrant subVI can be connected to only one channel.
2
If a non-reentrant subVI is called from multiple locations, the channel wires connected to a
given terminal must resolve to the same channel at compile time.
ht
ig
yr
op
C
4-26 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
m
tru
ns
Available Channel Wire Templates
lI
• Tag—Use the Tag channel to share a single value among multiple readers and/or writers. Sharing
na
a value is like sharing a global or network shared variable. Each time a writer endpoint writes a
value to the channel, the value overwrites the existing value in the channel to ensure that the
reader endpoints always read the latest value.
io
• Accumulator Tag—Same as a Tag, but each time a writer endpoint writes a value to the channel,
the channel adds the value to the existing value. Reader endpoints can optionally clear the value
at
when they retrieve the current sum.
• Stream—Use the Stream channel to communicate homogeneous data from a single writer to a
single reader. The data elements are buffered and transferred with no data loss in a first-in-first-out
N
(FIFO) order.
• Lossy Stream—Same a stream, but if the channel is already full when the writer attempts to write
3
a new data, the writer does not wait for space to be available.
02
• One Element Stream—Same as a stream but with a size equal to one. Allowing only one element
in the buffer makes One Element Stream channels more optimized.
Exploring FIFO
ts
First-in-First-Out (FIFO) buffer The first data item written to the FIFO is the first item read and
en
removed from the FIFO.
Like memory and registers for tag transfer, FIFOs can either be:
m
• Target-Scoped—A single FIFO transfers data between loops on multiple VIs running on the same
FPGA target.
tru
• VI-Defined—A single FIFO transfers data between multiple loops in the same VI.
ns
lI
na
io
at
To transfer data between different portions of an FPGA VI, between VIs on an FPGA target, or
between devices, use a FIFO. A FIFO is a data structure that holds elements in the order they are
N
received and provides access to those elements using a first-in-first-out access policy.
The presented illustration demonstrates the behavior of elements moving through a FIFO.
3
Use the FIFO Properties dialog box to create and configure FIFOs. All FIFOs except VI-defined FIFOs
have a corresponding item in the project. Therefore, if you use a FIFO other than a VI-defined FIFO
ig
and send the FPGA VI to another user, you must send the entire project. Otherwise, you cannot run
the FPGA VI.
yr
op
C
4-28 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
Target-Scoped FIFOs
• Appear under the FPGA target in the Project Explorer window.
• Use to store data that you need to access from multiple VIs.
• Create Target-Scoped FIFOs from the Project Explorer window.
ts
en
m
tru
ns
lI
na
io
at
N
3
02
Complete the following steps to create a target-scoped FIFO from the Project Explorer window:
1. In the Project Explorer window, right-click the FPGA target.
2. Select New»FIFO to display the FIFO Properties dialog box.
2
3. On the General page, expand the pull-down menu under Implementation to display the available
options.
ht
ts
en
m
tru
ns
lI
na
io
at
N
Note The Type drop-down does not appear if you have created a VI-defined FIFO. This
page includes the following components:
3
• Name—Specifies the name of the FIFO that appears in the Project Explorer window or in the
VI-Defined FIFO Configuration node. The name also appears in the FIFO Method Node on the block
02
diagram, and you can use it in FIFO name controls and constants to access target-scoped FIFOs.
• Type—Specifies the type of FIFO to use. This option is not available for VI-defined FIFOs.
2
• Target-Scoped—FIFOs can transfer data within the FPGA VI as well as between FPGA VIs
under the same target in the Project Explorer window.
ht
• Host to Target - DMA or Target to Host - DMA—DMA FIFOs can transfer data between the
host VI and target.
ig
• Peer to Peer Writer or Peer to Peer Reader—FIFOs can transfer data using a peer-to-peer
stream.
yr
• Disable on Overflow—Specifies to disable the peer-to-peer stream when the writer FIFO attempts
to write to the stream and fails. This option is only available for peer-to-peer writer FIFOs.
Disable on Underflow—Specifies to disable the peer-to-peer stream when the reader FIFO does not
op
•
receive data from the stream. This option is only available for peer-to-peer reader FIFOs.
C
4-30 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
• Requested Number of Elements—Specifies the desired number of elements the FIFO can hold. The
maximum number of elements the FIFO can hold depends on the Implementation you select and
the amount of resources available on the FPGA for the Implementation. If the FIFO uses built-in
control logic, the maximum number of elements also depends on the data type. The width of the
built-in FIFO must be less than or equal to 1024. If the FPGA does not have enough resources for
the Requested Number of Elements you enter, the FPGA VI fails to compile. If you select Host to
ts
Target - DMA or Target to Host - DMA in the Type pull-down menu, Requested Number of
Elements specifies the size of the FPGA FIFO of the DMA channel. Maximum DMA FIFO size varies
en
by target. Refer to the specific FPGA target hardware documentation for more information about
DMA FIFO size limitations. If you select Block Memory in the Implementation control, restrictions
apply to the number of elements the FIFO can hold. Actual Number of Elements indicates the
m
number of elements in the FIFO, which may not be the same as Requested Number of Elements.
tru
Note If you experience timeout during DMA transfers from the FPGA to a host, use the
FIFO. Configure method of the Invoke Method function and increase the Depth parameter
rather than increasing the Requested Number of Elements. Increasing the Depth parameter
increases the size of the host-side buffer, which is more likely to resolve the timeout and
ns
does not increase FPGA device utilization.
• Implementation—Specifies the type of storage the FIFO uses on the FPGA. You can specify the
lI
implementation only for target-scoped and VI-defined FIFOs. Contains the following options:
Flip-Flops—Stores the data in flip-flops available on the FPGA and provides the fastest
na
•
performance. NI recommends using this option for small FIFOs, up to 100 bytes. You cannot
use FIFOs with an Implementation of Flip-Flops or Look-Up Table across multiple clock
domains.
io
• Look-Up Table—Stores the data in look-up tables available on the FPGA. Xilinx literature
describes this implementation as distributed RAM or LUT RAM. NI recommends using this
at
option for FIFOs that are 100–300 bytes. You cannot use FIFOs with an Implementation of
Flip-Flops or Look-Up Table across multiple clock domains.
N
• Block Memory—Stores the data using embedded blocks of memory. Xilinx literature describes
this implementation as block RAM or BRAM. NI recommends using this option for FIFOs larger
than 300 bytes.
3
02
Note If you select the Block Memory option, you might not be able to read data in a
target-scoped FIFO or VI-defined FIFO until up to six clock cycles after you write the data
to the FIFO. If you select the timeout interface, use the Timed Out? output of the FIFO
2
Method Node that invokes the Read method to determine when the upstream data is ready.
If you select the handshaking interface, use the Output Valid output of the FIFO Method
Node that invokes the Read method to determine whether the upstream data is ready.
ht
ig
yr
op
C
ts
Interpret these numbers in the following ways:
en
• Built-In—Actual Number of Elements returns two numbers, which LabVIEW uses when the
handshaking interface is disabled or enabled, respectively.
m
Note (Xilinx Vivado) The actual number of elements in the FIFO is unknown at
configuration time. Actual Number of Elements returns only one number, which is the
tru
closest power of two, greater than Requested Number of Elements. This number is a
minimum guaranteed number, which might be smaller than the actual number of elements
in the FIFO.
ns
• Target-optimal—LabVIEW implements the FIFO using either slice fabric or built-in control logic,
depending on the clock domain and target type. Actual Number of Elements returns two or
lI
three numbers: the first one for the slice fabric control logic and the other(s) for the built-in
control logic.
•
•
na
Control Logic—Specifies how the FPGA implements the FIFO.
Slice Fabric—Specifies that the FPGA uses flip-flops, LUTs, and block memory to implement
the control logic for the FIFO.
io
• Target Optimal—Specifies that the FPGA uses built-in FIFO control logic or slice fabric control
logic, depending on the target and application.
at
• Built-In—Specifies that the FPGA uses built-in FIFO control logic. Not all FPGAs support built-in
FIFO control logic, and restrictions apply.
N
Note (Xilinx Vivado) If you select the built-in control logic, you cannot use this FIFO with
the Get Number of Elements to Read or Get Number of Elements to Write method because
3
the actual number of elements in the FIFO is unknown at configuration time. In simulation
mode, the Timed Out? output value of the Read or Write method might not reflect the actual
02
behavior on hardware because these methods use the conservative number in Actual
Number of Elements as the FIFO depth, which might be smaller than the actual number of
elements in the FIFO.
2
Maximum depends on the Implementation that has been selected and the amount of space available
on the FPGA for the implementation.
ig
You request the number of elements based on the needs of the application. LabVIEW specifies the
yr
actual number of elements. If the actual number is greater than the requested number, the difference
is due to technical constraints.
op
C
4-32 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
If the value specified is too large, The FPGA will fail to compile. For DMA FIFOs, Requested Number
of Elements specifies the size, in elements, of the FPGA part of the FIFO.
Requested Number of Elements—Specifies the desired number of elements the FIFO can hold. The
maximum number of elements the FIFO can hold depends on the Implementation you select and the
amount of resources available on the FPGA for the Implementation. If the FIFO uses built-in control
ts
logic, the maximum number of elements also depends on the data type. The width of the built-in FIFO
must be less than or equal to 1024. If the FPGA does not have enough resources for the Requested
en
Number of Elements you enter, the FPGA VI fails to compile. If you select Host to Target - DMA or
Target to Host - DMA in the Type pull-down menu, Requested Number of Elements specifies the size
of the FPGA FIFO of the DMA channel. Maximum DMA FIFO size varies by target. Refer to the specific
m
FPGA target hardware documentation for more information about DMA FIFO size limitations. If you
select Block Memory in the Implementation control, restrictions apply to the number of elements the
FIFO can hold. Actual Number of Elements indicates the number of elements in the FIFO, which may
tru
not be the same as Requested Number of Elements.
Note If you experience timeout during DMA transfers from the FPGA to a host, use the
ns
FIFO. Configure the method of the Invoke Method function and increase the Depth
parameter rather than increasing the Requested Number of Elements. Increasing the Depth
parameter increases the size of the host-side buffer, which is more likely to resolve the
lI
timeout but does not increase FPGA device utilization.
FIFO: Implementation
na
Implementation—Specifies the type of storage the FIFO uses on the FPGA. You can specify the
implementation only for target-scoped and VI-defined FIFOs. Contains the following options:
io
• Flip-Flops—Stores the data in flip-flops available on the FPGA and provides the fastest
performance. NI recommends using this option for small FIFOs, up to 100 bytes. You cannot use
at
FIFOs with an Implementation of Flip-Flops or Look-Up Table across multiple clock domains.
• Look-Up Table—Stores the data in look-up tables available on the FPGA. Xilinx literature describes
N
this implementation as distributed RAM or LUT RAM. NI recommends using this option for FIFOs
that are 100–300 bytes. You cannot use FIFOs with an Implementation of Flip-Flops or Look-Up
Table across multiple clock domains.
3
• Block Memory—Stores the data using embedded blocks of memory. Xilinx literature describes this
02
implementation as block RAM or BRAM. NI recommends using this option for FIFOs larger than
300 bytes.
2
Note If you select the Block Memory option, you might not be able to read data in a
target-scoped FIFO or VI-defined FIFO until up to six clock cycles after you write the data
ht
to the FIFO. If you select the timeout interface, use the Timed Out? output of the FIFO
Method Node that invokes the Read method to determine when the upstream data is ready.
If you select the handshaking interface, use the Output Valid output of the FIFO Method
ig
Node that invokes the Read method to determine whether the upstream data is ready.
yr
op
C
VI-Defined FIFOs
Right-click the VI-Defined FIFO Configuration item and select Configure to launch the Properties
dialog box.
ts
en
m
tru
ns
lI
FPGA FIFO Write and Read
na
io
• Place a FIFO Method Node from the Functions palette.
at
• Right-click the object and select Select FIFO»VI::FIFO.
• This associates a node with a defined FIFO.
N
4-34 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
Timeout—Sets the number of ticks that the method waits for available space or data if the FIFO is full
or empty.
ts
Timed Out?—True if the attempt to write or read failed. Does not overwrite or add new element.
FIFO transfer may be lossy if the write times out.
en
•
m
tru
ns
The default Timeout value is 0, resulting in no wait. If you set the Timeout value to -1, then the node
will wait indefinitely. FIFO write can fail if the FIFO was full at the time that the FIFO Write method
was called.
lI
FIFO Overflow and Underflow
•
na
Overflow: Write loop executing faster than the read loop.
FIFO is filled, and the FIFO Write method times out.
io
• Data is not written to the FIFO until space is available in the FIFO.
Space can be created by reading data or resetting the FIFO.
at
•
The method for handling overflow/underflow depends on the importance of lossless transfer.
• Latch Timed Out? output of the read/write method so that the operator can see if a timeout
2
ever occurred.
• Use Timed Out? output as a condition for termination of loop execution.
ht
ig
yr
op
C
The following methods can be used to avoid underflow/overflow conditions by monitoring the status
of the FIFO.
Get Number of Elements to Read: Returns the number of elements remaining to be read.
ts
en
m
Get Number of Elements to Write: Returns the number of empty elements remaining in the FIFO.
tru
ns
Clear Method
lI
• FIFOs retain data if the FPGA is stopped and restarted.
Use the Clear Method to empty a target-scoped or VI-defined FIFO.
na
•
Additional Resources
3
02
Topic Website
Global Variables
2
LabVIEW Help
Communicating Data between Parallel Sections of Code Using
ht
Channel Wires
4-36 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
b. Memory item
c. Register item
en
d. FIFO
e. Channel Wire
m
tru
2. Which of the following is not a supported Channel Wire template in LabVIEW FPGA?
a. Lossy Stream
b. Accumulator Tag
ns
c. High Speed Stream
d. One Element Stream
lI
na
3. Which of the following may result if an FPGA VI with a FIFO Read or Write does not monitor the
Timed Out? output, assuming that the Timeout is not -1 (infinite)?
Select all that apply.
io
a. Attempts to write when there is no room in the FIFO may go undetected.
b. Attempts to read from an empty FIFO may be misinterpreted as having produced valid data.
at
ts
b. Memory item
c. Register item
en
d. FIFO
e. Channel Wire
m
tru
2. Which of the following is not a supported Channel Wire template in LabVIEW FPGA?
a. Lossy Stream
b. Accumulator Tag
ns
c. High Speed Stream
d. One Element Stream
lI
na
3. Which of the following may result if an FPGA VI with a FIFO Read or Write does not monitor the
Timed Out? output, assuming that the Timeout is not -1 (infinite)?
Select all that apply.
io
a. Attempts to write when there is no room in the FIFO may go undetected.
b. Attempts to read from an empty FIFO may be misinterpreted as having produced valid data.
at
4-38 | ni.com
ts
5
en
Communicating
m
between the
tru
FPGA and
ns
lI
Real-Time VIs
io
na
at
N
Topics
02
B. Deploying an FPGA VI
C. Transferring Latest Data (Tag)
ht
Exercises
Exercise 5-1 Transfer Tag Data between FPGA and RT
op
ts
Developing the Real-Time VI on Real-Time Target
To add a VI under the Real-Time target, right-click cRIO Target in the Project Explorer window, then
en
select New»VI.
m
tru
ns
lI
na
io
at
N
3
2 02
ts
If you place a checkmark in the Run the FPGA VI checkbox in the Configure Open FPGA VI Reference
dialog box, the FPGA VI starts running if it is not already running. The Open FPGA VI Reference
en
function will just open a reference to the FPGA VI if the FPGA VI is already downloaded and running.
If you want to restart the FPGA VI, you can use the Invoke Method function to abort or reset the FPGA
VI, then use the Invoke Method function to run the FPGA VI again.
m
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
5-4 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
B. Deploying an FPGA VI
Objective: Explore different methods to deploy the FPGA bitfile.
ts
Before using an FPGA with LabVIEW, the FPGA should have a bitfile deployed to it. This can be done
in two ways.
en
• Deploy the FPGA bitfile dynamically with the Open FPGA VI Reference Function. The FPGA bitfile
will be deployed only when the FPGA reference is opened.
• Save the FPGA bitfile to the FPGA flash. The FPGA bitfile will be automatically deployed during
m
power-up.
Note Download an FPGA VI to flash memory on the FPGA target from Project Explorer.
tru
Bitfile Deployment from RT VI Method
ns
RT VI can deploy the bitfile directly to the FPGA fabric, or a bitfile can be downloaded onto the
FPGA Flash. The FPGA Flash is persistent and sits alongside the FPGA fabric itself.
lI
na
io
at
N
3
2 02
ht
The Open FPGA VI Reference function checks if the bitfile is loaded and loads the bitfile if it has not
already been loaded. The only issue with this method is that one must wait until the OS and VI/EXE
ig
have loaded before this function executes and starts the FPGA VI/bitfile. In many cases, it is
unacceptable to have the FPGA I/O state uncontrolled as the OS and VI/EXE load.
yr
op
C
If you use the Open FPGA VI Reference function, the FPGA loads only after the OS and VI/EXE have
been loaded. Between reboots or on the initial device power on, the FPGA state is uncontrolled. By
default, the FPGA pins float when the I/O state is uncontrolled. The C Series modules are set to accept
floating FPGA pin signals and have a default behavior when they detect floating FPGA pin signals.
Generally, C Series modules will be digital low or analog 0 Volts when the I/O state of the FPGA is
uncontrolled. However, between soft reboots and managing the FPGA state for fail-safe reasons, it is
ts
useful to have control of the FPGA I/O state independent of the OS and VI/EXE.
en
m
tru
ns
lI
Bitfile Deployment from Flash Method
na
In this case, the bitfile is already downloaded onto the FPGA flash. Now, each time the system power
io
up or reboots, the FPGA loads the bitfile from the FPGA flash to the FPGA fabric.
at
N
3
2 02
ht
ig
yr
op
C
5-6 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
1. The first step in the FPGA Flash Deployment Method is to configure the build specification to
generate a bitfile that is set to run automatically when loaded onto the FPGA target. To do so,
enable the Run When loaded to FPGA option in Build Specifications and then generate the bitfile
using the build specification.
ts
en
m
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
2. The second step in the FPGA Flash Deployment Method is to download the bitfile to the FPGA
flash. You can do this either manually or programmatically.
Manual Method is good for downloading to one or a few FPGA targets.
a. Right-click the FPGA Target in the Project Explorer and select RIO Device Setup to open the
configuration window. In the RIO Device Setup dialog box, use the Download Bitfile tab to
download a bitfile to flash, and use the Device Settings tab to configure when the FPGA loads
ts
the bitfile from Flash memory. There are three options:
en
• Do not autoload—Leaves the I/O state uncontrolled.
• Autoload VI on device powerup—Starts running the FPGA on device power but will not
start running on soft reboots.
m
• Autoload on device reboot—Starts running the FPGA on device power and on soft reboots.
tru
Note Some cRIOs (e.g., the cRIO-906x) do not have the Device Settings tab because those
cRIOs already autoload on device powerup and reboot. For example, if you have downloaded
a bitfile to the NI cRIO-906x, it will be autoloaded by default at startup. If you want to
disable bitfile autoloading, either use the Disable FPGA Startup Application setting in
ns
NI MAX or click the Erase Bitfile on Flash button in the RIO Device Setup Utility.
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
5-8 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
To download a bitfile to several FPGA targets, use the System Configuration VIs. The subsequent
example shows how to download the bitfile to the FPGA flash of the cRIOs at the IP addresses shown
in the string array constant. This VI block diagram is typically running on a Windows PC and
downloads the bitfile from the Windows PC onto the FPGA flash of the FPGA targets.
ts
en
m
tru
ns
lI
na
Note You can also use the Find Systems VI to return a string array of the addresses of all
the systems (e.g., cRIO) found on the network.
io
This is what the timeline of events looks like for an application that has an FPGA bitfile downloaded
to flash and is set to start either on device power or reboot. Note that the FPGA I/O state is always
at
controlled.
N
3
2 02
ht
ig
yr
op
C
ts
Read/Write Control Reads a value from or writes a value to a control or indicator in the FPGA VI
en
on the FPGA target. A host VI can control, and monitor data passed through
the FPGA VI front panel.
m
You cannot access values on any wires on the FPGA VI block diagram that do not have controls or
indicators unless the data is stored in a DMA FIFO.
tru
ns
lI
Programmatic Front Panel Communication
na
Use the Read/Write control with the reference to the FPGA created by the Open FPGA VI Reference.vi
to programmatically communicate with the FPGA, to read values coming from it, or update
parameters.
io
RT VI
at
N
3
2 02
ht
ig
yr
op
C
5-10 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
FPGA VI
ts
en
m
tru
ns
lI
na
Programmatic Front Panel Communication Use Cases
io
• Sending configuration parameters or data from RT to FPGA
• Reporting status from FPGA to RT
at
data between the FPGA and the host is its low overhead. Although you cannot attain high throughput
with programmatic front panel communication, each call to the Read/Write Control function initiates
ig
data transfer with minimal delay. Therefore, programmatic front panel communication is ideal for
small, frequent data transfers.
yr
A disadvantage of programmatic front panel communication is that this method transfers only the
most current data stored on the control or indicator of the FPGA VI. For example, data could be lost
op
if the FPGA VI writes data to an indicator faster than the host VI can read the data. Also, each control
or indicator on the FPGA VI uses resources on the FPGA. Best practices in FPGA programming
recommend limiting the number of front panel objects in FPGA VIs. Finally, transferring data between
C
the FPGA VI and the host VI using front panel controls and indicators requires the use of the host
processor. As a result, the speed of data transfer is highly dependent on the speed and availability of
the host processor. A slower processor or lack of processor availability results in slower data transfer
from the FPGA target to the host.
Invoke Method Invokes an FPGA Interface method or action from a host VI on an FPGA VI.
ts
en
The following methods are supported by most targets:
m
• Run
tru
• Abort
• Get FPGA VI Execution Mode
• Reset
ns
• Download
The methods you can choose from depend on the target hardware and the FPGA VI. You must wire
lI
the FPGA VI Reference In input to view the available methods in the shortcut menu.
Close FPGA VI
na
FPGA Interface Functions: Close FPGA VI Reference
Stops and resets the FPGA VI running on the FPGA target and closes the
io
Reference reference to the VI.
at
N
3
Right-click the Close FPGA VI Reference function on the block diagram and select Close to close the
02
reference without resetting the FPGA VI running on the FPGA target. The default is Close and Reset
if Last Reference, which closes the reference, stops the FPGA VI and resets the FPGA VI running on
the FPGA target.
2
ht
ig
yr
op
C
5-12 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
Requirements
To complete this exercise, it is necessary to have access to the following hardware and software.
en
Software:
• LabVIEW 2023 Q3 (32-bit)
m
• NI-DAQmx 2023 Q3 (32-bit)
LabVIEW Real-Time Module 2023 Q1 (32-bit)
tru
•
ns
Hardware:
• An NI CompactRIO from either the 904x or 905x product lines
lI
• USB Type C or RJ45 Ethernet connection
• NI-9211 Thermocouple Input C Series Module
•
• Windows 10 PC na
NI-9474 Digital I/O C Series Module
io
Scenario
at
You will implement the transfer of tag data between the FPGA and RT target and create an RT VI that
resembles a part of the final course project. This course communication diagram is an approximation
to the exercise communication schema. You will create the VI and logic to process the signals
N
na
io
at
N
3
02 2
ht
rig y
op
C
5-14 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
Implementation
1. Review the communication diagram of the course project.
b. From the C:\Exercises\FPGA\Transfer Tag Data from FPGA to RT\Documentation folder,
open Fan Control - Communication Diagram.pdf file.
2. List all the data that needs to be transferred between the FPGA and RT Target. For each data that
ts
needs to be transferred, identify the transfer type (tag, message, or stream).
en
Table 5-1. Data to Transfer between FPGA and RT Target
Data to Transfer Transfer Type (Tag/Message/Stream)
m
tru
ns
3. From the C:\Exercises\FPGA\Transfer Tag Data from FPGA to RT directory, open
[FPGA] Fan Control (prototype) [cRIO-9056].lvproj.
a. From Project Explorer, open FPGA Main.vi and run it.
lI
• This is done so that the bitfile gets compiled as you continue with the next part of the
exercise, which is creating the RT VI.
4. Create an RT VI.
na
a. In Project Explorer, right-click the RT Target cRIO-9056 item and select New»VI.
io
b. Save the VI as C:\Exercises\FPGA\Transfer Tag Data from FPGA to RT\
RT Main - RT-FPGA Transfer Tag Data.vi.
at
N
3
2 02
ht
ig
yr
op
C
Lesson 5
Figure 5-2. RT Main - RT-FPGA Transfer Tag Data Block Diagram—True Case
|
m
ni.com
3 4
tru
ns
lI
na
io
1 Open FPGA VI Reference function:
a. Right-click the function and select Configure Open FPGA VI Reference.
at
b. Select VI and browse to FPGA Main.vi. This will deploy the bitfile associated with the FPGA VI if it is not already deployed on the
FPGA. Notice there is also a Bitfile option if you want to select a specific bitfile. This will deploy this bitfile if it is not already deployed
on the FPGA.
N
c. Leave the Run the FPGA VI and Dynamic mode options enabled. With this configuration, this function will run the FPGA VI if it is
not already running. Click Help to read more information about this dialog box.
d. Click OK.
3
2 Transfer tag data between the RT VI and FPGA VI using the Read/Write Control function:
02
a. Wire the FPGA VI Reference wire from the Open FPGA VI Reference function to the Read/Write Control function. The Read/Write
Control function is now able to populate with the names of all the controls and indicators on the FPGA VI specified by the Open
FPGA VI Reference function.
2
3 Using the functions shown, change the FPGA State if the value of the New FPGA State control has changed or if this is the first iteration
of the While Loop.
rig
6. Switch to the False case of the Case Structure and modify it, as shown in Figure 5-3.
Figure 5-3. RT Main - RT-FPGA Transfer Tag Data VI Block Diagram—False Case
ts
en
m
tru
7. Rearrange the front panel and set the control values, as shown in Figure 5-4.
ns
Figure 5-4. RT Main - RT-FPGA Transfer Tag Data VI Front Panel
lI
na
io
at
N
3
2 02
ht
ig
yr
op
Test
If you are using in-person hardware, on the Sound and Vibration Signal Simulator, set the following
switches (optional):
1. Verify that all the controls are set to the values shown in Figure 5-4.
2. On the Sound and Vibration Signal Simulator, set the Fan Speed Control switch to BNC and the
ts
other switch to UNBALANCED FAN.
3. Run the RT Main - RT-FPGA Transfer Tag Data VI, which runs this RT VI on the processor of the
en
RT target. You have programmed the RT VI to do the following:
a. Load and run the FPGA bitfile on the FPGA.
b. Transfer tag data between the FPGA VI and RT VI.
m
4. Set the Fan Speed Setpoint (RPM) control to 3000.
tru
5. Notice that the fan does not rotate because the FPGA VI is still in Safe State.
6. Set the New FPGA State control to Control (PID).
7. Verify that the fan starts to rotate and settles at a fan speed of 3000 RPM.
ns
8. Click the Stop button to stop the VI.
9. Save the VI.
lI
End of Exercise 5-1
na
io
at
N
3
2 02
ht
ig
yr
op
C
5-18 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
User-defined I/O variables can be useful if your RT VI is running on an RT target already using both
the NI Scan Engine and FPGA (i.e., hybrid mode). Your RT VI can use Scan Engine I/O Variables to
access the C Series modules in Scan Interface Mode. In addition, you can create a User-Defined I/O
en
Variable that you can access in both the FPGA VI and RT VI for tag (latest) data transfer.
m
• Read/write in FPGA VI and for FPGA-RT tag data transfer.
tru
ns
Scan Engine I/O Variables
• Read/write in RT VI.
lI
na
io
at
N
3
Use Cases
02
• Similar use cases as programmatic front panel communication, but with the timing and
synchronization of the NI Scan Engine.
2
Disadvantages
ht
Buffer Overview
ts
en
Buffer An area of computer memory that stores multiple data items.
• To transfer larger amounts of data at high rates between the FPGA target and the host,
m
you should buffer your data.
• The best way to transfer buffered data is by using Direct Memory Access (DMA) data transfer
tru
methods.
ns
Direct Memory Access A FIFO-based method for transferring data between an FPGA target and host
(DMA) computer.
lI
Consists of two parts—FPGA and host.
na
•
• Provides better performance than using the CPU to read and write data to the indicators and
controls.
N
3
2 02
ht
ig
yr
op
C
5-20 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
m
tru
ns
lI
na
DMA uses FPGA memory to store data and then transfer it at high speed to host processor memory
with very little processor involvement. This uses much fewer processor cycles when sending large
io
blocks of data compared to the front panel indicator with the FPGA Read/Write method.
Here are some programming tips for implementing DMA:
at
• When setting the FPGA buffer size, you can use the default size (1023). Creating a larger FPGA
memory buffer typically has no benefits.
N
• If you are passing an array of data, the Number of Elements input should always be an integer
multiple of the array size. For example, if you are passing an array of 8 elements, the Number of
Elements should be an integer multiple of 8 (such as 80, which would give 10 samples of 8
3
elements each).
Each DMA transaction has overhead, so reading larger blocks of data is typically better. The DMA
02
•
FIFO Read function automatically waits until the Number of Elements you requested becomes
available, minimizing processor usage.
2
• Packing 16-bit channel data into a U32 (since DMA uses the U32 data type) typically does not
have benefits. That is because the PCI bus has a very high bandwidth for sending DMA data, so
you are most likely nowhere near using up all the bus bandwidth. Instead, it is typically the
ht
processor that is the bottleneck in processing the data being streamed. Packing the data in the
FPGA means it has to be unpacked on the processor, adding additional processor overhead. In
ig
general, you should send each channel as a U32 even if you are acquiring 16-bit data.
yr
The Timed Out? output on the DMA FIFO Write function is an error indicator. Under normal operation,
this should never occur, so it is recommended that you stop the application if this error occurs and
reset the FPGA before restarting.
op
C
ts
en
m
tru
ns
lI
DMA FIFO: Buffer Data Sizes na
io
at
N
3
2 02
ht
ig
yr
op
C
5-22 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
m
tru
ns
lI
na
io
at
• In the FIFO Properties dialog box of the DMA FIFO, use Requested Number of Elements to set the
size of the buffer on the FPGA.
3
• Save resources by choosing the smallest size that is reasonable for your application.
02
The default FPGA buffer size of 1023 is typically enough for most applications.
2
ht
ig
yr
op
C
ts
en
m
tru
FIFO.Configure Method—Specifies the depth of the host memory part of the DMA FIFO. The new
depth is implemented when the next FIFO Start, FIFO Read, or FIFO Write method executes. Before
the new depth is set, LabVIEW empties all data from the host memory and FPGA FIFO. This method
ns
is optional.
Depth—Specifies the number of elements in the host memory part of the DMA FIFO. On certain
targets, the value wired to this parameter may not be the actual number of elements allocated for the
lI
host memory part of the DMA FIFO. On these targets, the number of bytes allocated in memory will
be coerced to a multiple of 4096 bytes, which may increase the actual number of elements in the host
na
memory part of the DMA FIFO. If you do not wire this parameter, the Invoke Method function uses a
default of 10,000 elements or twice the size of the FPGA FIFO buffer, whichever is greater.
io
Place the DMA FIFO onto the block diagram of your FPGA VI by dragging it from Project Explorer.
at
N
3
2 02
ht
ig
yr
op
C
5-24 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
On the RT VI:
• Open a reference to the FPGA.
• Add an Invoke Method function.
ts
en
m
tru
ns
lI
na
io
Using DMA FIFOs Effectively
at
Using Target to Host DMA FIFO
• RT VI
N
3
Read Data
02
• FPGA VI
2
Write Data
ht
ig
The presented example shows a Target to Host DMA FIFO, where the FPGA VI writes and the RT VI
reads. You can also create a Host to Target DMA FIFO, where the RT VI writes and the FPGA reads.
yr
Note Target to Host – DMA is the name specified in the FIFO Configuration dialog box of
op
ts
en
m
tru
ns
RT (Host) VI—The RT (Host) VI uses the first DMA FIFO Read to immediately determine how many
lI
elements are remaining in the DMA FIFO. Note that the first DMA FIFO Read has a timeout of 0 and
reads 0 elements. If the first DMA FIFO Read determines that at least 10 elements remain in the DMA
FIFO, the Host VI will use a second DMA FIFO Read to read 10 elements from the DMA FIFO. If not,
na
the Host VI does not read any elements from the DMA FIFO and uses a Wait function in the False case
of the Case structure to specify how long to wait before polling the DMA FIFO again. The Wait
prevents the While Loop from using 100 % of the CPU.
io
at
N
3
2 02
ht
ig
Note All the DMA FIFO Read methods on the Host VI have 0 wired to the timeout input.
On some RT targets, such as the cRIO, any timeout value other than 0 will cause the
yr
DMA FIFO Read method to use 100 % of the CPU to actively check the DMA FIFO for the
number of elements.
op
C
5-26 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
RT VIs
en
m
tru
ns
lI
na
io
at
N
Overflow—FIFO is filled as a result of data being written faster than it is read, data may be lost.
02
• The speed of the CPU and competing tasks impact the transfer data from DMA to application
memory.
ig
The speed of the overall DMA transaction is limited by the processor (windows, real-time). The
processor is not used for DMA transfer, but it is used to copy the memory from DMA to application
yr
memory. The speed of the CPU and competing tasks limit the availability of CPU resources.
op
Increasing the host buffer size is a common necessity for many applications. The default host buffer
size of 10,000 elements (or twice the FPGA buffer size) is on the small side but is adequate for some
single-point applications. Many data streaming applications (which are the most common use cases
for DMA) use a host buffer size of at least 1,000,000 elements. For example, many cRIO data
C
ts
en
m
tru
It is very important to latch the overflow, as overflow typically will not be persistent.
ns
Recovering from a DMA FIFO Overflow
lI
There are two primary methods for clearing the DMA FIFO when an overflow occurs, depending on
whether you want to keep the data is in the DMA FIFO.
•
•
na
Reset the FPGA VI—Discards the data in the DMA FIFO.
Flushing the buffer—Reads the remaining data in the DMA FIFO.
io
Either method can be performed to initialize the DMA FIFO at the beginning of execution.
at
To reset programmatically:
• Use the Invoke Method function.
2
• Use the Close FPGA VI Reference function configured to Close and Reset if Last Reference.
ht
ig
yr
op
C
5-28 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
m
tru
ns
Clearing DMA FIFO: Flush DMA FIFO Buffer Method
lI
• Stop writing to the DMA FIFO.
• Find out how much data remains in the DMA FIFO.
•
na
Read all the remaining elements to empty the DMA FIFO.
RT VIs
io
at
N
3
02
Note If your DMA FIFO data is interleaved, it is usually impossible to use the data you
flush.
2
ht
ig
yr
op
C
ts
Requirements
To complete this exercise, it is necessary to have access to the following hardware and software.
en
Software:
• LabVIEW 2023 Q3 (32-bit)
m
• NI-DAQmx 2023 Q3 (32-bit)
LabVIEW Real-Time Module 2023 Q1 (32-bit)
tru
•
ns
Hardware:
• An NI CompactRIO from either the 904x or 905x product lines
lI
• USB Type C or RJ45 Ethernet connection
• NI-9211 Thermocouple Input C Series Module
•
• Windows 10 PC na
NI-9474 Digital I/O C Series Module
io
Scenario
at
The exercise aims to optimize data exchange between the LabVIEW Real-Time application and the
FPGA. You will create the VI and logic to process the signals specified in the communication diagram.
N
3
2 02
ht
ig
yr
op
C
5-30 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
m
tru
ns
lI
Figure 5-5. Fan Control—Communication Diagram
na
io
at
N
3
02 2
ht
rig y
op
C
© National Instruments Corporation | 5-31
Lesson 5 Communicating between the FPGA and Real-Time VIs
Implementation
1. Review the communication diagram of the course project.
a. From the C:\Exercises\FPGA\Transfer Stream Data from FPGA to RT\Documentation
folder, open Fan Control - Communication Diagram.pdf file.
2. List all the data that needs to be transferred between the FPGA and RT Target. For each data that
ts
needs to be transferred, identify the transfer type (tag, message, or stream).
en
Table 5-2. Data to Transfer between FPGA and RT Target
Data to Transfer Transfer Type (Tag/Message/Stream)
m
tru
ns
3. From the C:\Exercises\FPGA\Transfer Stream Data from FPGA to RT, open
[FPGA] Fan Control (prototype) [cRIO-9056].lvproj.
4. From Project Explorer, open RT Main - RT-FPGA Transfer Tag Data.vi.
lI
5. Save a copy of this VI:
na
a. From this VI, select File»Save As. Then select Copy»Open additional copy. Ensure that the
Add copy to [FPGA] Fan Control (prototype) [cRIO-9056].lvproj checkbox is enabled.
b. Click Continue.
io
c. Save the VI as C:\Exercises\FPGA\Transfer Stream Data from FPGA to RT\
RT Main - RT-FPGA Transfer Stream Data.vi.
at
5-32 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
7. Create the DMA FIFO that you will use to transfer stream acceleration data from the FPGA VI
to the RT VI:
a. In Project Explorer, right-click FPGA Target»New»FIFO.
b. Configure the FPGA FIFO Properties window, as shown in Figures 5-6 and 5-7.
The Requested Number of Elements item is where you can configure the FPGA buffer size of
ts
the DMA FIFO. Usually, you should just leave this item at the default value.
en
m
tru
ns
lI
na
io
at
N
en
5-34
Lesson 5
1. From Project Explorer, open the FPGA Main.vi.
|
2. To write stream data to the Acceleration DMA FIFO, modify the block diagram, as shown in Figure 5-8.
m
ni.com
tru
ns
lI
na
1 3
io
at
2
N
3
02
2 Right-click the Timed Out? terminal from the Acceleration DMA FIFO to create the DMA FIFO Overflow? indicator.
3 DMA FIFO Overflow?—On the front panel of the FPGA VI, move the DMA FIFO Overflow? Boolean indicator to the Acceleration section.
If the Timed Out element of the DMA FIFO Write node ever outputs TRUE, an overflow has occurred. This means you have written data
ht
to the DMA FIFO faster than it has been read, so you have lost data. If an overflow has ever occurred, then output a TRUE value on the
DMA FIFO Overflow indicator. Use the Feedback Node and Or function to implement this.
rig
en
1. To reset the FPGA VI, configure the DMA FIFO host buffer size, set the starting values of the FPGA VI controls, and run the FPGA VI,
open RT Main - RT-FPGA Transfer Stream Data.vi and add code to the left of the While Loop, as shown in Figure 5-9.
m
Figure 5-9. RT Main - RT-FPGA Transfer Stream Data VI Block Diagram—Initialization
tru
1 2 3 4
ns
lI
na
at
1
N
Reset Invoke Method—Reset the FPGA VI. Place an Invoke Method on the block diagram. Right-click it and select Method»Reset. This
aborts and resets the FPGA VI to the default state of the VI and clears the FIFOs.
3
© National Instruments Corporation
2 Acceleration.Configure Invoke Method—Configure the number of elements on the host FIFO of the DMA channel. Place an Invoke
02
Method on the block diagram. Wire in the FPGA reference wire. Right-click it and select Method»Acceleration»Configure. Right-click the
input and select Create»Constant, and set it to 102,400. The FPGA VI will write 10,240 elements per second to the DMA FIFO. Later
in this exercise, you will add code to this RT VI to read 10,240 elements per second from the DMA FIFO. Here, we set the host FIFO to
102,400 elements, which should be large enough to prevent a DMA FIFO overflow in this application.
2
3 Read/Write Control function—Set the starting values of the controls in the FPGA VI by using the Read/Write Control function. Data Rate
constant. Open the FPGA VI and copy the Data Rate control from the FPGA VI to this RT VI. On the block diagram of this RT VI, right-click
the Data Rate control and select Change to Constant.
ht
4 Run Invoke Method—Run the FPGA VI. Place an Invoke Method on the block diagram. Right-click it and select Method»Run.
5 Local Variable of Stop button—Initialize the Stop control on the RT VI to FALSE. Create a local variable of the Stop control by
right-clicking the Stop control and selecting Create»Local Variable. Then go to the front panel, right-click the Stop control, and select
rig
Mechanical Action»Switch When Released. To use a local variable on a Boolean control, you must use a switch mechanical action.
| 5-35
y
op
C
ts
en
2. To transfer stream data between the RT VI and FPGA VI using a DMA FIFO, modify the block diagram, as shown in Figure 5-10.
5-36
Lesson 5
Figure 5-10. RT Main - RT-FPGA Transfer Stream Data VI Block Diagram—Initialization
|
m
ni.com
na
5
io
at
N
3
1 2 3 4 6
02
1 Acceleration. Read Invoke Method—Check if there is a specified number of samples available to read from the DMA FIFO. Place an Invoke
Method on the block diagram. Wire the FPGA Reference wire into this node. Click Method and select Acceleration»Read.
2 Number of Elements—Read a specified number of samples from the Acceleration DMA FIFO.
3 Analyze Acceleration (RT) VI—Analyze the acceleration data by performing a grms calculation. In Project Explorer, right-click the
2
6 Local variable—Stop the bottom loop if the Stop control value is TRUE. Right-click the Stop control on the block diagram and select
Create»Local Variable. Right-click it and select Change to Read.
7 True Constant—If either loop exits, ensure that the other loop stops by setting the Stop control value to TRUE. Use a local variable.
8 DMA FIFO Monitor Overflow?—Monitor the DMA FIFO overflow status. Resize the Read/Write Control function to show another element.
y
m
tru
ns
lI
na
2 02
3 Acceleration Waveform—Add and rename the Waveform Graph (Silver) to Acceleration Waveform. Change the x-axis label from Time
to Time(s). Disable the X Autoscale from the context menu and set the X scale on the graph to start at zero and end at 0.1.
4 Power Spectrum—Add and rename the Waveform Graph (Silver) to Power Spectrum. Change the x-axis label from Time to
rig
Frequency(Hz).
| 5-37
y
op
C
Lesson 5 Communicating between the FPGA and Real-Time VIs
4. Switch to the False case of the Case Structure in the bottom loop. Modify it, as shown in
Figure 5-12, so that the loop will check the number of elements available in the DMA FIFO every
n milliseconds when waiting for the specified number to be available.
Figure 5-12. RT Main - RT-FPGA Transfer Stream Data VI Block Diagram—False Case
ts
en
m
tru
ns
5. Save the VI and project.
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
5-38 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
Test
If you are using in-person hardware, on the Sound and Vibration Signal Simulator, set the following
switches (optional):
1. Verify that the FPGA VI is finished compiling. Close the FPGA VI.
2. On the Sound and Vibration Signal Simulator, set the Fan Speed Control switch to BNC and the
ts
other switch to UNBALANCED FAN.
3. Verify that all the controls on the RT VI are set to the values shown in Figure 5-8.
en
4. Change the Max Acceleration Threshold (g) control value to 1, so you will be able to observe higher
acceleration signals before transitioning to Safe State for testing.
5. Run the RT Main - RT-FPGA Transfer Stream Data VI, which runs this RT VI on the processor of
m
the RT target. You have programmed the RT VI to do the following actions:
a. Load and run the FPGA bitfile on the FPGA.
tru
b. Transfer tag data between the FPGA VI and RT VI.
c. Read stream data from FPGA VI using the Acceleration DMA FIFO.
ns
6. Set the New FPGA State control to Control (PID).
7. Set the Fan Speed Setpoint (RPM) control to 4500.
lI
Note Confirm that the Max Fan Speed Threshold (RPM) to 6000.
na
8. Verify that the fan starts to rotate and settles at a fan speed of 4500 RPM.
9. Verify that the DMA FIFO Overflow indicator is not lit. If this indicator is lit, then you know a DMA
FIFO overflow has occurred.
io
10. Notice that the FPGA VI can stream every point of acceleration data to the RT VI.
The Acceleration Waveform graph shows every point in the acceleration waveforms. The Power
at
Spectrum graph displays the waveform in the frequency domain. This requires having every point
of data of the acceleration waveform.
N
11. Set the New FPGA State control to Safe State. The fan should now stop rotating.
12. Click the Stop button to stop the VI.
3
13. If you wish to take a closer look at the time domain, you can zoom in on the Acceleration
Waveform graph by looking at x-axis time from just 0 to 0.05 seconds, as shown in Figure 5-13.
02
14. If you wish to take a closer look at the frequency domain, you can zoom in on the Power Spectrum
graph by looking at x-axis frequencies from just 0 to 1000 Hz, as shown in Figure 5-13. You
should see a peak at approximately 75 Hz. At 4,500 RPM, the unbalanced fan is spinning 75 times
2
ts
en
m
tru
ns
lI
na
io
15. Save the VI and the project.
16. Close the VI and the project.
at
5-40 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
• You can interleave data of the same type prior to writing to the DMA FIFO.
en
• Combine multiple elements of the same data type into a single array.
• Module 1 Channel 0—Index 0
m
• Module 1 Channel 1—Index 1
• Iterate through that array, writing the data one element at a time to the DMA FIFO.
tru
FPGA VI
ns
lI
na
io
at
N
• Divide the data into multiple arrays, each representing a single channel of acquisition.
Process the data for each channel.
02
RT VIs
2
ht
ig
yr
op
C
ts
Requirements
en
To complete this exercise, it is necessary to have access to the following hardware and software.
Software:
m
• LabVIEW 2023 Q3 (32-bit)
• NI-DAQmx 2023 Q3 (32-bit)
tru
• LabVIEW Real-Time Module 2023 Q1 (32-bit)
• LabVIEW FPGA Module 2023 Q1 (32-bit)
ns
• NI CompactRIO 2023 Q3 (32-bit)
Hardware:
lI
• An NI CompactRIO from either the 904x or 905x product lines
• USB Type C or RJ45 Ethernet connection
•
•
na
NI-9211 Thermocouple Input C Series Module
NI-9474 Digital I/O C Series Module
Windows 10 PC
io
•
Scenario
at
The exercise aims to prepare the acquired data to be shared with the RT VI, you will use basic
LabVIEW programming functions to act upon all the channels as an array and then extract the signals
N
that will be updated and shared. You will create the VI and logic to process the signals specified in
the communication diagram.
3
2 02
ht
ig
yr
op
C
5-42 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
m
tru
ns
lI
Figure 5-14. Fan Control—Communication Diagram
na
io
at
N
3
02 2
ht
rig y
op
C
© National Instruments Corporation | 5-43
ts
Implementation
en
5-44
Lesson 5
1. From the C:\Exercises\FPGA\Sample Project directory, open Fan Control (deploy) [cRIO-9056].lvproj.
|
m
ni.com
tru
4. Transfer multiple channels of data through a single DMA FIFO by interleaving the DMA FIFO.
ns
lI
na
io
2
at
N
1 3
2 02
ht
1 Build Array—The Build Array function combines data from each channel into a 1D array.
2 For Loop—For Loop processes the data and writes the data to the Acceleration DMA FIFO for every channel, one channel at a time.
rig
m
3
tru
2
ns
lI
1
na
2 De-interleave the data—The Decimate 1D Array function de-interleaves the data into a separate array for each channel. The top output
02
wire contains the data for the Mod1/AI1 channel, and the bottom output wire contains the data for the Mod1/AI2 channel.
3 Process the data for each channel—This example uses the Build Array function and For Loop to process the data for each channel.
2
y
op
C
Lesson 5 Communicating between the FPGA and Real-Time VIs
Techniques Overview
ts
Boolean Flag—Use of a Read/Write control to send a Boolean flag to the FPGA.
en
m
Interrupts—A physical hardware line to the host that the FPGA target asserts.
tru
ns
lI
Exploring Boolean Flag
Use Cases
• RT VI notifies the FPGA Vi of an event.na
io
• Easy way for RT VI to tell FPGA VI to run something.
at
RT VI FPGA VI
N
3
2 02
Use the Boolean flag method when you need the host VI to notify the FPGA VI of an event. Notice
ht
that the Boolean control on the FPGA VI has latching mechanical action. When the Host VI sets this
Boolean control to True with the Read/Write Control function, the Boolean control on the FPGA VI will
output a True value and then automatically latch back to a False value.
ig
yr
op
C
5-46 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
Exploring Interrupts
Use Cases
• FPGA VI notifies the RT VI of one-time or infrequent events.
• FPGA has started or is ready.
ts
• Task has finished.
en
• Trigger occurred.
• Error occurred.
• Generate interrupts from the FPGA VI.
m
• Minimize CPU usage of host processor.
tru
ns
lI
You can generate an interrupt on the FPGA VI to notify the Host of one-time or infrequent events. One
na
advantage of using interrupts instead of polling is that interrupts minimize the use of the host
processor. However, the overhead required to process the interrupt increases latency relative to
polling-based synchronization.
io
Interrupts require the execution of a low-level driver on the host, so a host VI can process more polling
at
operations per second than interrupts per second. An example of a polling operation is the Host using
the Read/Write Control function to continually read the status of a Boolean control on the FPGA VI in
N
Interrupt VI on FPGA
3
Wait Until Cleared—Specifies if this VI waits until the host VI acknowledges the logical interrupt.
The default is FALSE.
2
Interrupt VI becomes a shared resource if you use more than one and can induce jitter.
ht
ig
yr
IRQ Number(s)—Specifies the logical interrupt or array of logical interrupts for which the function
waits.
ts
Timeout (ms)—Specifies the number of milliseconds the VI waits before timing out.
-1 = infinite timeout.
en
Timed Out—Returns TRUE if this method has timed out.
m
IRQ(s) Asserted—Returns the asserted interrupts. Empty or -1 array indicates that no interrupts were
received.
tru
ns
lI
na
Interrupt Example: Synchronize Start of Code in RT and FPGA
The subsequent example shows how to use an interrupt to synchronize the start of code in the host
VI and the FPGA VI.
io
RT VI
at
N
3
02
FPGA VI
2
ht
ig
yr
op
C
5-48 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
What Is a Watchdog?
ts
• FPGA VI monitors the status of the RT VI.
• FPGA VI can act if RT VI becomes unresponsive.
en
• Reboot RT target.
• Set I/O to safe states.
m
Implementation Overview
This code is a simplified version of the code in the FPGA Control sample project in LabVIEW.
tru
RT VI
ns
lI
na
io
at
FPGA VI
N
3
2 02
ht
ig
yr
op
C
ts
Requirements
en
To complete this exercise, it is necessary to have access to the following hardware and software.
Software:
m
• LabVIEW 2023 Q3 (32-bit)
• NI-DAQmx 2023 Q3 (32-bit)
tru
• LabVIEW Real-Time Module 2023 Q1 (32-bit)
• LabVIEW FPGA Module 2023 Q1 (32-bit)
ns
• NI CompactRIO 2023 Q3 (32-bit)
Hardware:
lI
• An NI CompactRIO from either the 904x or 905x product lines
• USB Type C or RJ45 Ethernet connection
•
•
na
NI-9211 Thermocouple Input C Series Module
NI-9474 Digital I/O C Series Module
Windows 10 PC
io
•
Scenario
at
The exercise aims to explore the use of the FPGA Watchdog in our Sample Project and understand the
impact of the Pet Watchdog control for this type of applications. You will create the VI and logic to
N
5-50 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
m
tru
ns
lI
Figure 5-17. Fan Control—Communication Diagram
na
io
at
N
3
02 2
ht
rig y
op
C
© National Instruments Corporation | 5-51
Lesson 5 Communicating between the FPGA and Real-Time VIs
Implementation
1. Review the communication diagram of the sample project.
a. From the C:\Exercises\FPGA\Sample Project\Documentation folder, open
Sample Project Diagram.png.
b. Notice the inter-target tag communication between the Watchdog Loop on the RT VI and the
ts
FPGA Watchdog Loop on the FPGA VI.
2. From the C:\Exercises\FPGA\Sample Project directory, open
en
Fan Control (deploy) [cRIO-9056].lvproj.
3. From Project Explorer, open FPGA Main.vi.
m
4. In the FPGA Main VI, explore the Watchdog Loop. If the RT VI does not continually set the
Pet Watchdog control to TRUE within the Watchdog Timeout Period, this loop will reboot the RT
application.
tru
Note It is important to notice that the Watchdog implemented here is made possible by the
specific mechanical action of the Pet Watchdog button set to “Latch”. Otherwise, if left in
ns
default “Switch”, it would never reset and would miss any RT hangs.
lI
6. From the RT Main VI block diagram, open the RT Loop - Watchdog subVI.
7. Explore the RT Loop - Watchdog subVI block diagram. As long as the RT VI is responsive, this loop
na
continually pets the watchdog at the specified Watchdog Pet Rate (ms).
8. Close the RT Loop - Watchdog subVI without saving.
io
9. Close this project without saving any VIs or the project.
at
Additional Resources
3
02
Topic Website
(FPGA Module)
5-52 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
b. Read/Write Control
c. Invoke Method
en
d. Close FPGA VI Reference
m
2. Which of the following are considerations to FPGA buffer sizing?
tru
Select all that apply.
a. Depends on the number of resources available on the FPGA.
b. Refer to the specific FPGA target documentation for any potential limitation.
ns
c. It does not matter if you select a larger buffer than what you need.
lI
3. Match the communication methods to their corresponding usage.
infrequent events.
N
4. You have developed an application that acquires data and uses a DMA FIFO to transfer data from
3
the FPGA to the RT. However, the DMA FIFO repeatedly fills, resulting in an overflow condition.
02
ts
b. Read/Write Control
c. Invoke Method
en
d. Close FPGA VI Reference
m
2. Which of the following are considerations to FPGA buffer sizing?
tru
Select all that apply.
a. Depends on the number of resources available on the FPGA.
b. Refer to the specific FPGA target documentation for any potential limitation.
ns
c. It does not matter if you select a larger buffer than what you need.
lI
3. Match the communication methods to their corresponding usage.
infrequent events.
N
4. You have developed an application that acquires data and uses a DMA FIFO to transfer data from
3
the FPGA to the RT. However, the DMA FIFO repeatedly fills, resulting in an overflow condition.
02
5-54 | ni.com
ts
6
en
Exploring
m
Common FPGA
tru
Optimizations
ns
lI
na
io
Learn about optimizations for the FPGA performance and
at
resource usage.
N
Topics
A. Optimization Use Cases
3
Exercises
ht
Timed Loop
Exercise 6-2 Fix SCTL Errors
yr
Optimization Scenarios
ts
Optimize your FPGA code if one of the following scenarios occurs:
• Your FPGA code does not execute fast enough.
en
For example, the processing code in your acquisition loop does not execute fast enough, so the
acquisition loop runs slower than the required acquisition rate. You should optimize your code so
that the acquisition loop runs at its required faster rate. You must optimize for speed.
m
tru
ns
• Your FPGA code does not fit on the FPGA.
When you try to compile your FPGA VI, the compilation fails and tells you that there are not
lI
enough FPGA resources (flip-flops, LUTs, DSP48, block memory, etc.) to implement your FPGA
VI. You should optimize your code so that it fits on the FPGA. You should optimize for size.
na Compilation failed
io
at
N
3
2 02
ht
ig
yr
op
C
ts
• Avoid using large arrays on front panel of top-level FPGA VI.
• Basic optimizations listed in Programming Using LabVIEW FPGA.
en
• Replace SGL with FXP data type.
• Non-reentrant subVIs.
Multiplex a large algorithm.
m
•
tru
If your algorithm does not need to hold any state data or use data from a previous iteration, it is very
simple to just put the algorithm in a For Loop to multiplex your data through the algorithm.
ns
The advantage of this technique is that it uses much fewer FPGA resources. In this example, the
caveat is that it will take 8x longer to run 8 channels of data one-by-one through the algorithm in the
For Loop. However, if the above code is executing in a While Loop, then as long as the total amount
lI
of time to multiplex all 8 channels through the algorithm does not increase the required loop period,
then the added time from multiplexing has no detrimental effects.
na
io
at
N
resources
2 02
ht
ig
yr
op
C
6-4 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
•
Original subVI (previous i data) Multiplexed subVI (previous i data for n channels)
en
m
tru
ns
Alternatively, you can replace Feedback Nodes with Memory Items and a Channel # control.
lI
Shift registers and Feedback Nodes are implemented using flip-flops unless the compiler can optimize
one or more into a Look-Up Table (LUT). If your code does not depend on the initial value of the
na
Feedback Node to function correctly, you can save additional resources by selecting the Ignore FPGA
reset method option on the FPGA Implementation page of the Feedback Node Properties dialog box.
This allows the compiler to remove the reset logic from the register and implement it using shift
io
register lookup tables (SRLs) instead of flip-flops. SRLs can combine multiple delays into a single LUT,
which can significantly reduce FPGA resources relative to flip-flops.
at
ts
en
m
tru
ns
Multiplex a Large Algorithm: Result
lI
na Multiplexed subVI
(previous i data for n channels)
io
at
N
3
2 02
ht
6-6 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
Throughput Overview
ts
Throughput The rate at which the system can process inputs.
en
• It is a number of measurements taken per time.
• It is not a measure of how recent they are, but rather of their volume.
Although throughput is generally represented in samples per second
m
•
(S/s), many computer components are rated in B/s, MB/s, GB/s,
and so on.
tru
Speed/Throughput Optimization Considerations
ns
• Execute code inside a Single-Cycle Timed Loop (SCTL).
• Pipeline the code.
• Use Four-Wire Handshaking Protocol.
lI
• Reentrant subVIs.
na
io
at
N
3
2 02
ht
ig
yr
op
C
Dataflow in FPGA
ts
The following figure shows a simple VI that has a Boolean control, a Not function, and a Digital Output
function.
en
m
tru
ns
lI
na
io
at
N
• The Boolean control has some logic associated with the data register to retrieve data from a host
3
• The Not function has the logic associated with the function itself, a synchronization flip-flop, and
an enable chain flip-flop.
• The Digital Output function has a synchronization flip-flop and an enable chain flip-flop.
2
When the program runs, the enable line goes high to enable the synchronization flip-flop associated
with the Boolean control. Meanwhile, a rising edge of the clock pushes the data from the register
ht
through the flip-flop. Downstream, the previous values are held on the outputs of the flip-flops. During
the next rising edge of the clock, the synchronization flip-flop associated with the Not function passes
ig
the new value through. On the third rising edge of the clock, the enable in of the digital output is high,
and the new value is pushed through the flip-flop to the I/O pins. The data is synchronized using a
yr
flip-flop that pushes the data through the flip-flop on the first rising edge of the clock.
op
C
6-8 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
LabVIEW executes code in a dataflow manner. Nodes execute when data is present on all inputs.
When the node finishes execution, the outputs of the node pass data to the next node downstream.
The previous figure shows an example of the FPGA hardware required to implement a Boolean
operation.
LabVIEW code is transformed into FPGA logic in three sections: logic, synchronization, and the enable
ts
chain. The logic, shown in the upper third of the figure, corresponds to the actual LabVIEW operation.
In this example, the LabVIEW code is a Not function corresponding to an inverter in the FPGA
en
hardware. The synchronization register shown in the middle of the figure guarantees that data is
output only on rising edges of the clock. The final portion of FPGA code that is generated from the
LabVIEW code is the enable chain. The enable chain is an additional register that only outputs on the
m
rising edge of the clock. The enable chain guarantees that the FPGA logic executes in the same order
depicted on the block diagram.
tru
Due to the enable chain overhead, each function or VI takes a minimum of 1-clock cycle. Some
functions, such as analog input operations, can take hundreds of clock cycles, depending on the
complexity of the operation and hardware limitations.
ns
A VI can run only as fast as the sum of the items in a combinatorial path. One advantage of using an
FPGA is that code can run in true parallel with another operation. Because you can create code in
lI
parallel, it is often best to design code so that as many parallel operations can take place as possible.
This uses the same amount of FPGA space and can increase the execution speed by reducing the
na
combinatorial path size.
Single-Cycle Timed An SCTL is a Timed Loop that has been placed onto the block diagram of an
Loop (SCTL) FPGA VI.
The structure name is the same as the Timed Loop structure as used in Real-Time and in Windows.
ts
However, the Timed Loop on the FPGA block diagram executes one iteration per clock cycle.
en
m
tru
ns
lI
LabVIEW automatically optimizes code inside an SCTL.
• Removed enable chain registers from code inside the SCTL.
•
•
Executes more quickly.
Consumes less space on the FPGA. na
io
• All code in the SCTL finishes executing within one tick of the specified FPGA clock.
at
7 Ticks 1 Tick
N
3
2 02
• FPGA Target
Executes as a single-cycle Timed Loop.
ig
• Use to optimize performance, such as resource utilization and throughput, or to simply meet
the performance requirements of your application.
yr
• Implement multi-rate timing capabilities, precise timing, feedback on loop execution, timing
characteristics that change dynamically, or several levels of execution priority.
C
Resources For more information about differences in FPGA and RT Windows, refer to
Timed Loop VI Help.
6-10 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
and single-cycle Timed Loop running the same code. Observe the difference in speed between the two.
en
Requirements
To complete this exercise, it is necessary to have access to the following hardware and software.
m
Software:
• LabVIEW 2023 Q3 (32-bit)
tru
• NI-DAQmx 2023 Q3 (32-bit)
• LabVIEW Real-Time Module 2023 Q1 (32-bit)
ns
• LabVIEW FPGA Module 2023 Q1 (32-bit)
• NI CompactRIO 2023 Q3 (32-bit)
lI
Hardware:
• An NI CompactRIO from either the 904x or 905x product lines
•
•
na
USB Type C or RJ45 Ethernet connection
NI-9211 Thermocouple Input C Series Module
NI-9474 Digital I/O C Series Module
io
•
• Windows 10 PC
at
Scenario
You are given a VI containing code to benchmark the total number of clock ticks it takes for a While
N
Loop to run 1,024 iterations and calculate the average number of clock ticks per iteration. You
complete the block diagram to simultaneously obtain the same benchmark and calculation for a
3
Implementation
1. From the C:\Exercises\FPGA\Comparing While Loop and SCTL directory,
2
a. From Project Explorer, right-click the CompactRIO Target and select Properties.
b. In the General category, set the IP Address to the IP address of your CompactRIO target.
ig
3. From Project Explorer, open While Loop SCTL Benchmarking.vi. You will finish building this VI
in this exercise.
yr
connecting the two sequence structures to each other, the two sequence structures will run
in parallel.
b. Observe the top sequence structure. This sequence structure gets the value of the free-running
C
counter in units of ticks before and after the code in the second frame of the sequence
structure runs.
Lesson 6
except that it does not contain a While Loop.
d. Observe the code to the right of each sequence structure. This code calculates the total number of ticks it takes to run the While
|
m
ni.com
Loop 1,024 times. It also calculates the average number of ticks per loop iteration.
tru
Figure 6-1. While Loop SCTL Benchmarking VI Block Diagram
ns
lI
na
io
at
1
N
3
2 02
ht
1 Timed Loop—Double-click the Input node of the Timed Loop. Notice that the Timed Loop is configured to use the top-level timing source,
rig
which is the 40 MHz Onboard Clock on the FPGA. This means that the Timed Loop is configured to run at a rate of 40 MHz.
Test
1. Set the front panel controls to the values that you want the VI to average.
2. Compile the VI on the FPGA.
3. Run the While Loop SCTL Benchmarking VI to start the compile process.
4. When the VI finishes running, verify that the values in the Average Value (1234) indicator and
ts
Average Value (ABCD) indicator are correct.
5. Compare the Ticks (While Loop) and Ticks (SCTL) indicators.
en
6. The Ticks (While Loop) indicator shows the number of FPGA clock ticks required to run the While
Loop 1,024 times. The Ticks (SCTL) indicator shows the number of FPGA clock ticks required to
m
run the single-cycle Timed Loop 1,024 times.
7. Compare the Avg Ticks (While Loop) and Avg Ticks (SCTL) indicators.
tru
8. The Avg Ticks (While Loop) indicator shows the average number of FPGA clock ticks required to
run each iteration of the While Loop. The Avg Ticks (SCTL) indicator shows the number of FPGA
clock ticks required to run each iteration of the single-cycle Timed Loop.
ns
9. Notice that the While Loop requires about 7 FPGA clock ticks to run each iteration. The
single-cycle Timed Loop is much faster and only requires 1 FPGA clock tick to run each iteration.
lI
Note All operations in a single-cycle Timed Loop must be able to be completed within one
cycle of the FPGA clock.
ts
en
m
tru
• Time of clock tick = 1 / clock frequency.
• The default FPGA clock frequency depends on the hardware. For example, clock frequency is
40 MHz for R Series boards and cRIO.
ns
• Altering clock frequencies alters the execution speed of FPGA code.
lI
FPGA Clocks
•
diagram. na
Determine the execution time of the individual VIs and functions on the FPGA VI block
io
Types of FPGA Clocks
at
6-14 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
m
tru
ns
lI
na
io
at
•
2 02
ht
ig
yr
op
C
ts
en
m
tru
ns
lI
FPGA Top-Level Clock
na
io
• Clock that the FPGA VI uses outside of SCTLs.
at
6-16 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
Using FPGA Clocks with SCTL
en
• Can configure a SCTL to use a specific FPGA clock as its timing source.
• Default timing source is the top-level.
m
• Can set a different base clock or derived clock as the timing source.
tru
ns
lI
na
io
at
N
• All code in the SCTL must finish executing within 1 cycle of the selected timing source for the
3
•
the specified time.
2
ts
• Top-Level Clock—The clock that the FPGA VI uses outside of SCTLs.
en
Troubleshooting SCTL Errors
You can use most VIs and functions available when you target an FPGA target in a single-cycle Timed
Loop. However, you cannot use the following VIs, functions, and structures in a single-cycle Timed
m
Loop. LabVIEW reports a code generation or compile-time error for the single-cycle Timed Loop when
you try to compile an FPGA VI with any of the following VIs, functions, or structures in a single-cycle
tru
Timed Loop:
• Analog Period Measurement VI
• Butterworth Filter VI
ns
• Discrete Delay VI
• Divide function
lI
• FIFO Clear function
• FPGA I/O Method Node except with some FPGA targets
•
• Interrupt VI na
FPGA I/O Property Node except with some FPGA targets
io
• Look-Up Table 1D VI with the Interpolate data checkbox selected
• Loop Timer VI
at
• Multiple FPGA I/O Nodes configured for the same I/O resource if at least one node is inside the
loop and at least one node is outside the loop
N
• Reciprocal function
• Rotate 1D Array function
2
• Wait Express VI
• Wait on Occurrence function
yr
• While Loop
op
Resources For more information and a detailed list of unsupported objects, refer to
LabVIEW FPGA Help.
C
6-18 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
m
tru
ns
lI
na
io
at
Note You do not need to wait for the compilation to finish to find these errors.
N
• If total path propagation takes longer than 1 clock cycle, compilation fails.
02
A combinatorial path is the path through logic between the output of a register and the input of another
register on an FPGA. A register stores data on an FPGA and updates the data on the rising edge of a
ht
clock. Long combinatorial paths take more time to execute and limit the maximum clock rate of the
clock domain.
ig
Long combinatorial paths are typically a problem in single-cycle Timed Loops because the logic
between the input register and the output register must execute within one period of the clock rate
yr
you specify. In the single-cycle Timed Loop, registers within and between components are removed,
increasing the length of the combinatorial path between registers. If the code in a combinatorial path
op
does not execute within a clock cycle, LabVIEW returns a timing violation in the Compilation Failure
dialog box.
Note Deeply nested Case structures can also cause LabVIEW to return a timing violation
C
ts
en
m
tru
ns
lI
SCTL Errors—Combinational Paths
• Fix the timing violations.
•
na
Speed up the path by optimizing the code in the SCTL.
io
• Select a slower clock for the SCTL timing source.
Speed up the path by moving some code out of the SCTL.
at
•
To reduce the length of a combinatorial path, first, simplify the logic as much as possible. Once you
have reduced the logic to its simplest form, you can further reduce the length of a combinatorial path
by dividing the logic into discrete steps and pipelining your design.
3
2 02
ht
ig
yr
op
C
6-20 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
Requirements
To complete this exercise, it is necessary to have access to the following hardware and software.
en
Software:
• LabVIEW 2023 Q3 (32-bit)
m
• NI-DAQmx 2023 Q3 (32-bit)
LabVIEW Real-Time Module 2023 Q1 (32-bit)
tru
•
ns
Hardware:
• An NI CompactRIO from either the 904x or 905x product lines
lI
• USB Type C or RJ45 Ethernet connection
Scenario
na
You inherited an FPGA VI that contains code in a single-cycle Timed Loop. When you try to compile
the VI in this exercise, you run into errors caused by unsupported objects and clock rates. You will
io
use the Code Generation, Compilation Status, and Timing Violation Analysis windows to examine and
fix the errors.
at
Implementation
N
b. In the General category, set the IP Address to the IP Address of your CompactRIO target.
3. From Project Explorer, open Investigate SCTL Errors.vi.
2
NI 9234.
b. Notice that the second frame of the Sequence Structure contains a single-cycle Timed Loop
ig
that contains code to acquire from an analog input channel on the NI 9234 and calculates the
average of the last four values.
yr
c. What functions do you see in the Timed Loop that are not supported in a single-cycle Timed
Loop?
op
d. Notice the True constant wired to the Conditional terminal of the Timed Loop, this configures
the single-cycle Timed Loop to only run one iteration when it is called.
e. Notice that the While Loop will stop if the Stop control is TRUE.
C
f. Notice that the last frame of the Sequence Structure stops the analog input acquisition on the
NI 9234.
5. Run the VI to start the compilation process. Because the single-cycle Timed Loop contains
unsupported objects, LabVIEW will pop up a Code Generation Errors window instead of compiling
the VI.
6. Examine the Code Generation Errors window:
a. Notice that the Divide function and the FPGA I/O Node: Mod2/AI0 (Read) are not supported
ts
inside the single-cycle Timed Loop.
en
Note Some FPGA I/O Nodes are supported in the single-cycle Timed Loop.
m
c. Select each unsupported object and click Show Error to see where the object is on the block
diagram.
tru
d. Close the Code Generation Errors window when finished.
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
6-22 | ni.com
ts
en
7. To remove the unsupported objects from the single-cycle Timed Loop, modify the block diagram, as shown in Figure 6-2.
m
tru
6
5
ns
3
lI
2
na
7
at
4
N
3
© National Instruments Corporation
3 FPGA I/O Node—Move this object outside the single-cycle Timed Loop because it is not supported in the single-cycle Timed Loop.
4 Stop control—Move this object outside of the single-cycle Timed Loop.
5 Timed Loop—Right-click the loop condition terminal and select Create»Constant. Set the constant to TRUE. This technique configures
ht
the single-cycle Timed Loop to only run one iteration when it is called.
6 While Loop—Use the While Loop to implement the looping functionality of the code. Wire the Stop control to the loop iteration terminal
of the While Loop.
rig
7 Shift registers—Delete the shift register on the single-cycle Timed Loop. Create and wire the shift register on the While loop as shown
in Figure 6-2. Expand the shift register to display three elements.
| 6-23
ts
d. Click OK.
en
Note Create derived clocks to create clocks with frequencies other than the base clock
frequency.
m
10. Set the single-cycle Timed Loop to use the 200 MHz derived clock:
a. Double-click the Input Node of the single-cycle Timed Loop.
tru
b. Enable the Select Timing Source checkbox.
c. Select 200 MHz in the Available Timing Sources section.
d. Click OK.
ns
11. Save the VI.
12. Run the VI to start the compilation process.
lI
13. Investigate the timing violations that caused the compilation process to fail:
• When the compile fails, set Reports to Summary in the Compilation Status window. Notice
15. Examine the Timing Violation Analysis window, which displays the objects in the Timed Loop:
io
a. Notice the time requirement of 5.00 ns. Because all operations in the single-cycle Timed Loop
must execute within one FPGA clock cycle, the operations must execute within less than 5 ns
at
(1/200,000,000 seconds), which is the FPGA clock period of the 200 MHz derived clock.
b. You can see the total delay required for each path and item.
N
Note The total delay is the sum of the logic delay and the routing delay. The logic delay
02
indicates the amount of time in nanoseconds that a logic function takes to execute. The
routing delay indicates the amount of time in nanoseconds that a signal takes to traverse
between FPGA logic blocks.
2
e. Select the Timed Loop object and click Show Element to display the path on the block diagram.
ht
6-24 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
16. Fix the timing error by modifying the derived FPGA clock to an appropriate rate.
a. Add a 80 MHz derived clock:
i In Project Explorer, double-click cRIO-9056»Chassis»FPGA Target. Right-click 40 MHz
Onboard Clock and select New FPGA Derived Clock.
ii Set Desired Derived Frequency to 80 MHz.
ts
iii Click OK.
b. Double-click the Input Node of the Timed Loop.
en
c. Enable the Select Timing Source checkbox.
d. Select 80 MHz in the Available Timing Sources section.
m
e. Click OK.
17. Save the VI and the project.
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
Test
If you are using in-person hardware, on the Sound and Vibration Signal Simulator, set the following
switches (optional):
1. Compile the VI on the FPGA:
• Run the Investigate SCTL Errors VI to start the compile process.
ts
2. Test the application.
At the end of compilation, the program should download, and the FPGA VI should begin to report
en
an averaged acceleration signal value from the Y Acceleration output of the Sound and Vibration
Signal Simulator box:
a. Switch the Fan Speed Control switch to DIAL.
m
b. Twist the Fan Speed Control dial to vary the Mod1/AI0 signal.
tru
c. When finished, click Stop to stop the application.
3. Close the VI and the project.
ns
End of Exercise 6-2
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
6-26 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
If you want to use the single-cycle Timed Loop, all operations inside the loop must fit within 1 cycle
of the FPGA clock. You can use most VIs and functions in a single-cycle Timed Loop. However,
LabVIEW reports a code generation or compile-time error for the single-cycle Timed Loop when you
en
compile an FPGA VI with certain VIs, functions, or structures in a single-cycle Timed Loop. Refer to
Timed Loop for more information about objects you cannot use in a single-cycle Timed Loop.
m
tru
ns
lI
na
io
at
N
3
a 40 MHz clock, and another SCTL can run using an 80 MHz clock.
You can write to a register item or a local or global variable from only one clock domain. You can then
ig
read from the register item or local or global variable in as many clock domains as you need. LabVIEW
transfers data from the writing domain to the reading domain and uses handshaking to avoid data
corruption. You must wait several clock cycles for both the writing and reading domains to handshake
yr
a new value. Some values you write from one clock domain might not be read by the destination
domain because of the handshaking overhead. To avoid cases where data is written faster than it can
op
be read, you should program additional logic to ensure two-way communication between the reader
and writer, thus preventing data loss.
C
Note To ensure that all data written in the same iteration of the sending clock domain
arrive together in the destination clock domain, place the data in a cluster. The data for each
register item or variable handshake separately.
ts
one reader node for each memory item.
Caution When you use memory items implemented using block memory in multiple clock
en
domains, it is possible to read from and write to the same address simultaneously. However,
doing so can result in reading incorrect data.
m
Note Memory Items are not always recommended to transfer data between multiple clock
domains.
tru
Block Memory FIFOs
You can use a target-scoped or VI-defined FIFO to transfer data between clock domains only if you
ns
implement the FIFO using block memory. To change the FIFO implementation, choose Block Memory
as the Implementation of the memory item on the General page of the FIFO Properties dialog box. You
can write data to a block memory FIFO from only one clock domain. You can then read the FIFO from
lI
only one other clock domain.
na
io
at
N
3
2 02
ht
ig
yr
op
C
6-28 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
E. Implementing Pipelining
Objective: Learn how to implement pipelining in your FPGA VI.
ts
Pipelining A technique you can use to increase the throughput or speed of an FPGA loop.
en
• Takes advantage of the parallel processing capabilities of the FPGA.
• By using parallel processing, pipelining increases the efficiency of sequential code.
m
• The code should be divided into discrete steps.
• Wire inputs and outputs of each step to Feedback Nodes or shift registers.
tru
ns
lI
Feedback Nodes na
io
Feedback Nodes are identical in functionality to a shift register and are often preferable from a user
standpoint because they maintain a more congruous appearance like that in the initial code. The
at
Feedback Node uses the value wired to the initializer terminal as the initial value for the first iteration
or execution. The Feedback Node then stores the previous iteration result for each subsequent
N
execution. If you do not wire a value to the initializer terminal, the Feedback Node uses the default
value for the data type and continues building on previous results in subsequent executions.
3
You can use the Feedback Node to implement a pipeline and reduce long combinatorial paths. When
you use the Feedback Node inside a Case structure, the Feedback Node updates data only on clock
02
The Feedback Node is implemented as a register and requires logic resources in proportion to the width
2
of the data type. Using the initialization terminal slightly increases logic resource usage.
ht
ig
yr
op
C
ts
• If Input = 1 for I = 0...3.
• Output = 1, 5, 9, 13.
en
m
tru
ns
Implementation and Optimization
• Passes data to the next step of code by using shift registers.
lI
• Takes 5 clock cycles to execute.
• 3 cycles for the code, 2 for the loop.
• If Input = 1 for I = 0…3.
• Output = ?, ?, 1, 5. na
io
at
N
3
2 02
ht
ig
yr
op
C
6-30 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
Pipelining the analog input and output operations drastically reduces the loop period, increasing the
sample rate, or control loop rate. Because the analog input and analog output operations both take a
long time to run on the FPGA, it is efficient to put them in parallel on the FPGA and have them run at
the same time.
ts
en
m
tru
ns
lI
na
io
at
Note There are blue coercion dots on the math functions. Any arithmetic functions
performed on fixed-point data will generate outputs with larger integer and word lengths to
N
accommodate any possible outputs. To control the fixed-point word and integer lengths,
right-click the arithmetic function and select Properties. Navigate to the Output
Configuration tab and de-select Adapt to Source. In the Encoding section, you can specify
3
the integer and word length of the fixed-point data that is generated.
02
12 cycles
ht
ig
yr
op
In the presented figure, the longest path is from the DIO to the position indicator. Because little is done
C
a. You can shorten the longest path using basic optimizations. Reduce the Depth of the Data
Flow. Execute the increment and decrement functions in parallel to shorten the path.
9 cycles
ts
en
m
tru
ns
b. You can shorten the longest path further by implementing pipelining. Implement pipelining to
reduce the loop rate to 6 clock cycles.
lI
6 cycles
na
io
at
N
3
2 02
• If total combinatorial path propagation takes longer than 1 clock cycle, compilation fails.
• First, shorten the longest path using basic optimizations.
ig
• If necessary, reduce the length of the combinatorial path further using pipelining.
yr
op
C
6-32 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
Implementation in SCTL
Within this SCTL, the combinatorial path is too long for the FPGA to successfully compile. You should
reduce the combinatorial path by pipelining the block diagram.
ts
en
m
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
ts
en
m
tru
ns
lI
na
When you implement a pipeline, the output of the final step lags the input by the number of steps in
io
the pipeline, and the output is invalid for each clock cycle until the pipeline fills. The number of steps
in a pipeline is called the pipeline depth, and the latency of a pipeline, measured in clock cycles,
at
corresponds to its depth. For a pipeline of depth N, the result is invalid until the Nth loop iteration, and
the output of each valid loop iteration lags the input by N-1 iterations.
N
The subsequent block diagram shows a pipeline with three steps. Therefore, the result of the final step
is invalid until the 3rd loop iteration (i = 2), and the output of each valid loop iteration lags its
corresponding input by two iterations.
3
2 02
ht
ig
yr
op
C
6-34 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
Requirements
To complete this exercise, it is necessary to have access to the following hardware and software.
en
Software:
• LabVIEW 2023 Q3 (32-bit)
m
• NI-DAQmx 2023 Q3 (32-bit)
LabVIEW Real-Time Module 2023 Q1 (32-bit)
tru
•
ns
Hardware:
• An NI CompactRIO from either the 904x or 905x product lines
lI
• USB Type C or RJ45 Ethernet connection
Scenario
na
You inherited an FPGA VI that contains code in a single-cycle Timed Loop that needs to execute using
io
an 80 MHz derived clock. However, the code currently cannot finish executing within one FPGA clock
cycle of the 80 MHz clock. You use pipelining to speed up the code so that it can run using the 80 MHz
clock.
at
Implementation
N
ts
If you compile this VI, the compilation fails due to timing violations and you would investigate
the Timing Violation Analysis window, as shown in Figure 6-3.
en
Figure 6-3. Timing Violation Analysis Window
m
tru
ns
lI
na
io
at
N
3
c. How can you use pipelining to reduce the total delay of Path 1 to less than or equal to
12.49 ns?
ht
ig
yr
op
C
6-36 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
5. Modify the block diagram, as shown in Figure 6-4, to speed up the path inside the single-cycle
Timed Loop by reducing the path length using the pipelining technique.
ts
1
en
m
tru
ns
2
1 Feedback Node—Delete the wires between the Process Data subVIs. Place two Feedback Nodes
lI
on the block diagram. Right-click each Feedback Node and select Change Direction.
2 Greater Or Equal? function—Because this pipeline has three steps, the first valid output of the
3 na
final step does not occur until the third iteration of the single-cycle Timed Loop. Therefore, use
the Greater Or Equal? function to indicate whether the output of the final step is valid.
Case structure—Place the Result indicator in the True case. Leave the False case empty.
io
Note When you implement a pipeline, the output of the final step lags behind the input by
at
the number of steps in the pipeline, and the output is invalid for each clock cycle until the
pipeline fills. The number of steps in a pipeline is called the pipeline depth, and the latency
of a pipeline, measured in clock cycles, corresponds to its depth. For a pipeline of depth N,
N
the result is invalid until the Nth clock cycle, and the output of each valid clock cycle lags
behind the input by N-1 clock cycles.
3
Test
1. Compile the VI on the FPGA.
• Run the Pipelining VI to start the compile process.
2. Verify that the FPGA VI now compiles successfully due to your pipelining optimization.
3. When finished, abort the execution of the FPGA VI.
ts
4. Close the VI and the project.
en
End of Exercise 6-3
m
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
6-38 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
To increase the throughput of Express VIs, place them inside an SCTL and use four-wire handshaking.
en
m
tru
ns
lI
VI Execution Modes
na
io
Outside Single-Cycle Timed Loop Inside Single-Cycle Timed Loop
at
N
3
2 02
ht
ig
yr
The Express VI generates different codes depending on its configuration parameters. The Execution
Mode configuration parameter determines if the Express VI may be placed inside a Single-Cycle Timed
op
Loop or not. In the presented example, due to the algorithm, this node (Mean, Variance and Standard
deviation Express VI) includes a handshaking terminal even when it is configured for execution outside
a single-cycle timed loop, and there are additional terminals on the Express VI configured to operate
C
inside a Single-Cycle Timed Loop. These terminals are also used for handshaking between upstream
and downstream nodes and will be covered in more detail later. Lastly, point out that when the
Execution Mode is Inside SCTL, there is a Latency specification.
Throughput The minimum number of FPGA clock cycles that must elapse before this
function can receive valid input data.
ts
en
Latency The number of iterations before generating a valid result for the
corresponding input.
m
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
Most FPGA Math & Analysis VIs (when set to execute in a SCTL) are multi-cycle, which means these
yr
functions take more than 1 cycle to return a valid result. If you place a multi-cycle node inside a
single-cycle Timed Loop, it does not return a valid value during every clock cycle. The throughput rate
of the function and the values of the handshaking terminals determine the clock cycles during which
op
this function produces a valid value. The throughput rate, in cycles/sample, is the minimum number
of FPGA clock cycles that must elapse before this function can receive valid input data. Latency is the
number of iterations before generating a valid result.
C
Note Throughput and latency may change depending on how the node is configured. In
many functions, you can configure the throughput. Consider an SCTL iteration to be an
FPGA cycle.
6-40 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
en
m
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
Most multi-cycle Express VIs implement throughput and latency as shown in the presented figure.
For this example, in the configuration of the High Throughput Square Root VI, the throughput is
op
Throughput
C
Two SCTL iterations (i.e., FPGA clock cycles) must elapse before the function can accept a new input.
Notice that there are two SCTL iterations between this function accepting input A, input B, input C,
input D, and input E.
Latency
This requires 8 cycles from the time it accepts input A to when it generates a valid output A’ that
corresponds to input A. Notice that eight SCTL iterations (i.e., FPGA clock cycles) occur between
input A and output A’, input B, and output B’, input C and output C’, etc.
The example function requires 8 cycles before it outputs the first valid result. But afterwards, this
ts
example function will output a new valid result every two cycles. The timing above shows how most
functions with a throughput setting execute.
en
FFT Express VI Example
m
The FFT Express VI implements throughput and latency differently from other multi-cycle Express VIs.
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
6-42 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
FFT Express VI
For most VIs with a throughput setting, the throughput specifies the number of iterations between
when the VI can accept a new input. However, the FFT Express VI throughput behaves slightly
differently because the FFT Express VI must process frames of n points, where n is defined by the
Length parameter in the configuration window of the Express VI. Because of this, the FFT Express VI
ts
accepts n new inputs in consecutive Iterations and returns the corresponding n outputs in consecutive
iterations after the number of iterations determined by latency. The throughput indicates how often
the FFT Express VI can accept a new frame of n points.
en
Latency
m
The example configuration of the FFT Express VI requires 228 cycles from the time it accepts the first
input of Frame A to when it generates the first valid output of Frame A’ that corresponds to Frame A.
Notice that 228 SCTL iterations (i.e., FPGA clock cycles) occur between input Frame A and output
tru
Frame A’, input Frame B and output Frame B’, etc.
ns
outputs. This is because the configured length of this FFT Express VI is 64.
Throughput
lI
The throughput of 4.07 cycles/sample is the overall throughput when using this configuration of the
FFT Express VI. In this example, Frame A consumes inputs for 64 consecutive cycles and waits
na
196 cycles before consuming inputs for another 64 consecutive cycles. This gives you an overall
throughput of 4.0625 cycles/sample ((64+196) / 64). Rounding to a slower throughput, you get
~4.07 cycles/sample.
io
at
N
3
2 02
ht
ig
yr
op
C
VI Handshaking
ts
en
m
tru
ns
lI
In a single-cycle Timed Loop, handshaking is necessary because multi-cycle nodes need more than one
cycle to compute valid data, but the single-cycle Timed Loop forces these nodes to return data every
na
clock cycle. Therefore, multi-cycle nodes do not return valid data every clock cycle (due to throughput
and latency). To ensure the numerical accuracy of an algorithm, nodes that depend on this data must
know whether the data is invalid or valid.
io
NI has established a handshaking protocol you can use with certain nodes inside a single-cycle Timed
Loop. This protocol involves the following terminals:
at
• input valid—Specifies that the next data point has arrived for processing.
output valid—Indicates that the current data point produced by the node is valid and ready to be
N
•
used by downstream nodes. This terminal also exists for many math and analysis functions that
run outside of the SCTL, simply due to the nature of the algorithm.
3
• ready for output—Specifies whether the downstream node can accept a new data point.
ready for input—Indicates whether the node can accept a new data point during the next clock
02
•
cycle.
Note Because this protocol involves four terminals, handshaking in FPGA VIs is sometimes
2
6-44 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
Since ready for input indicates readiness on the next clock cycle, a feedback node is used.
Handshaking determines:
• When a function discards data from upstream nodes
• When a function accepts data from upstream nodes
• When downstream nodes discard data from an upstream function
ts
• When downstream nodes accept data from an upstream function
en
m
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
Note These nodes may contain an initial initialization cycle. If you convert them to subVIs,
yr
you may notice the First Call? primitive is wired to the Reset? terminal of the internal
implementation.
op
C
ts
en
m
tru
ns
Throughput is the rate at which a node is ready to accept new data. In a series of connected nodes
lI
inside a SCTL, the node with the slowest throughput will bottleneck the entire SCTL.
For a series of connected nodes inside a single-cycle Timed Loop, the fastest throughput rate refers
na
to the fewest number of clock cycles, after which you can send more data to the series. The fastest
throughput rate is equal to the throughput rate of the slowest node (that is, the node with the highest
value of its Throughput control) in the series. This node is the bottleneck for all nodes in the series. If
io
the system sends data to this series at a rate that is faster than this fastest rate (that is, the system
waits fewer than the fewest number of allowable clock cycles before sending data to the series),
at
To determine the fastest throughput rate for a series of nodes, first determine the throughput rate of
each node by looking at the Throughput control for that node. You can see this control by
double-clicking a node or by displaying the Context Help window of the node. The Throughput control
3
with the highest value (that is, the slowest node) has the fastest rate (that is, the fewest number of
cycles) at which the system can send data to this series of functions.
02
example, if Node A has a latency of 0 cycles, Node B has a latency of 3 cycles, and Node C has a
latency of 228 cycles, then the total latency for the series of nodes is 231 cycles.
ht
Caution
ig
Use caution when branching wires. It is important to consider node latency when branching wires. If
the latency between two parallel branched paths is different, data along the two branches may not be
yr
correlated.
op
C
6-46 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
• Logarithmic, etc.
• All operations are supported inside the SCTL:
en
• Divide inside an SCTL.
• Use SCTL to optimize the bitfile size.
m
These functions are like the Numeric functions but support higher throughput rates, handshaking
terminals inside a single-cycle Timed Loop, input/output registers, and automatic pipelining. The High
Throughput Add, Subtract, and To Fixed-Point functions are single-cycle functions. These functions
tru
execute in a single FPGA clock cycle. All other High Throughput Math functions are multi-cycle
functions. These functions need more than one clock cycle to execute.
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
ts
change with data types. You cannot generate graphical code from High Throughput Math nodes.
The node generates different code depending on its configuration parameters. The Execution Mode
en
configuration parameter determines if the node may be placed inside a Single-Cycle Timed Loop or
not. Notice there are additional terminals on the node configured to operate inside a Single-Cycle
Timed Loop. These terminals are also used for handshaking between upstream and downstream nodes
m
in the same way as shown in the previous section. You can configure the throughput of this node.
Changing the throughput adds internal pipelining to the implementation, but this is not the same kind
tru
of pipelining you’re used to in LabVIEW FPGA programming. This pipeline does not increase latency.
ns
lI
na
io
at
N
3
2 02
ht
ig
Additional Resources
yr
Topic Website
op
Using Single-Cycle Timed Loops to Optimize FPGA VIs (FPGA Module) ni.com
6-48 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
2. FPGA derived clock b. Clock created from a base clock that you can
use as additional clocks for an FPGA application.
en
3. FPGA top-level clock c. Digital signal existing in hardware that you can
use as a clock for an FPGA application.
m
tru
2. Which of the following objects are NOT supported in single-cycle Timed Loops?
Select all that apply.
a. Add
ns
b. While Loop
c. Loop Timer VI
lI
d. NI 9211 Analog Input FPGA I/O Node
na
3. Which of the following are ways to avoid timing violations when using SCTL in FPGA?
Select all that apply.
io
a. Optimize the code in the SCTL.
at
b. Move some code out of the SCTL.
c. Select a faster clock for the SCTL timing source.
N
1. FPGA base clock c. Digital signal existing in hardware that you can
use as a clock for an FPGA application.
ts
2. FPGA derived clock b. Clock created from a base clock that you can
en
use as additional clocks for an FPGA application.
m
tru
2. Which of the following objects are NOT supported in single-cycle Timed Loops?
Select all that apply.
a. Add
ns
b. While Loop
c. Loop Timer VI
lI
d. NI 9211 Analog Input FPGA I/O Node
na
3. Which of the following are ways to avoid timing violations when using SCTL in FPGA?
Select all that apply.
io
a. Optimize the code in the SCTL.
at
b. Move some code out of the SCTL.
c. Select a faster clock for the SCTL timing source.
N
6-50 | ni.com
ts
7
en
Debugging and
m
Testing in FPGA
tru
ns
lI
na
Learn techniques for debugging and testing your FPGA VI
and explore some additional resources.
io
Topics
at
A. Debugging and Testing FPGA Code
B. Investigating Additional Resources
N
3
02
2
ht
ig
yr
op
C
C
op
yr
ig
ht
202
3
N
at
io
na
lI
ns
tru
m
en
ts
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
To avoid unnecessary compilations, use Simulation Mode.
en
m
tru
ns
lI
na
io
at
N
3
2 02
ht
Compiling an FPGA VI can take minutes to hours. However, you can test the logic of an FPGA VI
ig
before compiling it by executing the FPGA VI in simulation mode using simulated I/O. When you use
this test method, LabVIEW generates random data for the inputs or uses a custom VI that you create
yr
to provide I/O. You can also use the FPGA Desktop Execution Node to communicate with FPGA
resources that you select and to debug your FPGA design. For some FPGA targets, you can also
execute the FPGA VI in simulation mode using real I/O.
op
When you run the FPGA VI in simulation on the development computer, you can use all traditional
LabVIEW debugging techniques, such as probes, execution highlighting, breakpoints, and
C
single-stepping, as well as debugging techniques that are specific to the FPGA host VI context.
To debug your FPGA design in simulation mode using simulated I/O, select from the following options:
• Sampling probes—Use this option to check intermediate values on a wire as a VI runs and to view
changes in signal data over time.
• FPGA Desktop Execution Node—Use this option if you need to test individual design elements of
your FPGA VI or for system-level testing for designs that rely on supported features. Supported
ts
features include front panel controls and indicators, I/O resources, and resources that use
simulated time.
en
• Custom VI Test Bench—Use this option if you need to create the data coming from a particular
input or monitor an output.
The Sampling Waveform Probe gives you the ability to visualize multiple signals on a waveform graph
m
based on sampling events.
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
7-4 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
You can use traditional debugging tools such as probes, execution highlighting, breakpoints, and
single-stepping when simulating your FPGA VIs on the development computer. However, in FPGA
designs that involve communication protocols, you need to view signals in relation to each other with
history data in order to debug the application. The LabVIEW 2013 FPGA Module introduced a new
probe based on sampling events that makes it easy to visualize signals on a waveform graph, including
relevant timing information.
ts
The Sampling Waveform Probe can use While Loops, For Loops, and FPGA clock domains as sampling
en
event sources. Multiple wires on the block diagram can be associated with those sampling sources,
so they can be visualized together on the Sampling Probe Watch Window. This new way of
visualization makes it easier to analyze multiple signals, especially when they are generated within a
m
single-cycle Timed Loop.
tru
Desktop Execution Node
ns
• Executes FPGA VI in simulation mode.
• Passes values to FPGA I/O nodes and FPGA controls/indicators.
lI
na PC Test VI
io
at
N
3
2 02
ht
ig
yr
op
C
ts
en
m
tru
ns
lI
na
io
at
N
Compiling each FPGA VI for unit testing is not feasible. One unit testing option for LabVIEW FPGA VIs
ig
is to run the VIs on a Windows target. This allows you to test the logic and algorithms. On a Windows
target, you can use graphs, and you can also use the NI LabVIEW Unit Test Framework toolkit.
yr
Another unit testing option for LabVIEW FPGA VIs is testing the VIs using the Simulation Execution
mode.
op
C
7-6 | ni.com
Developing Embedded Applications Using CompactRIO and LabVIEW FPGA
ts
CompactRIO Waveform Programming library and template for performing waveform data
en
Library acquisition (stream data from FPGA to RT).
• Uses many FPGA best practices.
• Easily modify the examples to jump-start your application
m
development.
• Install from VI Package Manager.
tru
ns
lI
na
io
at
Additional Resources
Topic Website
ts
NI CompactRIO Waveform Reference Library
en
NI LabVIEW for CompactRIO Developer’s Guide ni.com
m
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
7-8 | ni.com
ts
A
en
Additional
m
Information and
tru
Resources
ns
lI
na
io
NI provides global services and support as part of our
at
A. NI Services
To get started, register your product at ni.com/myproducts.
ts
• Easier product management with an online account.
• Receive critical part notifications, software updates, and service expirations.
en
Log in to your NI ni.com User Profile to get personalized access to your services.
m
B. Services and Resources
tru
• Maintenance and Hardware Services—NI helps you identify your systems’ accuracy and reliability
requirements and provides warranty, sparing, and calibration services to help you maintain
accuracy and minimize downtime over the life of your system. Visit ni.com/services for more
information.
ns
– Warranty and Repair—All NI hardware features a one-year standard warranty that is
extendable up to five years. NI offers repair services performed in a timely manner by highly
lI
trained factory technicians using only original parts at a NI service center.
– Calibration—Through regular calibration, you can quantify and improve the measurement
na
performance of an instrument. NI provides state-of-the-art calibration services. If your product
supports calibration, you can obtain the calibration certificate for your product at
ni.com/calibration.
io
• System Integration—If you have time constraints, limited in-house technical resources, or other
project challenges, NI Alliance Partner members can help. To learn more, call your local NI office
at
or visit ni.com/alliance.
• Training and Certification—The NI training and certification program is the most effective way to
increase application development proficiency and productivity. Visit ni.com/training for more
N
information.
– NI offers courses in several languages and formats including instructor-led classes at facilities
3
worldwide, courses on-site at your facility, and online courses to serve your individual needs.
02
thousands of example programs, tutorials, application notes, instrument drivers, and so on.
Registered users also receive access to the NI Discussion Forums at ni.com/forums. NI
Applications Engineers make sure every question submitted online receives an answer.
ht
Suite. This program entitles members to direct access to NI Applications Engineers through
phone and email for one-to-one technical support, as well as exclusive access to online training
yr
the user protection for electromagnetic compatibility (EMC) and product safety. You can obtain
the DoC for your product by visiting ni.com/certification.
For information about other technical support options in your area, visit ni.com/services, or contact
your local office at ni.com/contact.
ts
D. NI Certification
en
Earning an NI certification acknowledges your expertise in working with NI products and technologies.
The measurement and automation industry, your employer, clients, and peers recognize your NI
certification credential as a symbol of the skills and knowledge you have gained through experience.
Visit ni.com/training for more information about the NI certification program.
m
tru
ns
lI
na
io
at
N
3
2 02
ht
ig
yr
op
C
A-4 | ni.com