You are on page 1of 13

Introduction to National Instrument’s LabVIEW

Virtual Instruments(VI), For Loop Structure, Formula Node, and


Graphs

WHY LEARNING LABVIEW?


LabView is a very powerful graphical programming language for
instrumentation and control applications. It is specifically designed to take
measurements, analyze data, and present results in a very efficient way.
It has a versatile graphical user interface and a vast library of functions for
a wide range of applications. It is easy to program with and may be used
to solve a wide range of engineering problems.

LEARNING OBJECTIVES
At the end of this lab session, you would have learned to:
 Navigate the LabVIEW graphical programming language environment.
 Create a VI code to perform simple math operations and use of formula
node
 Use For and While Loop structures
 Disply results on Waveform Charts and Graphs

RESOURCES
o Lab Module # 1
o Text book by R. Bishop
o LabView on line tutorial
o National instrument website: www.ni.com
o Instructors

SETUP
 Insert (connect) your CD or floppy disk (USB mobile disk) into the
appropriate drive (USB port). Check the disk directory to make sure
your disk is free of any viruses.
 Launch LabVIEW from the LabVIEW group in the Start menu of the
task bar.
 When prompted to open an existing or new VI, select New VI.
 When the new VI windows appear, select Windows»Show Tools
Palette to display the Tools palette.
 From the File menu, select Save As and save the file to your CD or
USB disk under a suitable name. The file extension must be *.vi. It is a
good idea to save the file every few minutes during the development
process. Save the file after making a change you want to keep.

WHAT IS LabVIEW
Labview program is a visual programming tool that provides a
programming environment to develop programs with graphics rather than
use text-based languages to create lines of code. LabVIEW is an acronym
MECH 374: Measurements and Lab Module # 1; Pag
Instrumentation e1
for Laboratory Virtual Instrument Engineering Workbench. A LabVIEW
program is called a Virtual Instrument (VI) because its appearance and
operation imitate actual instruments. A VI has two main parts, the front
panel and the Block Diagram. LabVIEW programming consists of drawing
pictures that specify data dependencies. The LabVIEW programming
environment includes a large set of blocks grouped in two main palettes
to specify operations, the control palette and the functions palette. The
different blocks are wired using the wiring tool to connect them together.
The Front Panel (FP) is the interactive user interface of a VI mimicking
the "face" of the instrument. On it can be placed all the controls and
indicators (knobs, graphs, etc.) necessary to make the virtual instrument
look real. Associated with the front panel is the Control tool box or
Palette. The Controls are the Inputs that simulate typical input devices
such as knobs and switches. The Indicators are the Outputs that
simulate output displays that show data the program requires or
generates. Controls and indicators are not functionally equivalent. The
Toolbar located at the top of the FP contains buttons used to control the
execution of the program and alignment and distribution of objects.

MECH 374: Measurements and Lab Module # Page 2


Instrumentation 1
The control palette (CP) is available when the front panel is active. To
make it visible, right click on the mouse in an open area of the FP or select
Show Controls Palette from the windows pull down menu. The CP
contains top-level icons of representing sub-palettes, each containing a
wide range of associated objects used to construct the FP of a VI. The
available sub-palettes includes: Numeric Controls and Numeric Indicators,
Buttons and LEDs, Text Controls and Text Indicators, Graph Indicators,
and the All Controls. The All Control sub-palette allows access to all built in
controls. Control means input and indicator means output.
The Block Diagram (BD) holds the graphical source code of a LabVIEW
VI and it is essentially the source code of the virtual instrument where the
main executable program is written. FP objects have corresponding
terminals on the BD so that the data can pass from the user to the
program and back to the user. The BD has the Functions tool box or
Palette. The Toolbar at the top of the BD contains buttons used to control
the execution of the program and alignment and distribution of objects
and has a few more options than that in the FP. Components of a BD
include: icons, nodes, terminals, and wires.

MECH 374: Measurements and Lab Module # Page 3


Instrumentation 1
The Functions palette contains top-level icons of many sub-palettes that
contain a wide range of associated objects that are used to
construct the block diagram. The available sub-palettes includes:
Input, Analysis, Output, Execution Control, Arithmetic/Compare,
Signal Manipulation, and All Functions. The All Functions sub-palette
allows access to all built in functions that include the following sub-
palettes: Structures, Numeric, Boolean, Array, String, Cluster,
Comparison, Time and Dialog, File I/O, NI Measurement, Waveform,
Analyze, Instrument I/O, and many other functions. The Structure
sub-palette contains For Loops, While Loops, and Formula Nodes.
The functions palette becomes visible by a right click on the mouse
in an open area of the block diagram or by selecting Show
Functionss Palette from the windows pull down menu.
A Node is a program execution element analogous to statements,
operators, functions, and subroutines in standard programming
languages. The node represents a lower-level VI that operates as a sub VI
MECH 374: Measurements and Lab Module # Page 4
Instrumentation 1
inside another VI and allows other VIs to pass data to the VI. The Icon is
the graphical representation of a node on the BD. There are three types of
nodes: Functions, sub VI node, and Structures. Functions are the
fundamental operating element of a BD. They represent built-in nodes for
performing elementary operations. Sub VIs are built and saved for later
use. Structures control the program flow. Dataflow is based on the
principle that functions execute only after receiving the necessary data.
The icon shown is a built-in Gaussian Peak Fit Node
(Functions>Mathematics>Fitting)

Terminals are analogous to parameters and constants in text-based


programming languages. They represent any point to which a wire can be
attached to pass data. When a control or indicator is placed on the front
panel, LabVIEW spontaneously creates a corresponding terminal on the
block diagram. Control terminals have thick borders and indicator
terminals have thin borders. When the wiring tool moves over a terminal,
tip strips (shown on the node) pop up to facilitate identifying functions
and node terminals.
Wires define the data paths between source and destination terminals.
Each wire has a different style or color, depending on the data type that
flows through the wire. Data types indicate what objects, inputs, and
outputs that can be wired together. The wire types are: Orange for
floating point Numeric and Blue for integer Numeric; Green for Boolean;
and Pink for String. Wire thickness increases from the scalar, to the1D
array, and thickest for 2D array.
The Tools Palette
The tools palette (shown) contains the tools needed to edit and debug the
FP and BD. Table 1 explains the function of each tool.

MECH 374: Measurements and Lab Module # Page 5


Instrumentation 1
Table 1. Some Useful Commands and Tools

Command/Tool Purpose Used When Picture

Delete key Deletes There are unwanted objects <Delete>


selected in the program
objects
Ctrl-S Saves files You want to save your <Ctrl-S>
changes
Positioning Moves and You need to be move or
tool selects objects delete program elements or
insert new ones
Wiring tool Connects Program elements must be
objects connected to allow data to
together flow between them
Ctrl-B Removes all There are several unwanted <Ctrl-B>
broken wires wires in the program; use
with caution
Operating tool Changes values You need to change a value
in a front panel object
Text tool Edits text You need to change a label
or a comment

Illustrative Example
Assume a control application involving two switches and two sensors, an
LVDT and a potentiometer. One switch represents an IR emitter/detector
used at a door and the other is a filling station control switch used to
activate or stop a tank filling operation. The LVDT measures the level of
fluid in a tank and is represented by a slide indicator and the pot control
defines the angular position of a valve and is represented by a knob
control. The LVDT output is given by 0.01h, where h is the fluid level in the
tank. If the two switches are closed, a security light turns on and the tank
filling at a rate of 5Aθ , A is area of the tank and θ is the angular output
of the potentiometer. If the output of the LVDT is 100 mm, a siren should
go off for 2 seconds and the valve should close. Develop a LabVIEW code
to implement the control process.

CHARTS AND GRAPHS


Data may be displayed in LabVIEW as charts and graphs. LabVIEW
provides for three types of charts displays, strip chart, scope chart, and
sweep chart, and two types of graphs, waveform graph and XY graph.

Charts
The strip chart is similar to a typical paper strip chart used in laboratories
such as EKG machine. The display scrolls to the left as ecah new data
point arrives. The scope and sweep charts are similar to the action of an
oscilloscope. In the scope chart the entire plot is erased and the plotting
begins again from the left side whenever the data reaches the right
border of the chart. In the sweep chart a vertical line marks the beginning

MECH 374: Measurements and Lab Module # Page 6


Instrumentation 1
of new data and moves across the display instead of erasing the plot as
the scope chart does.
Graphs
A waveform graph plots array of uniformly spaced data points (evenly
spaced waveforms) of a single-valued function all at once. The space
between data points is ∆ X = 1 and the initial value of X is X0 = 0. If ∆ X ≠
1 or if X0 ≠ 0 then the desired ∆ X, X0 , and array are clustered to the
waveform graph using the bundle function as shown.

Graphs plots the rows of a 2D array. If the 2D data array is given in


columns transpose it first before wiring it to the graph. If wired first, pop
up on the graph in thye front panel and select Traspose Array from the
pop-up menu.

The XY graph is a general purpose cartesian plot for data available at


irregular intervals or for data belonging to two dependent variables
against each other, such as x vs y. The XY Graph can also plot
multivariable functions such as, circles, ellipsoids, etc. The Express (EX)
XY Graph located in the Graph Indicator sub-palette of the Controls
palette simplifies the use of XY Graphs. To plot multiple waveforms, say
(x1, y1) and (x2,y2), on a single graph, use the merge signal function to
merge x1, x2 data arrays and y1, y2 data arrays before routing them to X
input and Y input of the EX XY Graph VI.

INTERACTIVE EXAMPLES
A LabVIEW program, called a virtual instrument (VI), is a two-window
system. The code is in one window and the user interface (inputs and
outputs) appears in a separate window. The program window is the block
diagram window, and the user inputs and outputs are in the front panel
window. The following examples demonstrate the process of creating a VI.
They will help you learn the basics of LabVIEW programming. Follow each
step completely before executing the step. By the end of the session, you
will have written a VI that displays a sine function on a chart. After
completing this tutorial, you should be able to complete the rest of the
lab.
Example - I
As an introductory example, let us construct a VI to determine the
acceleration a of an object of mass m subject to a F resulting from a
pressure P acting on the object surface area A. Figure 1 shows the block
diagram window that implements the calculations involved: F = PA and a
= F/m

MECH 374: Measurements and Lab Module # Page 7


Instrumentation 1
Figure 1 Program to Multiply Two Numbers and Display the
result

MECH 374: Measurements and Lab Module # Page 8


Instrumentation 1
Figure 2 Front Panel for a Two-Number Multiplication Program

STEPS

The program calculates the force from pressure and area, and
then the acceleration of the object on which the force acts. The
numbers are entered into the computer and displayed in the
front panel window shown in Figure 2. The blocks on the left
(labeled pressure, area, and mass) are controls. The gauge box
and the slide on the right labeled force and acceleration are the
outputs or indicators. The boxes are associated with like labeled
boxes in the diagram window shown in Figure 2.
Example - II
Develop a VI to generate the following signals and show them on the
same plot:
x = 3sin t
y = 4e − t 5
z = xy
w = 2x − z
for t = ( π 10 ) * i; i = 1,..,100

STEPS

1. Place a Waveform chart located in the Controls>>Graph Indicator


subpalette on the Front Panel as shown.
2. Place on the block diagram the For Loop located in the Functions>>All
Functions>>Structures palette. The For Loop has two terminals: the
count terminal N and the iteration terminal i.
3. Pop up on the count terminal and select Constant from the Create
menu to create a constant to the For Loop. Set the value of the
constant to 100 to execute the For Loop 100 times. Wire this constant
to the count terminal using the wiring tool.
4. Drop the Divide and Multiply functions located in the
Functions>>Arithmetic & Comparison>>Numeric Palette inside the For
Loop.
5. Select Constant from the Create menu to create a constant 10 and
π inside the For Loop. Use the wiring tool to wire these two constants
MECH 374: Measurements and Lab Module # Page 9
Instrumentation 1
to the Divide function terminals as shown.
6. Wire the output terminal of the Divide function and the Iteration
terminal to the input terminals of the Multiply function as shown.
7. Place inside the For Loop a Formula Node located in the Functions>>All
Functions>>Structures palette. Type the equation as shown and
terminate with a semicolon.
8. Create the input and output terminals of the Formula Node by popping
on the border of the node and choose Add Input and Add Output
from the short cut menu. Note that output variables have a thicker
border than input variables.
9. Use the Labeling tool to enter the input and output variable names (t
and y)
10. Wire the output of the Multiply function to the input of the Formula
Node.

MECH 374: Measurements and Lab Module # Page 10


Instrumentation 1
11. Wire the output of the Formula Node to a Build Array node located in
the All Functions>>Array>>Build Array. Note a tunnel appear on the
border of the For Loop through which data exits the For Loop.
12. Wire the appended array to the waveform chart.

Figure 3 Block Diagram for Example II

Figure 4 Front Panel for Example II

Practice
Consider the distance required for an automobile to stop when the driver
suddenly applies the brakes, locking the wheels so that a skid occurs. The
car has mass m which at time t = 0 has velocity v0 (20 m/s). For time t>0,
MECH 374: Measurements and Lab Module # Page 11
Instrumentation 1
the only force acting on the car are the tire-pavement resistance force Fr
= µ mg and the weight mg of the car which generates the normal force
between the car and the pavement; m (800 kg) is the mass, µ (0.8) is the
coefficient of friction for the tire-pavement interface, and g (9.81 m/s2) is
the acceleration of gravity. Determine the stopping distance and indicate
on the front panel. Determine and plot the variation of acceleration,
velocity, and position during stopping.

Critical thinking questions

• Does the VI run? How do you know?


• How could you determine the number of times the while loop
executes each time you run the program?

References
• Rober H. Bishop, Learning with LabVIEW 7 Express, Prentice-Hall
(2004)
• LabVIEW Tutorial, National Instruments, Inc., Austin, TX.
www.ni.com

VOCABULARY

LabVIEW – Laboratory Virtual Instrument Engineering Workbench is a


graphical programming environment to develop programs with graphics
rather than use text-based languages to create lines of code.
Virtual Instrument - LabView program is called VI because the
appearance and operation imitate actual instruments. A VI has three main
parts: the front panel, the Block Diagram, and the icon and connectors.
Front Panel - is the interactive user interface of a VI
Controls = Inputs; Simulate typical input devices such as knobs and
switches
Indicators = Outputs; Simulate output displays that show data the
program requires or generates. Controls and indicators are not
functionally equivalent.
Block Diagram - It holds the graphical source code of a LabVIEW VI
which is the actual executable program. Its various components are:
terminals, nodes, and wires.
Icon - represents a VI that operates as a sub VI inside another VI. It allows
other VIs to pass data to the VI.

MECH 374: Measurements and Lab Module # Page 12


Instrumentation 1
Gaussian Peak Fit Node (Functions>Mathematics>Fitting)
Nodes - node is a program execution element analogous to statements,
operators, functions, and subroutines in standard programming
languages. The three node types are: Functions, sub VI node, and
Structures. Functions are the fundamental operating element of a BD.
They represent built-in nodes for performing elementary operations.Sub
VIs are built and saved for later use. Structures control the program flow.
Terminals –Analogous to parameters and constants in text-based
programming languages. They represent any point to which a wire can be
attached to pass data. When a control or indicator is placed on the front
panel, LabVIEW spontaneously creates a corresponding terminal on the
block diagram. Control terminals have thick borders and indicator
terminals have thin borders.
Wires - the data paths between source and destination terminals. Each
wire has a different style or color, depending on the data type that flows
through the wire. Common wire types are: Orange for floating point
Numeric and Blue for integer Numeric; Green for Boolean; and Pink for
String. Wire thickness increases from the scalar, to the1D array, and
thickest for 2D array.
Data types indicate what objects, inputs, and outputs that can be wired
together.
Dataflow – It is based on the principle that functions execute only after
receiving the necessary data
Toolbar – located at the top of LabVIEW windows. It contains buttons
used to control the execution of the program and alignment and
distribution of objects. The toolbar in the block diagram has a few more
options than that in the front panel.
Tunnel – A data entry point or exit point on a structure.

MECH 374: Measurements and Lab Module # Page 13


Instrumentation 1

You might also like