Crio Sample
Crio Sample
Crio Sample
Development Fundamentals
le
Course Manual
Copyright
© 2007 National Instruments Corporation. All rights reserved.
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 or in part, without the prior written consent
of National Instruments Corporation.
National Instruments respects the intellectual property of others, and we ask our users to do the same. NI software is protected by
copyright and other intellectual property laws. Where NI software may be used to reproduce software or other 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
Sa
license or other legal restriction.
The following notices relate to certain components used in USI (Xerces C++, ICU, and HDF5). For a listing of the conditions and
disclaimers regarding these components, refer to the USICopyrights.chm.
Xerces C++. This product includes software developed by the Apache Software Foundation (http://www.apache.org/).
Copyright 1999 The Apache Software Foundation. All rights reserved.
ICU. Copyright 1995–2003 International Business Machines Corporation and others. All rights reserved.
HDF5. NCSA HDF5 (Hierarchical Data Format 5) Software Library and Utilities
Copyright 1998, 1999, 2000, 2001, 2003 by the Board of Trustees of the University of Illinois. All rights reserved.
Trademarks
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.
Members of the National Instruments Alliance Partner Program are business entities independent from National Instruments and have
no agency, partnership, or joint-venture relationship with National Instruments.
Patents
For patents covering National Instruments products, refer to the appropriate location: Help»Patents in your software,
the patents.txt file on your CD, or ni.com/legal/patents.
le
mp
Sa
Worldwide Technical Support and Product Information
ni.com
Worldwide Offices
Australia 1800 300 800, Austria 43 662 457990-0, Belgium 32 (0) 2 757 0020, Brazil 55 11 3262 3599, Canada 800 433 3488,
China 86 21 5050 9800, Czech Republic 420 224 235 774, Denmark 45 45 76 26 00, Finland 385 (0) 9 725 72511,
France 33 (0) 1 48 14 24 24, Germany 49 89 7413130, India 91 80 41190000, Israel 972 3 6393737, Italy 39 02 413091,
Japan 81 3 5472 2970, Korea 82 02 3451 3400, Lebanon 961 (0) 1 33 28 28, Malaysia 1800 887710, Mexico 01 800 010 0793,
Netherlands 31 (0) 348 433 466, New Zealand 0800 553 322, Norway 47 (0) 66 90 76 60, Poland 48 22 3390150,
Portugal 351 210 311 210, Russia 7 495 783 6851, Singapore 1800 226 5886, Slovenia 386 3 425 42 00,
South Africa 27 0 11 805 8197, Spain 34 91 640 0085, Sweden 46 (0) 8 587 895 00, Switzerland 41 56 2005151,
Taiwan 886 02 2377 2222, Thailand 662 278 6777, Turkey 90 212 279 3031, United Kingdom 44 (0) 1635 523545
For further support information, refer to the Additional Information and Resources appendix. To comment on National Instruments
documentation, refer to the National Instruments Web site at ni.com/info and enter the info code feedback.
Contents
Student Guide
A. NI Certification .....................................................................................................vii
B. Course Description ...............................................................................................viii
C. What You Need to Get Started .............................................................................viii
D. Installing the Course Software..............................................................................ix
le
E. Course Goals.........................................................................................................x
F. Course Conventions ..............................................................................................x
Lesson 1
Introduction
A. CompactRIO .........................................................................................................1-2
B. Applications ..........................................................................................................1-3
C. Application Architecture.......................................................................................1-4
mp
D. Components ..........................................................................................................1-6
E. R Series Expansion System ..................................................................................1-11
F. Star-Fabric High-Speed PCI Interface System .....................................................1-12
G. Accessories ...........................................................................................................1-14
Exercise 1-1
Exercise 1-2
Exercise 1-3
Concept: Analyze Project Specifications .........................................1-15
Concept: Selecting CompactRIO Components ................................1-18
Concept: CompactRIO Specifications..............................................1-22
H. Operation ..............................................................................................................1-24
Exercise 1-4 Concept: CompactRIO Installation and Operating Manuals............1-29
Lesson 2
Configuring CompactRIO
A. Detect the Remote Target .....................................................................................2-2
B. Configure Network Settings .................................................................................2-3
C. View Devices and Interfaces ................................................................................2-7
Sa
D. Add/Remove Software..........................................................................................2-7
Exercise 2-1 Configure a CompactRIO System ....................................................2-12
Lesson 3
Implementing Application Architecture
A. Create a Project .....................................................................................................3-2
B. Add the CompactRIO Target ................................................................................3-4
C. Add I/O Modules ..................................................................................................3-7
D. Add FPGA I/O Items ............................................................................................3-10
Exercise 3-1 Build a CompactRIO Project............................................................3-15
© National Instruments Corporation iii CompactRIO and LabVIEW Fundamentals Course Manual
Contents
Lesson 4
FPGA
A. Introduction...........................................................................................................4-2
B. Defining FPGA Logic with LabVIEW .................................................................4-5
C. FPGA VI Development Process ...........................................................................4-9
D. Developing the FPGA VI .....................................................................................4-10
E. Modular Code .......................................................................................................4-21
F. Testing with the Emulator.....................................................................................4-22
le
G. Interactive Front Panel Communication ...............................................................4-23
Exercise 4-1 Build an FPGA VI and Test it with the Emulator ............................4-25
H. Wiring the Modules ..............................................................................................4-30
I. Compiling the FPGA VI .......................................................................................4-31
J. Downloading to Flash Memory ............................................................................4-36
Exercise 4-2 Compile and Test an FPGA VI ........................................................4-40
Lesson 5
mp
Real-Time Controller
A. Introduction...........................................................................................................5-2
B. The LabVIEW Real-Time Application Development Course..............................5-3
C. Deterministic Operating Systems .........................................................................5-5
D. Timing Methods....................................................................................................5-7
E. Developing an RT Host VI ...................................................................................5-9
F. Rebooting the CompactRIO RT Controller ..........................................................5-20
Exercise 5-1 Build and Test a Simple RT Host VI................................................5-21
G. Reusing Code in Multiple Targets ........................................................................5-27
Exercise 5-2
Reuse LabVIEW Example Code to Monitor Chassis Temperature .........................5-30
H. Converting Binary Representations ......................................................................5-36
Exercise 5-3 Convert Binary Representation to Engineering Units ......................5-41
Sa
Lesson 6
Windows PC Host
A. Overview...............................................................................................................6-2
B. Network-Shared Variable Communications .........................................................6-3
Exercise 6-1 Build and Test a Simple Windows Host VI .....................................6-8
Lesson 7
Data Transfer and Synchronization
A. Race Conditions ....................................................................................................7-2
B. Buffering and Synchronization .............................................................................7-7
C. FPGA FIFOs .........................................................................................................7-8
D. Handshaking .........................................................................................................7-19
E. Interrupts ...............................................................................................................7-21
Exercise 7-1 Interrupt FPGA VI............................................................................7-25
le
Exercise 7-6 PID Control RT Host VI...................................................................7-78
Exercise 7-7
Build and Test a Networked Fan Speed Control Application (Optional) ................7-88
Lesson 8
FPGA Wizard (Optional)
A. Generated Core Code for the FPGA VI................................................................8-2
B. Generated Core Code for the Host VI ..................................................................8-2
Appendix A
mp
C. Timing Engines.....................................................................................................8-3
D. Using the Wizard ..................................................................................................8-12
Exercise 8-1
Exercise 8-2
Build an Application with the FPGA Wizard...................................8-19
Modify Code Generated by the FPGA Wizard ................................8-25
Course Evaluation
Sa
le
also include I/O modules and channels. They might have special libraries for
variables to communicate over the internet. This lesson teaches you how to
use the LabVIEW Project Explorer to design and implement an architecture
for CompactRIO applications that organizes these items in a logical and
efficient manner.
Topics
mp A. Create a Project
B. Add the CompactRIO Target
C. Add I/O Modules
D. Add FPGA I/O Items
Sa
© National Instruments Corporation 3-1 CompactRIO and LabVIEW Fundamentals Course Manual
Lesson 3 Implementing Application Architecture
A. Create a Project
le
To create a CompactRIO project, open LabVIEW and select an Empty
Project, as shown in Figure 3-1. Save the project in an appropriate location
on the host computer. The project root name changes to the title of the file.
mp
Sa
An example CompactRIO project is shown in Figure 3-2. The top line is the
project root. The label on the project root includes the filename for the
project. Right-click the project root and select New»Targets and Devices
to add an RT target, such as CompactRIO, to the project. Notice that the
Windows PC computer, shown as My Computer, and the RT targets you add
to the project are located below the project root and are indented to show
their position in the architecture hierarchy.
le
Windows PC CompactRIO System Reconfigurable
FPGA
Windows Network Normal Inter-Thread Time-Critical FPGA LabVIEW
Host VI Communication Priority VI Communication Interface VI Interface FPGA VI
mp LabVIEW
for Windows
Each project can have multiple targets, representing the host computer as
well as real-time, FPGA, and PDA systems. In this course you have three
LabVIEW
FPGA
© National Instruments Corporation 3-3 CompactRIO and LabVIEW Fundamentals Course Manual
Lesson 3 Implementing Application Architecture
item. Place any VIs that run on the RT controller under the CompactRIO
target, and place the FPGA VI under the FPGA target.
le
Enterprise Data Storage
le
mp Figure 3-4. Adding a New Target in the Project Explorer
The targets and devices that are available depend on the target you select.
For example, if you select My Computer, the Add Targets and Devices
dialog box lists only targets and devices that are available on the local
computer. If you select another target it lists targets and devices that are
available for the target you selected. If you select the project root, you can
add top-level targets that are not contained by other targets, such as My
Computer.
The Add Targets and Devices dialog box shown in Figure 3-5 includes the
following components:
• Targets and Devices—Specifies the type of target or device you want
to add to the project.
– Existing target or device—Displays all targets and devices on the
Sa
local subnet.
– Existing device on remote subnet—Displays device types that a
remote subnet supports. Select a device from the list and enter an IP
address for the device to add the device to the project.
– New target or device—Displays targets and devices that you can
create without a physical target or device present. This option allows
you to develop a project without CompactRIO hardware connected
to the Host PC.
© National Instruments Corporation 3-5 CompactRIO and LabVIEW Fundamentals Course Manual
Lesson 3 Implementing Application Architecture
le
mp
Figure 3-5. Existing Targets in the Add Targets Dialog Box
le
mp Figure 3-6. Add I/O Modules to the Project
© National Instruments Corporation 3-7 CompactRIO and LabVIEW Fundamentals Course Manual
Lesson 3 Implementing Application Architecture
2. Expand the C Series Module directory in the Add Targets and Devices
on FPGA Target dialog box.
3. Click Continue in the Warning dialog box shown in Figure 3-8.
le
Figure 3-8. Discovering C Series Modules Warning Dialog Box
Figure 3-9. Add Targets and Devices on FPGA Target Dialog Box
5. After selecting the modules, click OK, and save the project. The
modules are displayed in the Project Explorer window similar to
Figure 3-10.
le
mp Figure 3-10. Project Explorer with C Series Modules
© National Instruments Corporation 3-9 CompactRIO and LabVIEW Fundamentals Course Manual
Lesson 3 Implementing Application Architecture
le
mp
Figure 3-11. Module Properties Dialog Box
le
mp
Figure 3-12. LabVIEW Help Display of NI 9211 Module Available Channels
© National Instruments Corporation 3-11 CompactRIO and LabVIEW Fundamentals Course Manual
Lesson 3 Implementing Application Architecture
le
mp Figure 3-14. New FPGA I/O Dialog Box
Use the FPGA dialog box to specify the I/O resources you want to use in the
Project Explorer window and to edit the names of the I/O items you select.
This dialog box includes the following components:
• Available Resources—Displays the I/O resources available for the
FPGA target. The FPGA target you right-click in the Project Explorer
window determines the I/O resources that appear in the Available
Resources tree.
• Add—Adds the I/O resources you select in the Available Resources tree
to the list of FPGA I/O items in the New FPGA I/O table.
Sa
• Remove—Removes the FPGA I/O items you select in the New FPGA
I/O table from the table. The FPGA I/O item returns to the Available
Resources tree.
• New FPGA I/O—Displays the I/O resources you add to the table from
the Available Resources tree. Each FPGA I/O item that appears in this
table appears in the Project Explorer window when you click the OK
button. Contains the following options:
– Name—Displays the name of the FPGA I/O item that appears in the
Project Explorer window. You can change the name of the FPGA I/O
item by typing in the Name column in the New FPGA I/O table, by
typing in the Name string control in the FPGA I/O Properties dialog
box, or by right-clicking the FPGA I/O item in the Project Explorer
window and selecting Rename.
le
You can select multiple resources by pressing the <Ctrl> key and clicking
additional resources. You also can select an entire group of I/O resources by
clicking the top-level I/O type or folder, if available.
After adding I/O items, save the project. An example project is shown in
Figure 3-15. Notice the project tree separates the I/O into Analog Input,
Digital Line Input, and Analog Output folders. The NI 9211 has Analog
Input for the Thermocouple, CJC, and Autozero. The NI 9233 has Analog
mp Input for Y Acceleration, X Acceleration, and Tachometer. It also has
Digital Line Outputs for Start and Stop.
Sa
© National Instruments Corporation 3-13 CompactRIO and LabVIEW Fundamentals Course Manual
Lesson 3 Implementing Application Architecture
You can reuse items among different FPGA targets in a Project Explorer
window. However, the new FPGA target might not support the same
functionality as the previous FPGA target, so you must update the item
properties to match the functionality and resources of the new FPGA target.
For example, if you copy an FPGA I/O item between two different FPGA
targets, you must verify the FPGA target to which you copied the FPGA I/O
item supports the same I/O resource to which the FPGA I/O item was
assigned in the first FPGA target.
le
mp
Sa
Scenario
le
Build a project for a condition monitoring application. The application
monitors the temperature, vibration, and speed of the fan. It also controls
fan speed. The project includes a Windows PC host, a CompactRIO RT
controller host, an FPGA target, and three I/O modules (NI 9211, NI 9233,
and NI 9263). The NI 9211 I/O items include a J-type thermocouple in
channel 0, an autozero channel, and a cold junction compensation (CJC)
channel. The NI 9233 I/O items include two channels for X- and Y-axis
acceleration and a third channel for a tachometer signal. The NI 9263 has
Design
mp one FPGA I/O item, AO0, for the fan speed control signal.
The NI 9211 module has three channels. Channel TC0 is the thermocouple
signal input. The CJC and Autozero channels retrieve data stored on the
NI 9211 for data conversion/scaling. The Autozero and CJC values convert
the thermocouple signal accurately from binary values to temperature units.
These channels are internal-only sensors on the NI 9211 and are not
physically visible or accessible on the module. The conversion normally
takes place in the RT host VI to conserve space on the FPGA and to use
Sa
floating-point math capabilities available on the controller. The conversion
is discussed in Lesson 5, Real-Time Controller.
The NI 9233 has five channels. Channel AI0 is the Y-axis accelerometer
signal input. Channel AI1 is the X-axis accelerometer signal input. Channel
AI2 is the tachometer signal input. The digital line outputs are Start and
Stop.
The NI 9263 has one channel. Channel AO0 is the output signal for fan
speed control.
The NI 9211 module and channels are used in the first phase, and all of the
modules and channels are used in the second phase. You create a copy of this
project to use for the first phase.
© National Instruments Corporation 3-15 CompactRIO and LabVIEW Fundamentals Course Manual
Lesson 3 Implementing Application Architecture
Implementation
1. Connect power to the CompactRIO and connect the Ethernet crossover
cable between the CompactRIO and the PC.
In the following steps you build the project shown in Figure 3-16.
le
mp
Sa
Figure 3-16. Temperature Monitor Project
2. Create a project.
❑ Notice that the project contains the root and the My Computer item.
le
❑ Select the cRIO-9012 target.
❑ Click OK.
❑ Expand the C Series Module item in the Add Targets and Devices
on FPGA Target dialog box.
❑ Hold down the <Ctrl> key and select all three modules.
Note You do not need all three to monitor temperature, but you are building a project
that supports later exercises.
❑ Click OK.
Sa
❑ Save the project.
© National Instruments Corporation 3-17 CompactRIO and LabVIEW Fundamentals Course Manual
Lesson 3 Implementing Application Architecture
– Hold down the <Ctrl> key and select TC0, CJC, and Autozero.
Do not click Add. You select all the items first, and then add
them at the end.
le
– Hold down the <Ctrl> key and select AI0, AI1, and AI2.
❑ Add two digital output channels for starting and stopping the
NI 9233.
–
Expand the Analog Output item.
❑ Click the Add button to add all of the I/O channels as shown in
Figure 3-17.
Sa
le
mp ❑ Click OK.
Figure 3-17. Selected FPGA I/O Items
© National Instruments Corporation 3-19 CompactRIO and LabVIEW Fundamentals Course Manual
Sa
mp
le
Lesson 3 Implementing Application Architecture
le
d. RT controller
e. Windows PC
f. My Computer
2. My Computer and the RT controller are at the same level in the Project
Explorer window.
a. True
mp b. False
3. Which Targets and Devices option allows you to develop a project
without CompactRIO hardware connected to the PC?
a. Existing Target or Device
b. Existing device on remote subnet
c. New target or device
4. Under which target do I/O modules reside?
a. FPGA
b. PCI Bus
c. Windows PC
d. RT controller
Sa
© National Instruments Corporation 3-21 CompactRIO and LabVIEW Fundamentals Course Manual
Sa
mp
le
Lesson 3 Implementing Application Architecture
le
d. RT controller
e. Windows PC
f. My Computer
mp 2. My Computer and the RT controller are at the same level in the Project
Explorer window.
a. True
b. False
3. Which Targets and Devices option allows you to develop a project
without CompactRIO hardware connected to the PC?
a. Existing Target or Device
b. Existing device on remote subnet
c. New target or device
4. Under which target do I/O modules reside?
a. FPGA
b. PCI Bus
Sa
c. Windows PC
d. RT controller
© National Instruments Corporation 3-23 CompactRIO and LabVIEW Fundamentals Course Manual
Lesson 3 Implementing Application Architecture
Notes
le
mp
Sa