VIRTUAL INSTRUMENTATION USING LABVIEW

advertisement
VIRTUAL INSTRUMENTATION USING
LABVIEW
BY
S.ANITHA KUMARI A.P(O.G)
DEPT. OF EIE
Virtual Instrument
• LabVIEW works on a data flow model in which information
within a LabVIEW program, called a virtual instrument (VI),
flows from data sources to data sinks connected by wires.
• LabVIEW supports two types of VIs--internal VIs and user
created VIs.
• Internal VIs are packaged with LabVIEW and perform simple
functions like adding numbers or opening files.
• User created VIs consist of both a graphical user interface
called the front panel and a code pipeline called the block
diagram.
FRONT PANEL
Every user created VI
has a front panel that
contains the graphical
interface with which a
user interacts. The front
panel can house various
graphical objects ranging
from simple buttons to
complex graphs. It also
includes nonfunctioning
items such as free labels
and decorations.
Block diagram
The Block Diagram is a window
where the graphical code is
created.
Accessing the Functions
Palette in the Block
Diagram
Popping-Up on Controls
and Indicators
The Tool Palette
…To manage, modify, and debug
VI's .
Automatic Tool Selection ‐ Automatically selects between the Operate Value, Position/Size/Select, Edit Text and Connect Wire Tools. It is the most commonly Selected item on the Tools Palette. Operate Value ‐ Manipulates the values of Front Panel Controls and Indicators. Generally selected while running a VI.
Position/Size/Select ‐ Selects objects in a VI, moves them and resizes them. Edit Text ‐ Creates Free Labels on the Front Panel and edits their text. Also edits text in Owned Labels.
Connect Wire ‐ Wires Block Diagram nodes and objects together.
Object Shortcut Menu ‐ Displays an object's pop‐up menu with the left mouse button. Scroll Window ‐ Pans the content on a VI window without using the window's scroll bars. Set/Clear Breakpoint ‐ Create breakpoints in a VI Block Diagram for debugging purposes. Breakpoints cause the VI to suspend execution at a particular point. Probe Data ‐ Places Probes on wires in the Block Diagram for debugging purposes. A Probe displays the data on a wire where it is placed. Get Color ‐ Copies colors from VI objects to pasting with the Set Color Tool.
Set Color ‐ Colors objects in a VI and displays the foreground and background colors of the object. DATA TYPES
There are three possible data types in a VI
• Number- This data type contains numbers that
can be either floating point or integer.
• Boolean - This data type contains logical
combinations of TRUE/FALSE, AND, OR, NOT,
Etc.
• String - Contains alpha-numeric characters only
• All of these data types can be in either Scalar, 1D
Array or 2D Array form.
Wire Types
• There are different wire colors and types that depict
what kind of data is flowing through a particular wire
and if it is in Scalar, 1D Array or 2D Array form:
Numeric Control
Representation
REPRESENTION
Representation
ABBREVATION
Abbreviation
TERMINAL
Terminal
SIZE(BYTES)
Size (bytes)
byte
I8
1
unsigned byte
U8
1
word
I16
2
unsigned word
U16
2
long
I32
4
unsigned long
U32
4
single precision
SGL
4
double precision
DBL
8
extend precision
EXT
16
complex single
CSG
8
complex double
CDB
16
complex extended
CXT
32
CHANGING
REPRESENTATIONS
WIRING
• Wires are data flow paths between Block Diagram components.
• Block Diagram nodes are wired together for logical functioning of the VI.
Deleting wires:
Creating wires:select the Connect Wire tool on the tools palette
Wire Stretching: move a wired node on the Block Diagram, the
wires will stretch to follow the node
Selecting wires:
Align and Distribute
Objects Rings
•
To quickly and easily make the objects on your Front Panel or Block Diagram nice
and neat.
RUNNING VI
click on a Broken Run button,to get a list of errors in a
pop-up window
DEBUGGING VIs
Debugging Tools on the Block Diagram
Debugging Tools on the Tools Palette
Execution Highlight
when pressed, turns bright and allows you to view
the data flow through the Block Diagram slowly as
it goes from one Block Diagram component to the
next.
Step Over
activates the single-step mode which steps the
execution of the VI from node to node. Each node
blinks then it executes one at a time.
Step Into
activates the single-step mode and is used to step into
a loop or Sub VI so you can single step inside them.
Step Out
used to step out of a loop or Sub VI and to end the
execution of a VI.
Breakpoint Tool
used to set breakpoints or stopping points in a VI,
especially in a Sub VIs, functions, structures and
wires.
Probe Tool creates probes on wires in the Block Diagram. It
shows the data at that point in a wire at a particular
time. It is used for checking intermediate data inside a
VI.
SUB VIs
•
•
•
•
The Sub VI is considered as a lower-level VI inside of an upper-level VI.
This reduces the number of Block Diagram icons, which simplifies and modularizes the VI. Sub VIs
are much like functions or subroutines in conventional text-based programming languages.
Steps in creating sub vi:
create sub vi icon
Assign sub vi connectors
STRUCTURES
• In addition to controls, indicators, and VIs, the block diagram
can also contain a number of programming structures that
modify the sequence of data flow on the block diagram.
• LabVIEW currently supports six different structures, -whileloops, case structures, event structures, for-loops, sequence
structures, and formula nodes.
WHILE LOOP
•
A While Loop executes all or a portion of
. your Block Diagram code multiple times
pseudo-code:
Do
Execute diagram Inside the loop
While the condition is TRUE/FALSE
Create a While Loop
• Block Diagram > Functions > Structures > While
Loop
• Drag a rectangle area around the portion of Block
Diagram code that is to be included in the while
loop
While loop components
The Conditional Terminal
Continue if True condition. the
while loop will continue to repeat the
code until a boolean value of FALSE is
passed to the conditional terminal.
Stop if True condition. the while
loop will continue to repeat the code
until a boolean value of TRUE is
passed to the conditional terminal.
The Iteration Terminal
outputs the number of times the loop
has been executed
Controlling a while loop
The conditional terminal is wired to a Boolean Terminal. This terminal represents a
Boolean Control (switch) on the Front Panel for the user to control the operation of the
while loop.
FOR LOOP
•
The For Loop repeats Block Diagram code a
predetermined number of counted times.
When the number of iterations equals the
predetermined count, the loop stops.
• pseudo-code:
For i = 0 to N-1
Execute diagram inside the loop
• Create a For Loop
• Block Diagram > Functions > Structures >
For Loop:
• then drag a rectangle area around the portion
of Block Diagram code that is to be included
in the for loop
For loop components
The Count Terminal
The Count Terminal is
where the predetermined
count is placed. to control
the number of iterations.
The Iteration Terminal
The Iteration Terminal in a
for loop It is a terminal that
outputs the number of times
the loop has been executed.
The count starts at zero (the
first iteration of the loop is
Iteration Zero)
Case structures
•
The Case Structure is a method of
executing conditional statements. The
Case Structure is similar to if ... then ...
else statements in conventional
programming languages.
•
pseudo code:
If (Condition = Something) Then
Do This
Else
Do That
Endif
Case Structure is configured like a deck of cards. Labview only executes one at a
time. case executed is determined by the value wired to the selector terminal
CASE STRUCTURE DATA TYPES
Creating a Case Structure
Creating a Case Structure is much like creating While Loops and For Loops. To create
a Case Structure, Pop-up in the Block Diagram > Structures > Case Structure.
Drag an area for the Case Structure to encompass.
Managing case structure
The Select Function
•
In simple if-then-else cases, you can use the Select function:
• This function:
Returns the value wired to the t terminal if the value at the s terminal is TRUE
Returns the value wired to the f terminal if the value at the s terminal is
FALSE.
SEQUENCE STRUCTURES
•
•
used to control the order of execution of nodes that are not data dependent on each other. The
nodes within each frame are data dependent
The output tunnels of Sequence Structures can only have one data source which, unlike Case
Structures, has outputs that must have one data source per case. The output can come from
any frame, but the data will not leave the structure until the last frame in the structure has
.
completed it's execution. Data input is available to all frames
•
•
CREATING SEQUENCE STRUCTURE:Pop-up in the Block Diagram > Structures >
Sequence Structure.
To add more frames, pop‐up on the sequence boundary > Add Frame After
SEQUENCE LOCAL: variables that allow you to pass data between frames of a Sequence Structure
Example for sequence local
FORMULAE NODE
• A Formula Node is a box where you enter algebraic formulas directly into the Block Diagram. It is useful when an equation is complicated or has many variables. • Below is an example of how you would implement y
= x^2 + x + 1 with regular block diagram nodes
It is much easier to use the Formula Node.
Creating a Formula Node
•
•
•
•
•
•
Pop-up in the Block Diagram > Structures > Formula Node.
Add an Input and an Output on the left and right vertical sides of the Formula
Node's boundary.
The nodes must also be named to match the variables used in the equation.
Add them by popping-up on a vertical boundary > Add Input or Add Output.
Label them correctly and wire them to the appropriate nodes.
Then type equation using the correct operators and functions. A semicolon always follows each formula statement.
ARRAYS
• An array is a collection of data elements. The data elements in an array can be numeric, boolean, string or cluster, but all data elements must be of the same type within an array. Arrays can be one or two‐dimensional.
ARRAY FUNCTIONS
Arrays can also be created and
controlled by Array
Functions. They are all found by
popping-up in the Block Diagram
> Functions > Array:
ARRAY SIZE
returns the number of
elements in an array it
is wired to.
INITIALIZE ARRAY
creates an array of dimension size elements containing the element value.
BUILD ARRAY
links multiple arrays. It appends elements to an array.
it concatenates multiple arrays
ARRAY SUBSET
returns a portion of an array starting at index and containing length elem
ents
ARRAY SEARCHING
searches the name array for the target and reports if the target is found as well as its position in the array.
Creating One-Dimensional Arrays With a Loop
•
Manually creating and
adding data to arrays
can be tedious work.
So loops are often
used to create onedimensional and twodimensional arrays.
Both For Loops and
While Loops can
create arrays and their
boundaries
automatically with
auto indexing.
Creating TWO-Dimensional Arrays With nested Loop
• The outer
loop creates
the row
elements and
the inner loop
creates the
column
elements.
Clearing Array Data
• To clear an array of data,
pop-up on any Index Display >
Empty Array:
INDEXING
•
•
Indexing is a feature that can be enabled for input and output tunnels of both whileloops and for-loop
When an array wire passes into a loop through a tunnel that does not have indexing
enabled, the entire array is placed on the wire and can be accessed during each loop
iteration. When indexing is enabled, only the array element at the index
corresponding to the current loop iteration is available from that tunnel.s by right
clicking on a tunnel.
INPUT INDEXING
OUTPUT INDEXING
Polymorphism
Labview arithmetic functions like Add, Multiply,
Divide. Etc. are polymorphic. This means that
the data structures on their inputs can be either
scalar or array. If any inputs are of the array data
structure, the output will be an array data
structure. If the inputs have array structures of
different sizes, the output will be an array that is
the same size as the smallest input array.
Controlling Boolean Controls
• BooleanControls
usually operate like
switches. Most of them
are in the off position
by default (Normally
Open). You can control
the mechanical action
of the Boolean Control
by popping-up on it >
Mechanical Action
Switch When Pressed ‐ The Control's value is changed each time the control is pressed. This works much like a standard light switch.
Switch When Released ‐ The Control's value is changed when the mouse button is released. Switch Until Released ‐ The Control's value is changed when the control is clicked and retains that value until the mouse button is released. Latch When Pressed ‐ The Control's value changes when it is clicked, retains that value until the VI reads it once and then reverts back to it's original value.
Latch When Released ‐ The Control's value changes when the mouse button is released, retains that value until the VI reads it once and then reverts back to it's original value. Latch Until Released ‐ The Control's value changes when it is clicked, retains that value until the VI reads it once or
until the mouse button is released, whichever occurs last.
Showing a Boolean
Controls State
popping up on the control >
Visible Items > Boolean Text
THANK YOU
Download