Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Document Type: Tutorial
NI Supported: Yes
Publish Date: Sep 29, 2008


Feedback


Yes No

Related Categories

Related Links - Developer Zone

Related Links - Products and Services

Exercise 1: Create and Debug a Real-Time Project and Application

3 ratings | 3.67 out of 5
Read in | Print | PDF

Overview

This is a LabVIEW Real-Time tutorial designed for the LabVIEW Online Evalutation Environment. The tutorial covers creating a real-time application, as well as using the Execution Trace Toolkit to debug an application. Because the tutorial is designed for the online environment, it doesn't depend on any hardware.

LabVIEW Real-Time Online Evaluation Tutorial:

Creating and debugging a LabVIEW Real-Time application

National Instruments real-time products combine the NI LabVIEW graphical development environment with the deterministic performance of dedicated real-time and FPGA targets to deliver applications that run predictably, deliver increased reliability, and offer stand-alone operation.

As shown in the diagram below, LabVIEW Real-Time along with LabVIEW FPGA are modules that add functionality to a LabVIEW Development System. Hardware targets that support LabVIEW Real-Time include the following: NI Compact Vision System, NI Compact FieldPoint, NI CompactRIO, PXI Real-Time targets, and Standard Desktop PCs.

The test drive you are about to complete will walk you through the LabVIEW Real-Time environment, and cover the following key concepts:  

  • Creating a LabVIEW Real-Time Project with the Real-Time Project Wizard
  • Debugging an Application with the LabVIEW Execution Trace Toolkit
  • More Information: Available Functions and Shipping Examples

Creating a LabVIEW Real-Time Project

Launch the Real-Time Project Wizard

From the LabVIEW 8.6 start screen, select Real-Time Project. This allows you to configure a project by choosing a proven architecture, in addition to the hardware configuration of your particular system.

TIP:  Although this test drive describes how to create a new Real-Time project through the Real-Time Project Wizard, there are multiple ways to begin a LabVIEW Real-Time project. For example, one alternative would be to choose an Empty Project, and build your system from scratch.

 

Step 1: Select the Appropriate Real-Time Architecture for Your Application

One of the most common real-time architectures involves two systems: a real-time target where the main application is running, and a host PC that is communicating to the real-time target. This architecture will be implemented in our example.

 

 

Choose the following options to define our architecture:

  1. Select Continuous Communication Architecture
  2. Choose Application includes deterministic components
  3. Name the project (i.e. Example1).
  4. Click Next to Continue.

 

Step 2: Configure the Real-Time Architecture in More Detail

You have selected the Continuous Communication Architecture, which can be further configured in the following dialog.

  1. Select Two Loops.
  2. Choose to Include File I/O by selecting the checkbox.
  3. Click Next

 

TIP:  Dividing a LabVIEW Real-Time application into two-loops is a very common method of programming. This allows you to define one loop at a high priority, and reserve that loop for “time-critical” tasks such as a closed loop control algorithm. The other loop can handle tasks that are not time-critical, such as communication and File I/O.

 

Step 3: Configure Your Real-Time Hardware

Now that the architecture has been selected and configured, the wizard will prompt you to select your hardware.

1.    Choose Browse….

 

 

If we had hardware connected to our system, we could choose Existing target or device. However, for the purposes of this test drive we will only be configuring the software for later use.

 

2.    Choose New target or device, which allows for creating a project when the hardware is not available or connected at the time.

 

 

3.    Click OK, which will bring you back to the previous screen. Click Next to continue.

 

Step 4: Preview the Project

Your project has been configured. A preview is provided before the code framework is built for you.

Click Finish.

 

 

Step 5: View the Code Template

The Real-Time Project Wizard creates code based on the architecture defined.

1.    View the Project Explorer and notice our hardware is listed as the Real-Time target, and contains a file name target-multirate-fileIO.vi which is the Real-Time application.

 

 

2.    View the code that was created by selecting Window » Show Block Diagram.

 

 

3.    When the block diagram appears, view the code that was automatically created by the Real-Time Project Wizard. This provides a starting point that can be easily modified for a custom application.

 

 

Conclusion:  In a matter of minutes, we created a Real-Time application that could be executed on hardware.

 

Debugging a Real-Time Application with the Execution Trace Tool

 

Introduction to the Execution Trace Toolkit

 

The National Instruments LabVIEW Execution Trace Toolkit offers low-level visibility into applications running on LabVIEW Real-Time targets, such as NI PXI controllers, NI CompactRIO controllers, NI Compact FieldPoint controllers, NI Compact Vision Systems, and desktop PCs. Using this toolkit, you can view and analyze the execution trace of real-time tasks/threads including VI and operating system threads. With the information obtained from these traces you can debug and optimize your application by identifying and removing sources of jitter such as memory allocations, priority inversions, and race conditions.

 

The LabVIEW Execution Trace Toolkit offers a set of flexible and easy-to-use functions (VIs) to plot and trace the execution of your real-time tasks. Once the trace session is captured, you can use interactive tools to take measurements that can help you track jitter and provide you with information on how consistently your application is executing.

 

For example, you can use the different zooming tools to view precise microsecond characteristics of the execution of your application. You can then use cursors to measure execution times of VIs and threads. In addition to controlling your trace session with the aforementioned functions, you can also use tools such as flags to denote a variety of low level execution behaviors such as:

 

·         Sleeping of high priority threads so lower level tasks can execute

·         Waiting on execution of other tasks, which can expose jitter sources such as resource contention

·         Threads accessing the memory manager

·         User-defined events for monitoring system execution

 

 

The LabVIEW Execution Trace Toolkit is integrated into LabVIEW and can be accessed by selecting All Functions » Execution Trace Tool palette. When you install the toolkit, the Execution Trace Toolkit palette and corresponding VIs are placed in your Functions Palette on the Block Diagram.

 

The LabVIEW Execution Trace Tool is a great way to debug your Real-Time application.  While it should be used for development it should not be used in deployed applications.

 

Priority of Real-Time Tasks

This exercise will help provide a clearer understanding of priority in the LabVIEW Real Time application. You will run a program that consists of six sub-VI’s with different priorities and view how the processor allocates resources using traces generated by LabVIEW Execution Trace Toolkit VIs.

 

1.    Open the LabVIEW Example Finder by clicking on Help » Find Examples

 

 

2.    Browse according to Task to: Toolkits and Modules » Execution Trace Tool » Priorities.lvproj.  Double-click Priorities.lvproj to open the example project.

 

3.    The open project should look similar to the picture below.  Expand the RT Target and open Priorities.vi.

 

 

4.    Open the block diagram of Priorities.vi by typing <Ctrl+E> or by navigating to Window » Show Block Diagram.  The block diagram should be similar to the code shown below.

 

 

5.    The following are two example VIs from the palette included with the Execution Trace Tool, with the purpose of debugging an application in LabVIEW Real-Time. These are added to the LabVIEW block diagram in order to record information about the tasks running on the Real-Time target.

 

The TraceTool Start Trace.vi loads a trace session file and sends the trace session to the LabVIEW Execution Trace Tool running on the host.

 

The TraceTool Stop Trace and Send.vi stops logging data from the application running on the real-time target and sends the trace session to the LabVIEW Execution Trace Tool running on the host computer.

 

These two VI’s are required to initiate and transfer an Execution Trace log on an RT controller. If we were running the Real Time code in this example on real hardware, these two VI’s would monitor the threads and OS usage of the system, and transfer results back to a host PC.  

 

6.    Next, take a closer look at the code being executed between the start trace and stop trace sub-VI’s.  Notice that Priorites.vi calls six sub-VI’s each with increasing priority levels.  Each sub-VI contains code to cause it to execute for a fixed amount of time.  In this case, each VI executes for 10 ms.

7.    Use the Execution Trace Toolkit to characterize how this code is executed on a controller.  Launch the Execution Trace Toolkit by going to Tools » LabVIEW Execution Trace Tool

 

 

8.    The LabVIEW Execution Trace Toolkit will show the execution of the VI so we can visualize the preemption of the sub-VIs.

9.    In practice, you would first run the VI you wish to analyze by switching to the front panel of the Priorities demo VI and entering the IP address of the host computer. This would tell the VI where to send the trace session when it has finished executing. For this demonstration, the log file has already been created for you, so there is no need to run the VI.

10.  Within the Execution Trace Tool, open the pre-existing trace log file for the Priorites.vi.  The log can be opened by navigating to Help » Open Example Sessions.  In the dialog box that appears, select Priorities.log.

11.  You should have the example trace open now.  The trace window should look similar to the one below:

 

 

12.  View the trace session. You may need to resize the window to display the relevant data.  You can zoom in and out of the trace by typing <Ctrl>++ or <Ctrl>+- respectively.

13.  The top view shows the thread execution. Each priority level has its own execution system with potentially multiple threads.  At the bottom of the trace tool is a time scale.

14.  The bars represent the execution of the thread where the loop code is executing.

15.  You can use the zoom tool to get a better view of the execution.

 

 

16.  Zoom in on approximately the first 60 ms of execution time.

 

 

17.  Investigate the execution system and priorities of each sub-VI priority level:

  • Notice that sub-Vis with Normal or Background priorities execute in the Standard: Normal #0 thread.  This thread is repeatedly interrupted by the OS Timer Thread, the Enet Receive Thread, and other background processes.
  • Notice the sub-VI with Above Normal priority executes in the Standard: Above Normal #1 thread.  This thread is interrupted less often by other background processes.
  • The sub-VI with High priority executes in the Standard: High #0 thread.  This thread is higher priority than the previous threads, and thus usually has fewer interruptions.
  • The Time-Critical sub-VI executes in the Standard: Time Critical #0 thread.  Because this is a very high priority, none of the background processes executing on this system could interrupt the time-critical thread. 
  • Finally, the Sub-Routine priority thread is executed.  Because this is another lower priority sub-VI, it is executed in the Standard: Normal #0 thread, where it is interrupted by background system processes.

 

Conclusion:  The Execution Trace Toolkit may be used in conjunction with LabVIEW Real-Time to analyze behavior of an application at the OS level.

 

Debugging a Multicore Real-Time Application

 

With the increase in potential performance promised by multicore real-time targets, the software industry needs a method to debug complex applications that span multiple processors.  The LabVIEW Real-Time Execution Trace Toolkit 2.0 has added the support for mulitcore debugging.  The next example will quickly demonstrate debugging a multicore application.

 

1.    Open an example multicore execution trace log. 

a.    In the Execution Trace Tool Viewing Utility click Help >> Open Example Sessions. 

b.    Select “Multi-Processor Timed Loops (SMP).log”

c.    Click OK.

 

Note:  When a trace is logged on a multicore real-time target, the Viewing Utility will have the option to select a “Highlight CPU Mode”.  If a trace is logged on a single core target, the “Highlight CPU Mode” option will not be available.

 

2.    Examine the thread usage in the Viewing Utility.  Within the thread view, two threads execute simultaneously in parallel. 

 

 

3.    In order to determine which CPU a thread or VI is executing on, use the option “Highlight CPU Mode”.  Selecting a CPU from this menu will dim all threads and VIs that are not running on the selected CPU.  Select CPU 0 and observe how all threads running on CPU 1 are dimmed, while the TL on CPU 0 and ETS Null Thread remain full color.

 

 

Conclusion:  LabVIEW Real-Time Execution Trace Toolkit provides a visual way to debug real-time applications running on multiple processors.

 

More Information: Available Functions and Shipping Examples

 

View the Available Functions in LabVIEW Real-Time

 

LabVIEW Real-Time offers support for many of the functions that are available in LabVIEW for Windows, in addition to specialized functions that are applicable to real-time development. Go to the block diagram of one of the VIs that is already open, or create a new VI and right-click on the block diagram to bring up the Functions palette.

 

Drivers for such as DAQmx and Fieldpoint are exactly the same in LabVIEW Real-Time as they are in LabVIEW for Windows. This means there is no new learning curve to use your hardware with LabVIEW Real-Time.

 

LabVIEW Real-Time also offers support for the vast breadth of Math and Signal Processing functions. An extra feature of LabVIEW Real-Time, is the inclusion of the PID Toolkit, which is normally an extra add-on for LabVIEW.

 

 

View the Shipping Examples

In LabVIEW, go to the menu option “Help>>Find Examples…” to open the Example Finder.

Browse through these examples and open any that may be similar to an application you are working on.

 

For more information on LabVIEW Real-Time, please visit www.ni.com/realtime

For more information: Call (800) 531-5066 to speak with a Technical Representative.

 

        

3 ratings | 3.67 out of 5
Read in | Print | PDF

Reader Comments | Submit a comment »

 

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/).