LabVIEW FPGA and CompactRIO Getting Started Tutorial

  • View
    30

  • Download
    1

Embed Size (px)

Transcript

LabVIEW FPGA and CompactRIO Getting Started Tutorial

This hands-on session is an introduction to basic concepts and methods of setting up an NI CompactRIO system and programming with NI LabVIEW FPGA version 8.2 and higher. You will configure your CompactRIO system, create a new LabVIEW Project, and create a LabVIEW FPGA application from scratch that introduces basic programming concepts and basic features. In the field programmable gate array (FPGA) application, you will perform analog I/O and design custom trigger logic to control a digital output. Hands-On Summary Introduce CompactRIO, LabVIEW Real Time, and LabVIEW FPGA Learn how to setup and configure a CompactRIO system using the Measurement & Automation Explorer (MAX) Create a LabVIEW Project to manage your FPGA, real-time processor and Windows host application code Use shared variable Ethernet networking technology to easily communicate with your CompactRIO system Create and compile an FPGA application to perform I/O and implement a custom trigger

For more information on LabVIEW FPGA and CompactRIO, visit these pages: http://www.ni.com/fpga http://www.ni.com/compactrio

LabVIEW FPGA and CompactRIO Getting Started Tutorial

Page 1 of 30

Table of ContentsRecommended Hardware and Software.................................................................................................................................................................3 Using the Target Control Application to Turn on Power to the System..............................................................................................................4 Creating a New LabVIEW Project and Adding I/O..............................................................................................................................................5 Developing the LabVIEW FPGA Application .....................................................................................................................................................17 Compiling the FPGA Application .........................................................................................................................................................................26 Running the LabVIEW FPGA Application .........................................................................................................................................................29

LabVIEW FPGA and CompactRIO Getting Started Tutorial

Page 2 of 30

Recommended Hardware and SoftwareSoftware

LabVIEW 8.2 Developer Suite Core Real-Time and FPGA Deployment Option for NI Developer Suite NI-RIO Version 2.1 (or later) for R Series and CompactRIO Embedded Targets

Hardware

Or

NI cRIO-9004 Real-Time Controller with 64 MB DRAM, 512 MB CompactFlash NI cRIO-9104 8-Slot, 3 M Gate CompactRIO Reconfigurable Embedded Chassis NI 9215 4-Channel, 100 kS/s, 16-bit, 10 V Simultaneous Sampling Analog Input Module (Install in Slot 1) NI 9263 4-Channel, 100 kS/s, 16-bit, 10 V, Analog Output Module (Install in Slot 2) NI 9401 8-Channel, 5 V/TTL High-Speed Bidirectional Digital I/O Module (Install in Slot 6)

NI cRIO-9004 Real-Time Controller with 64 MB DRAM, 512 MB CompactFlash NI cRIO-9103 4-Slot, 3 M Gate CompactRIO Reconfigurable Embedded Chassis NI 9215 4-Channel, 100 kS/s, 16-bit, 10 V Simultaneous Sampling Analog Input Module (Install in Slot 1) NI 9263 4-Channel, 100 kS/s, 16-bit, 10 V, Analog Output Module (Install in Slot 2) NI 9474 8-Channel 5 to 30 V, 1 s, Sourcing Digital Output Module (Install in Slot 4)

For help configuring your CompactRIO system and selecting accessories, use the CompactRIO Advisor. Hardware Setup Wire analog output channel 0 and COM from the cRIO-9263 in slot 2 to the AI0+ and AI0- terminals of the cRIO-9215 in slot 1 respectively (terminal 0 to terminal 0, terminal 1 to terminal 1).

See Also:Learn more about the NI CompactRIO reconfigurable embedded control and acquisition system Learn more about LabVIEW FPGA software

LabVIEW FPGA and CompactRIO Getting Started Tutorial

Page 3 of 30

Using the Target Control Application to Turn on Power to the SystemFollow the instructions below to make sure your National Instruments CompactRIO and CompactDAQ systems are powered up.

) on the desktop. To verify that system power is turned on, confirm that the green 1. Double click the Target Control icon ( light is on. If the light is not on, click on the Power Control button.

LabVIEW FPGA and CompactRIO Getting Started Tutorial

Page 4 of 30

Creating a New LabVIEW Project and Adding I/OIn this section you will learn the following:

How to configure a CompactRIO embedded application in the LabVIEW Project Explorer Auto-detection of the C Series I/O modules How to develop, target, download, and run an application on the reconfigurable FPGA

1. Launch NI LabVIEW by clicking on the desktop icon. Then click on the Real-Time Project link to start a new LabVIEW project for your NI CompactRIO system.

LabVIEW 8.20 has a Real-Time Project Wizard that makes creating and configuring real-time applications easy. To help you get started, the wizard enables you to choose an appropriate programming architecture and automatically generates a software template application.

2. To select the working folder for your project, click the folder ( ) icon, navigate to H:\VirtuaLab\CompactRIO and LabVIEW FPGA Getting Started Tutorial\Exercises, and then click the Current Folder button. Name your project Custom Trigger. Keep all of the project defaults as shown below and click the Next button.

LabVIEW FPGA and CompactRIO Getting Started Tutorial

Page 5 of 30

3. Change your Target Configuration to Two loops. Under the Host Configuration section, check the Include user interface box. Then click Next.

The LabVIEW 8.20 Real-Time Project Wizard makes it easy to create a complete CompactRIO embedded system that includes an FPGA application, real-time processor application, and networked Windows host computer application. After this exercise is complete, you could use the template applications created by the wizard to create a complete networked system, including a deterministic loop running on the real-time controller to communicate with the FPGA and a lower-priority loop to performed network communication, file logging, or additional analysis.

LabVIEW FPGA and CompactRIO Getting Started Tutorial

Page 6 of 30

4. Click the Browse button to find the networked target you configured in MAX. Expand Real-Time CompactRIO folder and wait until your CompactRIO system is detected. Highlight your CompactRIO system and click OK. Then click Next to continue creating the real-time project.

5. Notice that the project wizard displays a preview of the project you configured. Click Finish to finalize the creation of the new real-time project and generate the application template code.

LabVIEW FPGA and CompactRIO Getting Started Tutorial

Page 7 of 30

When code generation is complete, two pre-built template applications will automatically open. The Windows host application (host - network - RT (separate).vi) includes a chart to plot the data sent by the CompactRIO system over the network, and a stop network shared variable that is used to halt execution of the real-time embedded application running on the CompactRIO system.

LabVIEW FPGA and CompactRIO Getting Started Tutorial

Page 8 of 30

6. In the target - multi rate - variables.vi real-time processor application, navigate to Window>>Show Block Diagram.

LabVIEW FPGA and CompactRIO Getting Started Tutorial

Page 9 of 30

This embedded processor application produces a simulated I/O signal and sends the data to the Windows host computer using network-published shared variables. You would place any time critical routines, such as code to interface with your FPGA application within the top deterministic loop. Any lower priority non-deterministic tasks such as data logging or additional analysis would be placed in the bottom lower priority loop.

7. Click the Run button ( ) on the real-time processor application (target - multi rate - variables.vi). While the embedded application is being deployed, click the box next to Close on successful completion if it is not already checked.

LabVIEW FPGA and CompactRIO Getting Started Tutorial

Page 10 of 30

) on the Windows host application (host - network - RT (separate).vi). View the sinusoidal waveform 8. Click the Run button ( displayed on host application chart. Click the STOP button on the host application and notice that the application stops running on both the host and real-time target.

As you can see, the shared variable networking technology introduced with LabVIEW 8 makes it very easy to communicate with your CompactRIO system over Ethernet. In this case, you are using the default NI Publish-Subscribe Protocol (NI-PSP). In addition to NI-PSP, CompactRIO natively supports a wide array of additional networking protocols such as Modbus Serial and Modbus Ethernet. You can also communicate with your CompactRIO system using TCP/IP, UDP, SMTP Email, CAN, RS-232 and more. To learn more, see the Using the LabVIEW Shared Variable Tutorial.

LabVIEW FPGA and CompactRIO Getting Started Tutorial

Page 11 of 30

With the LabVIEW Datalogging and Supervisory Control Module, it's easy to log the shared variable data from your CompactRIO system to a historical database and build high-channel count distributed I/O systems consisting of multiple CompactRIO, Compact FieldPoint and third-party PLC devices. The LabVIEW DSC Module includes tools for viewing real-time and historical data, configuring alarms and events, setting up securit