ahmet ozmen
DESCRIPTION
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. Parts of a VI. LabVIEW VIs contain three main components: Front Panel - PowerPoint PPT PresentationTRANSCRIPT
AHMET OZMEN
2
Virtual Instruments (VIs)
•LabVIEW programs are called virtual instruments, or VIs•Appearance and operation imitate physical instruments, such as oscilloscopes and digital multimeters
3
Parts of a VI
LabVIEW VIs contain three main components:1. Front Panel 2. Block Diagram 3. Icon/Connector Pane
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
6
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
7
Front Panel – Front Panel Toolbar
8
Block Diagram
Block diagram objects include the following:
–Terminals–SubVIs–Functions–Constants–Structures–Wires
9
Block Diagram – Functions Palette• Contains the VIs, functions, and
constants you use to create the block diagram
10
Block Diagram – Block Diagram Toolbar
11
Block Diagram Terminals
12
Searching for Controls, VIs & Functions
• Find controls, function, and VIs using the Search button on the Controls and Functions palette
13
DataflowLabVIEW 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
Dataflow Programming
123
Comparison waits until all inputs are present, then executesOnce executed, output from comparison continues through code
Both Simulate Signal Express VIs execute simultaneously
1 2 3
Block
Diagram
15
Building a Simple VI
16
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
17
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
Built-in Programming Assistance
Highlight Execution
Block Diagram Cleanup
Context Help
PC-Based Data Acquisition (DAQ)
DAQ Demo
While Loops
LabVIEW While Loop Flowchart Pseudo Code
Repeat (code);Until Condition met;End;
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
LabVIEW For Loop Flowchart Pseudo Code
N=100;i=0;Until i=N:Repeat (code;i=i+1);
End;
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
Case StructureShift Register
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
• LabVIEW automatically divides each application into multiple execution threads (introduced in 1998 with LabVIEW 5.0)
• Parallel code paths will execute in unique threads
Automatic Multithreading in LabVIEW
thread
thread
thread
Multiple Loop Architectures
41
Triggered Acquisition Demo
THANK YOU!