Title: Advanced RealTime Programming
1Advanced Real-Time Programming
- John Limroth
- LabVIEW Real-Time Systems Engineer
2Presentation Overview
- Embedded versus real-time needs
- Real-time case study 16 Channel PID
- Software timing versus hardware timing
- Synchronizing analog input and output across
multiple DAQ boards - Real-time optimization rules of thumb
3Embedded Versus Real-Time
- Do you need real-time or embedded
characteristics? - What is your real-time need?
- NOTE This presentation focuses on maximizing
determinism in LabVIEW Real-Time applications.
4Real-Time Software Principles
- Benefits of multithreading
- Thread Priorities
- Time-critical priority (highest)
- Methods of scheduling multiple threads
- Round Robin
- Preemption
- Sleep mode
5Real-Time Software Principles (cont.)
- Benefits of multithreading
- Thread Priorities
- Time-critical priority (highest)
- Methods of scheduling multiple threads
- Round Robin
- Preemption
- Sleep mode
6Real-Time Software Principles (cont.)
- Benefits of multithreading
- Thread Priorities
- Time-critical priority (highest)
- Methods of scheduling multiple threads
- Round Robin
- Preemption
- Sleep mode
7Assigning Priority to a VI
8Real-Time Case Study
- System Multi-loop PID controller
- LabVIEW Real-Time 6i
- NI-DAQ 6.9.1
- PXI-8170 controller
- PXI E-series data acquisition (DAQ) boards
- Objective
- Achieve nanosecond determinism
9Single PID Loop Application
10Software Timing
- Software determines timing of all operations
AI
AO
AI
(t)
HW events
Code Execution Time
Sleep Time (Wait Until)
?T (ms multiple)
11Software Timing
- Software determines timing of all operations
AI
AO
AI
(t)
HW events
Code Execution Time
Sleep Time (Wait Until)
?T (ms multiple)
Software Jitter
Note Not drawn to scale!
12Software Timed PID Loop
- Max loop rate 1 kHz
- Timing limited to 1 ms intervals
- 1 kHz, 500 Hz, 333 Hz, 250 Hz, etc.
- AI/AO timing is subject to software jitter
- Note These characteristics are sufficient for
most real-time control applications!
13Anchoring Software to Hardware
- AI Single Scan.vi provides
- Hardware timing of software
- Sleeping pathway built into NI-DAQ
- Increased overall performance of application
- NOTE Counter/timer functions used with E-Series
MIO devices also have a sleeping pathway
14Hardware Timed Loop
15Hardware Timing
- Hardware timing masks software jitter from the
system under control
AI
AI
AO
(t)
HW events
Code Execution Time
Sleep Time (AI SingleScan)
DAQ Hardware ?T
16Hardware Timing
- Hardware timing masks software jitter from the
system under control
AI
AI
AO
(t)
HW events
Code Execution Time
Sleep Time (AI SingleScan)
DAQ Hardware ?T
Software Jitter
17Hardware Timing
- Hardware timing masks software jitter from the
system under control - Te Tj ? ?T
AI
AI
AO
(t)
HW events
Te
TJ
Code Execution Time, Te
Sleep Time (AI SingleScan)
DT
DAQ Hardware ?T
Software Jitter, Tj
18Hardware Timed PID Loop
- AI has nanosecond determinism
- AO timing is subject to software jitter
1916 Ch. PID Loop Application
- 2 PXI-6040E boards for analog input
- 2 PXI-6713 boards for analog output
2016 Ch. Hardware Timed Loop
2116 Ch. Hardware Timing
AI
AI
AO
AI
AI
AO
(t)
HW events
Code Execution Time
Sleep Time (AI SingleScan)
DAQ Hardware ?T
2216 Ch. Hardware Timing
AI
AI
AO
AO
AI
AI
(t)
HW events
Code Execution Time
Sleep Time (AI SingleScan)
DAQ Hardware ?T
Software Jitter
2316 Channel PID Loop
- Timing of AI scans on the two boards is
independent - AO timing is subject to software jitter
24Synchronized Hardware Timing
- Use RTSI line or PFI pin to synchronize AI and
AO - One AI board serves as master
- Clock for all other AI and AO is driven by the
master - Example
- \LabVIEW\Examples\DAQ\Solution
\Control.llb\Real-Time PID Control.vi
25Synchronized Hardware Timing
26Synchronized Hardware Timing
- Hardware timing masks software jitter from the
system under control
AI/AO
AI/AO
(t)
HW events
Code Execution Time
Sleep Time (AI SingleScan)
DAQ Hardware ?T
27Synchronized Hardware Timing
- Hardware timing masks software jitter from the
system under control
AI/AO
AI/AO
(t)
HW events
Code Execution Time
Sleep Time (AI SingleScan)
DAQ Hardware ?T
Software Jitter
28Synchronized Hardware Timing
- All AI board scans and AO board updates driven by
one clock - AI and AO timing have nanosecond determinism
29Shared Resources
- Shared resources cause priority inversions which
result in software jitter - Common shared resources
- Memory Manager
- Global variables
- Non-reentrant sub-VIs
- Synchronization code (Queues, Semaphores,
Occurrences, etc) - TCP/IP, UDP, VI Server, (networking protocols)
- File I/O
30Shared Resources(cont.)
- Shared resources cause priority inversions which
result in software jitter - Common shared resources
- Memory Manager
- Global variables
- Non-reentrant sub-VIs
- Synchronization code (Queues, Semaphores,
Occurrences, etc) - TCP/IP, UDP, VI Server, (networking protocols)
- File I/O
31Shared Resources Example
32Shared Resources Example
3310 Ch. PID Loop Example
34LabVIEW Real-Time Constraints
- ALL NI-DAQ calls MUST be done within the
real-time loop! - Single time-critical loop in the entire
application
35Results Summary
- Two solutions found
- Synchronized hardware timing
- Removal of all shared resources (e.g. no memory
management!) - Result robust, high performance control system
with nanosecond determinism