Part 1: Generating Data on the RT Target

The real-time operating system on your RT target allows you to specify processes to run deterministically. A deterministic process has preferential access to hardware resources, meaning it executes within a bound time frame without risk of being interrupted by lower priority processes. In this tutorial, we use a Timed Loop to specify a deterministic process that generates data on the RT target. In a producer/consumer design, we refer to this loop as the producer loop because it generates data for another loop to process. We discuss the consumer loop in the next part of this tutorial. Visit ni.com/info and enter PCdesign to learn about producer/consumer designs.

Setting up Your LabVIEW Project

Before you start designing your application, you need to add your RT target to a LabVIEW project, and then add a VI to run on your RT target. A VI runs on the hardware you add it to within the LabVIEW project hierarchy. If you add a VI to My Computer, it runs on the host computer. If you add a VI to the RT target project item, it runs on the RT target.

Complete the following steps to create your LabVIEW project:

  1. In the LabVIEW Getting Started window, select File»Create Project to display the Create Project dialog box.
  2. Select Blank Project and click Finish.
  3. Select File»Save to save the project.
  4. Name the project Getting Started.
  5. Click OK.

Complete the following steps to discover your RT target:

  1. In the Project Explorer window, right-click the project root and select New»Targets and Devices from the short-cut menu to display the Add Targets and Devices dialog box.
  2. Select Existing target or device.
  3. Select Discover an existing target(s) or device(s).
  4. Specify the type of RT target you have in the Targets and Device Types list box. For example, if your RT target is a cRIO-9033, expand the Real-Time CompactRIO folder and select cRIO-9033.
  5. Click OK to display the Select Programming Mode dialog box.
  6. (FPGA Targets) Select Scan Interface.
    Note   You can select LabVIEW FPGA Interface instead of Scan Interface to program the FPGA for maximum performance and flexibility.
  7. Click Continue.

Complete the following steps to add a new VI to your project:

  1. Right-click the RT target in the Project Explorer window and select New»VI.
  2. On the front panel, select File»Save to save the VI.
  3. Name the VI Real-Time Main.
  4. Click OK.

Creating a Timed Loop

The real-time operating system assigns priorities to every process in LabVIEW. Background tasks receive the lowest priority. LabVIEW processes receive low, normal, or high priority. VIs set to time-critical priority receive the highest priority. Timed Loops are deterministic structures that execute above high priority but below time-critical priority. When you add a Timed Loop to a VI, you must specify a period and priority for the loop. The period is the allotted execution time for one iteration of the loop. The priority tells LabVIEW which loop to execute first when there are multiple loops in the VI.

Note   To avoid undermining the determinism of a Timed Loop, set all other loops to normal priority and exercise caution when using more than one Timed Loop in an application.

Complete the following steps to configure a Timed Loop in the RT target VI:

  1. Add a Timed Loop to the block diagram of Real-Time Main.vi using the Functions palette under Programming»Structures»Timed Structures.
  2. Double-click the Input node of the Timed Loop to display the Configure Timed Loop dialog box.
  3. Select 1 kHz Clock from the Source Type list box.
  4. Enter 250 in the Period text box so that the loop runs four times per second.
    Note   The period that you set should provide adequate time for the code within the Timed Loop to execute. Additionally, the period should allow extra time for lower priority processes to execute in order to prevent CPU starvation.
  5. Enter 100 in the Priority text box.
  6. Click OK.
  7. Right-click the Loop Condition terminal of the Timed Loop and select Create Control from the short-cut menu. LabVIEW adds a Stop button to the front panel.

Adding Code to Generate Data

In this section, you use a Random Number function to generate data on the RT target. The Random Number function is a placeholder for application-specific code. For real-world applications, replace the Random Number function with code that generates data you want to process deterministically.

Complete the following steps to generate and display data:

  1. Add a Random Number function inside the Timed Loop.
  2. Right-click the Random Number function and select Create»Indicator from the short-cut menu.
    Note   As a best practice, do not include indicators inside time-critical code. It is important to generate data deterministically, but it is not important to display data deterministically. The indicator in this step is for testing that the RT target generates data. You remove it in a later part of this tutorial.
  3. Save the VI.

The block diagram should match the following image.

Running a VI on Your RT Target

Before you can start running the code, you must enable the VI to run on the RT target by deploying it. When you deploy the VI, LabVIEW saves the VI and any associated files to the RT target memory.

Complete the following steps to deploy the VI to your RT target:

  1. In the Project Explorer window, right-click the RT target and select Properties from the short-cut menu to display the RT Target Properties dialog box.
  2. Specify the IP address in the IP Address / DNS Name text box.
    Note You can use Measurement & Automation Explorer (MAX) to determine the IP address for your RT target.
  3. Click OK.
  4. In the Project Explorer window, right-click the VI and select Deploy from the short-cut menu.

Result

When you run Real-Time Main.vi, the RT target deterministically produces random numbers, and the indicator displays the numbers on the front panel.