Professional Documents
Culture Documents
Getting Started With Compactrio and Labview
Getting Started With Compactrio and Labview
Note If you are a new user of LabVIEW or are unfamiliar with LabVIEW, refer to the
Getting Started with LabVIEW manual for information about LabVIEW and LabVIEW
terminology.
The tutorial also includes optional sections wherein you can program the
CompactRIO system using the LabVIEW FPGA Interface.
Contents
Conventions ............................................................................................ 2
Required Components............................................................................. 3
Required Software ........................................................................... 3
Required Hardware .......................................................................... 3
For Scan Interface Mode .......................................................... 3
For FPGA Interface Mode ........................................................ 4
Related Documentation.................................................................... 4
Overview of the Application in this Tutorial .......................................... 5
Setting Up the Hardware......................................................................... 5
Installing Software on and Configuring the Controller .......................... 6
Selecting the Programming Mode for Your Application........................ 7
Creating a Project in Scan Interface Mode ............................................. 9
Creating a VI in Scan Interface Mode .................................................... 10
Configuring the Timed Loop ........................................................... 10
Configuring the DO Module for Pulse-Width Modulation ............. 11
Adding Pulse-Width Modulation to the VI...................................... 12
Configuring the DI Module for Period Measurement ..................... 13
Adding a Period-Measurement Counter to the VI............................15
Adding AO and AI to the VI ............................................................15
Deploying, Testing, and Using the VI in Scan Interface Mode...............17
Optional: Modifying the Scan Interface Application Using
the FPGA Interface ...............................................................................17
Putting the Chassis and the AI Module into FPGA
Interface Mode...............................................................................18
Creating and Configuring the DMA FIFO .......................................18
Adding Example VIs to the Project..................................................19
Replacing the Timed Loop in the Example Host VI and
Running the VI ..............................................................................20
Creating a Project in FPGA Interface Mode............................................22
Creating the AI/AO Loop in the FPGA VI ......................................23
Creating the PWM Loop ..................................................................25
Creating a Host VI in FPGA Interface Mode...................................27
Running and Testing the Host VI.....................................................29
What You Have Learned .........................................................................30
Where to Go for Support .........................................................................31
Conventions
The following conventions appear in this manual:
The symbol leads you through nested menu items and dialog box options
to a final action. The sequence FilePage SetupOptions directs you to
pull down the File menu, select the Page Setup item, and select Options
from the last dialog box.
This icon denotes a tip, which alerts you to advisory information.
This icon denotes a note, which alerts you to important information.
bold Bold text denotes items that you must select or click in the software, such
as menu items and dialog box options. Bold text also denotes parameter
names, controls and indicators on the front panel, dialog boxes, sections
of dialog boxes, menu names, and palette names.
italic Italic text denotes variables, emphasis, a cross-reference, or an introduction
to a key concept. Italic text also denotes text that is a placeholder for a word
or value that you must supply.
monospace Monospace text denotes text or characters that you should enter from the
keyboard, sections of code, programming examples, and syntax examples.
This font is also used for the proper names of disk drives, paths, directories,
programs, subprograms, subroutines, device names, functions, operations,
variables, filenames, and extensions.
monospace bold Bold text in this font denotes the messages and responses that the computer
automatically prints to the screen. This font also emphasizes lines of code
that are different from the other examples.
Required Software
The following software is required for this tutorial.
Required Hardware
The following hardware is required for this tutorial.
Tip Even if you do not have the hardware used in this tutorial, you can follow the steps
and do offline configuration to learn concepts about using CompactRIO with LabVIEW.
Related Documentation
The following documents contain information that you may find helpful as
you read this tutorial:
Operating instructions for the controller and modules (shipped with the
hardware and available at ni.com/manuals).
LabVIEW HelpUse the LabVIEW Help to access information about
LabVIEW programming concepts, step-by-step instructions for using
LabVIEW, and reference information about LabVIEW VIs, functions,
palettes, menus, tools, properties, methods, events, dialog boxes, and
so on. The LabVIEW Help also lists the LabVIEW documentation
resources available from National Instruments. Access the LabVIEW
Help by selecting HelpSearch the LabVIEW Help.
Getting Started with LabVIEWUse this document as a tutorial to
familiarize yourself with the LabVIEW graphical programming
environment and the basic LabVIEW features you use to build data
acquisition and instrument control applications. Access the Getting
Started with LabVIEW PDF by selecting StartAll Programs
National InstrumentsLabVIEWLabVIEW Manuals
LV_Getting_Started.pdf.
Getting Started with the LabVIEW Real-Time ModuleUse this
document to learn how to develop a real-time project and VIs, from setting up
RT targets to building, debugging, and deploying real-time applications.
Access the Getting Started with the LabVIEW Real-Time Module PDF
by selecting StartAll ProgramsNational InstrumentsLabVIEW
LabVIEW ManualsRT_Getting_Started.pdf.
CompactRIO Reference and Procedures (Scan Interface)Use this
help file to learn about using the CompactRIO system in Scan Interface
programming mode. To access this help file from LabVIEW, select
HelpSearch the LabVIEW Help, then expand Real-Time Module
on the Contents tab and select CompactRIO Reference and
Procedures (Scan Interface).
CompactRIO Reference and Procedures (FPGA Interface)Use this
help file to learn about using the CompactRIO system in FPGA
Interface programming mode. To access this help file from LabVIEW,
select HelpSearch the LabVIEW Help, then expand FPGA
Module on the Contents tab and select CompactRIO Reference and
Procedures (FPGA Interface).
FPGA ModuleUse this help file to learn about using the LabVIEW
FPGA Module. To access this help file from LabVIEW, select
HelpSearch the LabVIEW Help, then expand FPGA Module on
the Contents tab.
This tutorial shows how to create the VIs using both programming modes,
Scan Interface mode and FPGA Interface mode.
Note Refer to the module operating instructions for information about wiring and for
specifications. If the voltage ranges or other attributes of the inputs and outputs make the
modules unsuitable for wiring together, skip the module wiring and go to step 4. You can
still complete and learn from the tutorial, but you will not be able to test the VI as described
in the Deploying, Testing, and Using the VI in Scan Interface Mode section.
Note The default network behavior of an unconfigured controller depends on the revision
of the controller. Refer to the controller operating instructions for more information about
network configuration.
The following figure shows the Project Explorer window with a digital
input and other modules added in Scan Interface mode.
LabVIEW FPGA Interface mode enables you to use C Series modules from
LabVIEW FPGA VIs. Modules that you use in LabVIEW FPGA Interface
mode appear directly under the FPGA Target item in the Project Explorer
window and I/O channels appear as FPGA I/O items under the FPGA
Target. To access the I/O channels, you configure FPGA I/O Nodes in
FPGA VIs. In LabVIEW FPGA Interface mode, you can use LabVIEW
FPGA programming to add more flexibility, customization, and
The following figure shows the Project Explorer window with the same
modules added in FPGA Interface mode.
If you want to use Scan Interface mode for your application, you can
proceed to the Creating a Project in Scan Interface Mode section. If you
want to use FPGA Interface mode, you can skip to the Creating a Project
in FPGA Interface Mode section. Alternatively, you can go through the
entire tutorial to learn about both modes.
Tip If you do not have hardware installed, you can select the New target or device radio
button to display a list of targets and devices that you can create without a physical target
or device present. Throughout this tutorial, you can perform similar offline configuration
steps to follow along and learn about using CompactRIO and LabVIEW. For more
information about offline configuration in FPGA Interface mode, refer to the Configuring
a Project for a CompactRIO Reconfigurable or Integrated System (Scan Interface) topic
of the LabVIEW Help.
6. Click OK.
7. On the block diagram, right-click the conditional terminal at the
bottom right of the Timed Loop and select Create Control from the
shortcut menu.
6. Click OK.
7. Expand the DO module item in the Project Explorer window to see
the I/O variable items for the module channels. Note that LabVIEW
has changed all the DO I/O variables to PWM I/O variables.
Note Coercing values to be between 0 and 100 ensures that duty-cycle values are valid
percentages.
8. Click OK.
9. Save the VI as Tutorial.vi.
1 If you modify the application so that the DO module produces a frequency higher than 1 kHz, you can configure the DI module
for direct frequency measurement.
The analog input in the project now consists of only single-point data. In
your application, you may want to acquire and analyze waveform data
instead. For example, if an alarm condition occurs, you may want to
monitor a physical process in more detail or observe changes in data over a
period of time. In order to do waveform acquisition of analog input data,
you need to use LabVIEW FPGA.
Tip Alternatively, you can right-click the chassis item in the Project Explorer window
and select Properties from the shortcut menu to display the CompactRIO Chassis
Properties dialog box. After you select the programming mode using that dialog box, you
must deploy settings to the chassis.
3. In the Project Explorer window, drag and drop the AI module item
onto the FPGA Target item.
Note You must configure the FIFO for the type of data that the I/O module returns. The
FIFO in this tutorial is configured for an NI 9205. The NI 9205 returns signed, calibrated
fixed-point data by default. The word length is 26 bits and the integer word length is 5 bits.
Other AI modules may return different types of data. Refer to the CompactRIO Reference
and Procedures (FPGA Interface) help file for information about the data that other AI
modules return.
6. Click OK.
TipFor more information about DMA FIFOs, go to the LabVIEW Help and search for
DMA FIFO.
Replacing the Timed Loop in the Example Host VI and Running the VI
The host VI communicates with the FPGA VI. You can run the host VI on a
Real-Time (RT) target, such as a CompactRIO controller, or on a Windows
PC. The example host VI contains a Timed Loop that you must replace with
the Timed Loop you created and configured earlier in this tutorial.
Complete the following steps to replace the Timed Loop.
Note The Timed Loop at the top of the block diagram is similar to the Timed Loop in
Tutorial.vi. Note that wiring the error out terminal of the Start Read/Write Control
to the two loops ensures that the FPGA starts running before the loops start running.
3. Delete the Timed Loop and replace it with the Timed Loop from
Tutorial.vi.
4. Rewire the error out terminal of the Start Read/Write Control to the
error in terminal of the Input Node of the new Timed Loop.
5. In the Timed Loop, delete the AI0 I/O variable and indicator, and
delete the resulting broken wires. The AI data acquisition is done in the
FPGA VI, not in the host VI.
6. Right-click the Open FPGA VI Reference function and select
Configure Open FPGA VI Reference.
7. Verify that the Open FPGA VI Reference is configured to open FPGA
Target\Using Scan Interface with FPGA Interface
(FPGA).vi and click OK.
8. Save the VI.
9. Save the project.
10. In the Project Explorer window, right-click Using Scan
Interface with FPGA Interface (FPGA).vi and select
Compile from the shortcut menu to compile the FPGA VI. Compiling
can take from a few minutes to a few hours.
Note When you compile the VI, the LabVIEW FPGA Compile Server adds to the FPGA
VI all the logic necessary to communicate with modules you are using in Scan Interface
mode. When you run the host VI, the Open FPGA VI Reference and the Start Read/Write
control wired to the Timed Loop ensure that the FPGA VI is running before the I/O
variables in the Timed Loop start returning data.
11. When the FPGA VI is compiled, run Using Scan Interface with
FPGA Interface (Getting Started).vi.
12. Stop the VI.
Tip The code in Using Scan Interface with FPGA Interface (FPGA).vi was
generated using the FPGA Wizard. Refer to the FPGA Wizard book in the LabVIEW Help
for information about using the FPGA Wizard to generate code for projects.
Use a LabVIEW project to manage VIs, targets, and I/O modules on the
development computer. Complete the following steps to create a project
using the LabVIEW FPGA Project Wizard.
1. Launch LabVIEW.
2. On the Getting Started window, under Targets, select FPGA
Project.
3. Click Go.
4. On the Create New LabVIEW FPGA Project page that appears,
select CompactRIO Reconfigurable Embedded System and
click Next.
5. Make sure Discover existing system is selected and click Next.
Tip If you do not have hardware installed, you can select Create new system. Throughout
this tutorial, you can perform similar offline configuration steps to follow along and learn
about using CompactRIO and LabVIEW. For more information about offline configuration
in FPGA Interface mode, refer to the Configuring a Project for a CompactRIO
Reconfigurable or Integrated System (FPGA Interface) topic of the LabVIEW Help.
8. Select Help and make sure that Show Context Help is checked. You
can refer to the context help throughout the tutorial for information
about items on the block diagram.
9. Select FileSave Project and save the project as Getting
Started.lvproj.
Tip Analog I/O modules return calibrated fixed-point data by default. If you need to
conserve FPGA resources, you can configure the modules to return uncalibrated data.
Right-click the module you want to reconfigure in the Project Explorer window and select
Properties from the shortcut menu to display the C Series Module Properties dialog box.
Under Calibration Mode, select Raw, then click OK.
Tip Showing error terminals uses FPGA resources. After testing and debugging your
application, you can hide error terminals to conserve resources.
10. Right-click the error out output of the FPGA I/O Node and select
CreateIndicator from the shortcut menu to create an indicator on the
front panel.
Tip In this tutorial, you use one FPGA I/O Node for I/O on two C Series modules. If you
find that you need to identify the sources of errors in your application, use one FPGA I/O
Node and error indicator for each module.
11. Right-click the conditional terminal at the bottom right of the While
Loop and select Create Control from the shortcut menu to create a
stop control.
12. Rename the new control Stop AI/AO.
Figure 12. Block Diagram of the FPGA VI with Two While Loops
Tip You can use the following formula to calculate the duty cycle:
HighPulse
------------------------------------------------------------ = DutyCycle
HighPulse + LowPulse
National Instruments, NI, ni.com, and LabVIEW are trademarks of National Instruments Corporation.
Refer to the Terms of Use section on ni.com/legal for more information about National
Instruments trademarks. Other product and company names mentioned herein are trademarks or trade
names of their respective companies. For patents covering National Instruments products/technology,
refer to the appropriate location: HelpPatents in your software, the patents.txt file on your
media, or the National Instruments Patent Notice at ni.com/patents.