12-29-2009 10:56 AM
This document describes the top LabVIEW RT programming mistakes and explains how to avoid them.
Most real-time applications use a subset of common tasks. For the most common RT tasks, there are proven task architectures you can use as starting points in your applications. Reusing common, time-tested code reduces development and debugging time and generally increases the reliability of the application.
Benchmarking is easy to get wrong, but it can be difficult to know when your benchmarks are misleading. National Instruments strongly recommends using the RT Benchmark example project as a starting point when benchmarking code that will be included in a time-critical VI or a timed structure. You also can use the RT Benchmark example project to benchmark non-time-critical code. However, before doing so you should change the priority of the benchmarking VI to match the priority at which the code will run in your application. The code in the RT Benchmark example has been carefully designed to provide accurate average-case and worst-case (jitter) execution time over thousands of iterations. However, even when you are using the RT Benchmark example, it is important to keep the following considerations in mind:
When benchmarking timed structures, use the built-in timing nodes of the structure rather than the Get Timestamp function or the RT Get Timestamp VI.
Common foes of determinism include:
Add text here.
Add text here.
Add text here.
Add text here.
Add text here.
Add text here.
Add text here.
Add text here.
Generally, you should host network-published shared variables on the host PC rather than on the RT target itself. Hosting network-published shared variables consumes CPU resources, and in most cases there is no advantage to hosting on the RT target. Because RT CPU cycles are generally more valuable than CPU cycles on a desktop PC, it usually makes more sense to host network-published shared variables on a desktop PC to minimize CPU overhead on the RT target.
If your application consumes over 95% of the CPU resources available on the RT target, consider offloading certain tasks either to a desktop PC or to an FPGA target, if available. Use the following guidelines to determine the most appropriate device for offloading specific types of tasks.
Task | Appropriate Devices |
---|---|
Data acquisition | RT, FPGA |
Control loop | RT, FPGA |
Data analysis for logging or monitoring purposes (offline analysis) | Desktop PC |
Data logging | RT |
National Instruments never recommends turning off an RT target without stopping the application or switching the application to a safe shutdown state. Even if your RT target uses the Reliance file system, you can still cause data corruption by turning off the target while a file is open. Reliance protects the integrity of the file system itself in such cases, but does not guarantee the integrity of individual files that might be open when you turn off the RT target.
For example, the following block diagram shows the shutdown state of the top-level state machine for an RT application.
The code in the shutdown state ensures that all files are closed before notifying the operator that it is safe to turn off the RT target.