Navigating LabVIEW

AHMET OZMEN
Virtual Instruments (VIs)
•LabVIEW programs are called virtual
instruments, or VIs
•Appearance and operation imitate physical
instruments, such as oscilloscopes and digital
multimeters
2
Parts of a VI
LabVIEW VIs contain three main components:
1. Front Panel
2. Block Diagram
3. Icon/Connector Pane
3
The LabVIEW Environment
“VI” = program or function
“Front Panel” = user interface
“Block Diagram” = code
Front Panel-Controls & Indicators
•
•
•
•
•
•
•
Knobs/Dials
Graphs/Charts
Buttons
Digital Displays
Sliders
Thermometers
Customize and
create your own
Front Panel – Controls Palette
• Contains the controls and indicators you
use to create the front panel
• Access from the front panel by selecting
View»Controls Palette
6
Front Panel – Front Panel Toolbar
7
Block Diagram
Block diagram objects include
the following:
– Terminals
– SubVIs
– Functions
– Constants
– Structures
– Wires
8
Block Diagram – Functions Palette
• Contains the VIs, functions, and
constants you use to create the
block diagram
9
Block Diagram – Block Diagram Toolbar
10
Block Diagram Terminals
11
Searching for Controls, VIs & Functions
• Find controls, function, and VIs using the
Search button on the Controls and Functions
palette
12
Dataflow
LabVIEW follows a dataflow model for running
VIs
• A node executes only when data are available
at all of its input terminals
• A node supplies data to the output terminals
only when the node finishes execution
13
Dataflow Programming
1
2
3
1 Both Simulate Signal Express VIs execute simultaneously
2 Comparison waits until all inputs are present, then executes
3 Once executed, output from comparison continues through code
Building a Simple VI
15
Building a Simple VI – Acquire
Acquire Express VIs:
• DAQ Assistant Express VI
• Instrument I/O Assistant Express VI
• Simulate Signal Express VI
• Read from Measurement File Express VI
16
Building a Simple VI – Analyze
Analyze Express VIs:
• Amplitude and Level Measurements Express VI
• Statistics Express VI
• Spectral Measurements Express VI
• Tone Measurements Express VI
• Filter Express VI
17
Built-in Programming Assistance
Highlight Execution
Block Diagram Cleanup
Context Help
PC-Based Data Acquisition (DAQ)
DAQ Demo
While Loops
Repeat (code);
Until Condition met;
End;
LabVIEW While Loop
Flowchart
Pseudo Code
While Loops
• Iteration terminal: returns number of times
loop has executed; zero indexed
• Conditional terminal: defines when the loop
stops
Iteration Terminal
Conditional Terminal
While Loops – Tunnels
• Tunnels transfer data into and out of structures
• The tunnel adopts the color of the data type
wired to the tunnel
• Data pass out of a loop after the loop terminates
• When a tunnel
passes data into
a loop, the loop
executes only
after data arrive
at the tunnel
While Loops - Error Checking and Error
Handling
• Use an error cluster in a While Loop to stop
the While Loop if an error occurs
For Loops
N=100;
i=0;
Until i=N:
Repeat (code;i=i+1);
End;
LabVIEW For Loop
Flowchart
Pseudo Code
For Loops
• Create a For Loop the same way you create a
While Loop
• If you need to replace an existing While Loop
with a For Loop, right-click the border of the
While Loop, and select Replace with For Loop
from the shortcut menu
• The value in the count terminal (an input
terminal)
indicates how many times to repeat the
subdiagram
Timing a VI
Why do you need timing in a VI?
• Control the frequency at which a loop
executes
• Provide the processor with time to complete
other tasks, such as processing the user
interface
Timing a VI – Wait Functions
• A wait function inside a loop allows the VI to
sleep for a set amount of time
• Allows the processor to address other tasks
during the wait time
• Uses the operating system millisecond clock
Timing Methods
– Wait VI – Constant time of execution
– Execute A, Execute B, sleep 10 ms
– Wait Until Next Multiple VI – Variable time of
execution
– Execute A, Execute B, sleep until OS timer reaches
next multiple of 20 ms
29
Timing a VI – Elapsed Time Express VI
• Determines how much time elapses after
some point in your VI
• Keep track of time while the VI continues to
execute
• Does not provide the processor with
time to complete other tasks
Iterative Data Transfer – Shift Registers
• Right-click the border and select Add Shift Register from the
shortcut menu
• Right shift register stores data on completion of an iteration
• Left shift register provides stored data at beginning of the
next iteration
Case Structures
•
•
•
•
Have two or more subdiagrams or cases
Execute and displays only one case at a time
An input value determines which subdiagram to execute
Similar to case statements or if...then...else
statements in text-based programming languages
Case Structures
• Case Selector Label: contains the name of the
current case and decrement and increment buttons
on each side
• Selector Terminal: Wire an input value, or selector, to
determine which case executes
Case Structures – Default Case
• You can specify a default
case for the Case structure
– If you specified cases for 1,
2, and 3, but you get an
input of 4, the Case
structure executes the
default case
• Right-click the Case
structure border to add,
duplicate, remove, or
rearrange cases and to
select a default case
State Programming
Although Sequence structures or sequentially wired
subVIs accomplish the purpose, it is not always the
best choice:
– What if you need to change the order of the
sequence?
– What if you need to repeat one item in the sequence
more often than the other items?
– What if some items in the sequence execute only
when certain conditions are met?
– What if you need to stop the program immediately,
rather than waiting until the end of the sequence?
State Machines
– The state machine design pattern implements a
state diagram or flow chart
– When to use state machines?
• Commonly used to create user interfaces, where
different user actions send the user interface into
different states
• Commonly used for process tests, where a state
represents each segment of the process
State Machines – Infrastructure
– A state machine consists of a set of states and a
transition function that maps to the next state
– Each state can lead to one or multiple states or
end the process flow
While Loop
Shift Register
Case Structure
State Machines – Default Transition
Parallelism
– Often, you need to program multiple tasks so that
they execute at the same time
– In LabVIEW, tasks can run in parallel if they do not
have a data dependency between them, and if
they do not use the same shared resource
• An example of a shared resource is a file, or an
instrument
Automatic Multithreading in LabVIEW
• LabVIEW automatically divides each application into multiple
execution threads (introduced in 1998 with LabVIEW 5.0)
• Parallel code paths will execute in unique threads
thread
thread
thread
Multiple Loop Architectures
41
Triggered Acquisition Demo
THANK YOU!