You are on page 1of 11

Document Type: Tutorial NI Supported: Yes Publish Date: Oct 29, 2007

CompactRIO Hands-On Tutorial- Basics I


Overview This hands-on session is designed as an introduction to the fundamentals of CompactRIO. Concepts include hardware setup and configuration, developing an FPGA VI for reading and writing I/O modules, and passing data to a real-time host processor. This session is an opportunity to work with the hardware and become familiar with how to successfully start developing CompactRIO applications. Download the LabVIEW Example Code for this Hands-on Tutorial

Table of Contents 1. 2. 3. 4. 5. 6. Hands-On Summary Demo Requirements Exercise 1: Developing the FPGA Application Exercise 2: Developing the Host Interface for CompactRIO Exercise 3: Reading and Converting the Actual Temperature Appendix-Hardware Setup and Software configuration

Hands-On Summary 1. Introduce the CompactRIO Product Line. 2. Learn how to setup and configure a CompactRIO system using the LabVIEW Embedded Project Manager. 3. Create an FPGA VI to read and write to CompactRIO I/O and implement digital control operations. 4. Create a Host VI to interface with the FPGA VI and implement scaling of binary data. Demo Requirements Hardware NI FPGA 7831R, cRIO-9151 Expansion and SH68-C68-S Cable OR Software LabVIEW Full Dev System for Windows (Eng) w/1 Yr Standard Service (776670-09) LabVIEW Reconfigurable I/O Software Development Kit (779149-03)

NI cRIO-900x and cRIO-910x Chassis NI cRIO-9211, 9263, 9411, 9474 (AI, AO, DI, DO) Temperature Chamber: Light, Fan and Thermocouple

Table 1. Software and Hardware Requirements Exercise 1: Developing the FPGA Application 1. Launch LabVIEW. 2. In the Getting Started screen for LabVIEW, select Empty Project under the New section. The Project Explorer window appears.

1/11

www.ni.com

Figure 1. Creating a New Project. 3. Select FileSave Project and enter cRIO Thermostat in the Name the Project text box after selecting the appropriate directory for the project. 4. In the Project Explorer window, Right-click on Project: cRIO Thermostat.lvproj and select NewTargets and Devices... The Add Targets and Devices window will appear.

Figure 2. Selecting a Target for the Project. 5. While Existing target or device is selected, select the appropriate type of device. PXI R Series Embedded Expansion System Select Real-Time PXI and then the appropriate system that is listed on the network. The target will show up in the project on the same hierarchy level as My Computer with the name <Target's Name> (IP Address), where <Target's Name> is the actual name of the device that is given to it and (IP Address) is the IP Address of the particular device. Right-click on the target's name and select NewTargets and Devices... The Add Targets and Devices window will appear.

2/11

www.ni.com

Figure 3. Selecting FPGA Target for PXI System. Select the + next to FPGA Target and the R Series board should appear.

Figure 4. Selecting R Series Board for PXI System. In the Project Explorer window, Right-click on the newly added FPGA Target and select NewR Series Expansion Chassis. Specify the Name of the chassis and the proper Location of the Connector to the R Series board for the chassis. Ensure that the Discover C Series Modules option is selected and select OK.

3/11

www.ni.com

Figure 5. Adding Expansion Chassis to Project. Ensure that all of the C Series Modules appear to be in the appropriate slots in the Project Explorer window when compared to the actual chassis. The Project Explorer window should be configured for the chassis.

Figure 6. R Series Expansion Chassis Configured in Project. CompactRIO Embedded System While the Add Targets or Devices window for adding to the project is open, select Real-Time CompactRIO and then the appropriate device listed on the network. After selecting OK, the C Series Modules will be detected and the CompactRIO should show up in the project on the same hierarchy level as My Computer.

4/11

www.ni.com

Figure 7. cRIO Chassis Configured in Project. Develop an FPGA VI 1. In the Project Explorer window, Right-click on the FPGA Target for your device and select NewVI. Reading the Temperature Build the FPGA thermostat application shown below in Figure 11. For detailed instructions, refer to the step by step instructions below: 1. Place a While Loop on the block diagram. Right-click the conditional terminal and select CreateControl from the shortcut menu. 2. Place an FPGA I/O Node in the While Loop. The FPGA I/O Node function is on the FPGA I/O palette.

Figure 8. FPGA I/O Palette.

3. Right-click the I/O node and select Show Error Terminals from the shortcut menu. 4. Right-click on the I/O node and select Select FPGA I/OMod1Mod1/TC0. 5. Expand the I/O node to show three I/O properties. 6. Make sure the second I/O property is Mod1/Autozero by Left-clicking on the second property and selecting Mod1Mod1/Autozero. 7. Make sure that the third I/O property is Mod1/CJC by Left-clicking on the third property and selecting Mod1Mod1/CJC. 8. The I/O node for the 9211 Module should now be configured.

5/11

www.ni.com

Figure 9. 9211 I/O Node Configured.

9. On the block diagram, Right-click the Mod1/TC0 terminal of the Analog Input function and select CreateIndicator from the shortcut menu. Repeat this for the CJC, and Autozero outputs as well. Label the indicators Actual Temperature, CJC, and Autozero respectively.

Figure 10. Reading Actual Temperature, Autozero, and CJC Values. About the CJC and the Autozero Channels To ensure accurate measurements, you must read the cold-junction compensation (CJC) and autozero channels for the CompactRIO thermocouple module. You will use the autozero and CJC data in the host VI to convert the data read from the thermocouple input channel from binary values to temperature.

Controlling the Temperature To control the temperature, the FPGA VI must compare a target temperature range to the actual temperature and then decide whether to turn on the fan or the heater. Build the FPGA thermostat application shown below in Figure 11. For detailed instructions, refer to the step by step instructions below: 1. Place two Numeric Controls on the front panel. Label the controls low target temperature and high target temperature. The low target temperature control is for the lower limit of the target temperature range and the high target temperature control is for the upper limit of the target temperature range. 2. As shown on Figure 11 below, place a Less? function and a Greater? function on the block diagram. 3. Wire the Mod1/TC0 output of the I/O node to the x inputs of the Less? and Greater? functions. 4. Wire the low target temperature control to the y input of the Less? function. Write the high target temperature control to the y input of the Greater? function. Right-click on each of the controls and select RepresentationI32. 5. Place an FPGA I/O Node function in the While Loop. 6. Right-click the I/O node and select Show Error Terminals from the shortcut menu. 7. Right-click the I/O node and select Select FPGA I/OMod4Mod4/DO0. 8. Expand the I/O node to show two I/O properties. 9. Make sure that the second property is Mod4/DO1 by Left-clicking on the second property and selecting Mod4Mod4/DO1. 10. Wire the x>y? output of the Greater? function to the Mod4/DO1 input of the Digital Output function. Wire the x<y? output of the Less? function to the Mod4/DO0 input of the Digital Output function. 13. Wire the Error Out output of the first I/O node to the Error In input of the second I/O node. 14. Create indicators from the Less? function and the Greater? function outputs. Label the indicators Fan On and Heater On, respectively. 15. Save the VI.

Figure 11. cRIO Thermostat FPGA VI.

You have finished developing the FPGA VI. You are ready to build and download the VI to the FPGA device.

Compiling and Running the FPGA VI 1. While the FPGA VI is open, click the Run button to compile the FPGA VI and have it start running. 2. When LabVIEW returns the Successful Compile Report dialog box, click the OK button. The VI is now running on the FPGA of your device. You can see the un-scaled integer data being displayed on the front panel of the FPGA application. Experiment by entering different target temperature limits on the front panel of the VI. If the heater turns on, LED 0 on the cRIO-9474 and the heater on indicator on the front panel of the VI turn on. If the fan turns on, LED 1 on the cRIO-9474 and the fan on indicator on the front panel of the VI turn on.

Exercise 2: Developing the Host Interface for CompactRIO

Use the host VI to communicate with the FPGA VI. You can run the host VI on a RT target or on a Windows PC. Complete the following steps to develop the host VI for the CompactRIO thermostat. Build the Host Interface application shown below in Figures 14 and 15. For detailed instructions, refer to the step by step instructions below: R Series Expansion System 1. In the Project Explorer window, Right-click on the PXI target and select NewVI.

6/11

www.ni.com

Reconfigurable Embedded System 1. In the Project Explorer window, Right-click on the cRIO chassis RT controller and select NewVI.

R Series Expansion System or CompactRIO Reconfigurable Embedded System 1. Right-click on the block diagram and navigate to the All FunctionsFPGA Interface palette. Place the Open FPGA VI Reference function on the block diagram. Use this function to open a reference to the VI you downloaded to the FPGA device.

Figure 12. FPGA Interface Palette. 2. Right-click the function and select Select VI... from the shortcut menu. The Select Target VI dialog box appears. Browse to the cRIO thermostat (FPGA) VI and click the OK button.

Figure 13. Selecting FPGA VI to use in RT Host VI.

3. Right-click the Open FPGA VI Reference function and select Show Resource Input. Right-click this input and select CreateControl. 4. Place a While Loop on the block diagram to the right of the Open FPGA VI Reference function. If necessary, right-click the conditional terminal and select CreateControl from the shortcut menu. 5. Place the Close FPGA VI Reference function outside of the While Loop. 6. Place the Read/Write Control function inside the While Loop. 7. Wire the FPGA VI Reference Out and Error out outputs of the Open FPGA VI Reference function to the FPGA VI Reference In and Error in inputs of the Read/Write Control function. 8. Left-click the Unselected output of the Read/Write Control function and select Actual Temperature from the shortcut menu. This terminal corresponds to the actual temperature indicator you created in the FPGA VI. 9. Expand the Read/Write Control to show three separate controls. 10. Left-click the two remaining Unselected controls so they appear as Mod1/CJC and Mod1/Autozero, respectively. 11. Right-click each output and select the option to CreateIndicator.

Figure 14. cRIO Thermostat Read.

12. Place another Read/Write Control function. Wire the FPGA VI Reference Out output of the first Read/Write Control function to the FPGA VI Reference In input of the second Read/Write

7/11

www.ni.com

Control function. 13. Left-click the Unselected output and select low target temperature from the shortcut menu. 14. Expand the Read/Write Control to show four read/write properties. Left-click each property and select high target temperature, Fan On, and Heater On, respectively. 15. Right-click the Fan On and Heater On outputs and select CreateIndicator. 16. Navigate to the All FunctionsCluster palette. Insert a Bundle Function from the Cluster palette. Resize the bundle to contain 3 inputs. 17. Wire the Actual Temperature, CJC, and Autozero to the Bundle function. 18. Right-click the output of the Bundle function and select the option CreateIndicator. Label the indicator as Chart. 19. Wire the error in and error out clusters. 20. Double-click the Chart indicator to switch to the Front Panel. Right-click the indicator and select the option ReplaceGraphWaveform Chart. 21. In the VISA Resource Name Control, click the pull-down and select the appropriate RIO device. 22. On the block diagram, navigate to the All FunctionsTime & Dialog palette. Place the Wait Until Next ms Multiple function on the block diagram. Right-click on the input terminal to create a constant. Set the value to 200. 23. Wire the error cluster as shown below by using the Unbundle by Name function from the Cluster palette, and the Or function from the Boolean palette. 24. Save the VI as cRIO thermostat (Host).vi. Run the VI.

Figure 15.cRIO Thermostat Read and Write.

The CompactRIO thermostat (Host) VI is now complete. Try changing the low and high target temperature settings and observe the result. Exercise 3: Reading and Converting the Actual Temperature

Use the host VI to convert the CompactRIO data from the FPGA VI from un-scaled integer (binary) values to meaningful engineering units in the host VI. Build the scaled unit host interface application shown below in Figure 18. For detailed instructions, refer to the step by step instructions below: 1. Select Select a VI from the Functions palette. The Select VI to Open dialog box appears. 2. Browse to Program Files\National Instruments\LabVIEW 8.5\examples\CompactRIO\Module Specific\NI 9211 and select NI 9211 Support Files.llb. The File Dialog dialog box appears. 3. Select Convert to Temperature (NI 9211).vi and click the OK button. 4. Delete the indicators connected to the Actual Temperature, CJC, and Autozero outputs of the Read/Write Control function. 4. Wire the Actual Temperature output of the Read/Write Control function to the Thermocouple Channel input of the Convert to Temperature (NI 9211) VI. 5. Wire the CJC output of the Read/Write Control function to the CJC Channel input of the Convert to Temperature (NI 9211) VI. 6. Wire the Autozero output of the Read/Write Control function to the Autozero Channel input of the Convert to Temperature (NI 9211) VI. 7. Create constants for the Temperature Units and Thermocouple Type inputs of the Convert to Temperature (NI 9211) VI. 8. Right-click the Linearized Temperature output of the Convert to Temperature (NI 9211) VI and select CreateIndicator from the shortcut menu. Rename the indicator Actual Temperature.

Figure 16. Reading and Converting the Actual Temperature

Converting and Writing the Target Temperature Range You must write binary values to CompactRIO output modules. If you want to enter the value to output in engineering units, you must convert the value to a binary value before the host VI writes the target temperature range to the FPGA VI. 1. Select Select a VI from the Functions palette. The Choose VI to Open dialog box appears. 2. Browse to Program Files\National Instruments\LabVIEW 8.5\examples\CompactRIO\Module Specific\NI 9211 and select NI 9211 Support Files.llb. The File Dialog dialog box appears. 3. Select Convert to Binary (NI 9211).vi and click the OK button.

8/11

www.ni.com

4. Place another Convert to Binary (NI 9211) VI on the block diagram. 5. Connect the Low Target Temperature control to the Linearized Temperature input of one of the Convert to Binary (NI 9211) VIs. Right-click on the control and select RepresentationDouble Precision. 6. Connect the High Target Temperature control to the Linearized Temperature input of the other Convert to Binary (NI 9211) VI. Right-click on the control and select RepresentationDouble Precision. 7. Wire the CJC and the autozero outputs of the Read/Write Control function to the CJC Channel and Autozero Channel inputs of the Convert to Binary (NI 9211) VIs. 8. Wire the Thermocouple Type and the Temperature Channel constants to their respective inputs of the Convert to Binary (NI 9211) VIs.

Figure 17. Scaling Temperature

9. Wire the Thermocouple Channel (Binary) output of the first Convert to Binary (NI 9211) VI to the low target temperature input of the Read/Write Control function. 10. Wire the Thermocouple Channel (Binary) output of the second Convert to Binary (NI 9211) VI to the high target temperature input of the Read/Write Control function. 11. Wire the FPGA VI Reference Out output of the second Read/Write Control function to the FPGA VI Reference In input of the Close FPGA VI Reference function. 12. Rewire the input to the Bundle function to include the scaled Actual Temperature output from the Convert to Temperature (NI 9211).vi

Reading Errors from the FPGA VI 1. Expand either Read/Write Control to show another element. 2. Left-click the Unselected output and select Error OutAll Elements. 3. Right-click the Error Out output of the Read/Write Control function and select CreateIndicator from the shortcut menu. 4. Run the VI.

Figure 18. CompactRIO Thermostat Host VI with Binary Conversion You have finished developing your CompactRIO thermostat. Enter different target temperature ranges and see how the cRIO-9474 LED and the indicators on the front panel react. While the FPGA VI handles the I/O and the logic, you can use the host VI to view the current temperature and set the target temperature range. Appendix-Hardware Setup and Software configuration

Hardware Setup CompactRIO R Series Expansion System 1. Connect the cRIO-9151 Expansion chassis to the FPGA 7831\7811R device via the SH68-C68-S digital cable. Connect the cable to an available digital port on the 7831\7811R. IMPORTANT: To avoid communication issues with the CompactRIO expansion chassis, be sure NOT to use an analog MIO cable such as the SHC68-68-RMIO cable with the CompactRIO Expansion System. 2. Afterwards, examine the CompactRIO modules and installed them into the chassis according to the following layout: Slot 1: cRIO-9211 4-Channel Thermocouple Input Module Slot 2: cRIO-9263 4-Channel Analog Output Module Slot 3: cRIO-9411 6-Channel Digital Input Module Slot 4: cRIO-9474 8-Channel Digital Output Module

9/11

www.ni.com

Figure 1. CompactRIO Expansion System CompactRIO Reconfigurable Embedded System 1. Make sure the system is powered down. Then install the cRIO-9002 Embedded Real-Time controller onto the controller slot of the cRIO-9101\9103 Reconfigurable chassis. 2. Afterwards, examine the CompactRIO modules and install them into the chassis according to the following layout: Slot 1: cRIO-9215 4-Channel Analog Input Module Slot 2: cRIO-9263 4-Channel Analog Output Module Slot 3: cRIO-9411 6-Channel Digital Input Module Slot 4: cRIO-9474 8-Channel Digital Output Module 3. Power the Controller by connecting an 11-30 Volt DC supply to the appropriate terminals. 4. Connect the controller directly to the Host PC\PXI Chassis via a crossover Ethernet cable or through a LAN setup with a standard Ethernet cable.

Figure 2. CompactRIO Embedded System

Software Configuration of CompactRIO 1. Launch Measurement and Automation eXplorer (MAX)

CompactRIO Embedded System 2. Expand Remote Systems to view available Real-Time controllers. You should see the CompactRIO embedded system listed as a target. Configure the Network Settings if needed and install any necessary Software. The entry in MAX should appear as follows:

CompactRIO Expansion System 2. Expand Devices and Interfaces under My System to view available Reconfigurable I/O devices. You should see the PXI/PCI-78xxR board listed as a device. 3. Verify the Software on your system is installed as follows:

10/11

www.ni.com

Legal This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE ( http://ni.com/legal/termsofuse/unitedstates/us/).

11/11

www.ni.com

You might also like