Labview Report

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Theory

The acronym LabVIEW stands for “Laboratory Virtual Instruments Engineering Workbench”.
LabVIEW is a graphical programming language that uses icons instead of lines of text to create
applications. In comparison to text based programming, where instructions determine program
execution, LabVIEW uses dataflow programming, where the flow of data determines execution.
In LabVIEW, user interface can be built using tools and objects. The user interface is known as
front panel. Then codes are added using graphical representations of functions to control the front
panel objects. The block diagram contains this code. In some ways the block diagram resembles a
flowchart.
Nearly all test, measurement and control applications can be divided into three main components:
a) Acquisition: LabVIEW is closely integrated with all National Instruments hardware in
addition to being connected to thousands of I/O devices from hundreds of different
vendors.
b) Analyzing: Tools required for powerful measurements are built inside the environment of
LabVIEW.
c) Presentation: The presentation of the processed data can be done with the LabVIEW or
over a network or one can take advantage of additional applications.

Apparatus:
a) Personal Computer
b) LabVIEW software (version 2009)

Creating a new VI:


LabVIEW programs are called virtual instruments or VIs because of their appearance and
operation imitate physical instruments namely oscilloscopes and multimeters. Every VI uses
functions that manipulate the inputs from the user interface or other sources and display that
information or process that information in order to transfer to another computer. A VI contains the
following components:
 Front Panel: The front panel is the user interface of the VI. It is built with controls and
indicators, which are the interactive input and output terminals of the VI respectively.
Controls are knobs, push buttons, dials and other input devices. Indicators are graphs, LEDs
and other displays. Controls simulate instrument input devices and supply data to the block
diagram of the VI. Indicators simulate instrument output devices and display data the block
diagram acquires or generates.
 Block Diagram: It contains the graphical source code that defines the functionality of the
VI. After the block diagram is built, codes can be added using graphical representations of
functions to control the front panel objects. The block diagram contains this graphical
source code. Front panel objects appear as terminals on the block diagram. Figure 1 shows
the front panel and block diagram.
 Icon and connector pane: After a VI front panel has been built, it is required to build the
icon and connector panes to use the VI as a sub VI. Every VI has an icon as shown in the
upper right corner of front panel in Figure 1. An icon is a graphical representation of the
VI. It can contain text, images or combination of both. If a VI is to be used as a sub VI, the
icon identifies the sub VI on the block diagram of the VI. An icon can be customized by
double clicking it or editing it. When a VI is used inside another VI it is termed as sub VI.
A sub VI corresponds to a subroutine in text based programming languages. A connector
pane is also needed to use the VI as a sub VI. The connector pane is a set of terminals that
corresponds to the controls and indicators of that VI, similar to the parameter list of a
function call in text-based programming languages. The connector pane defines the inputs
and outputs that can be wired to the VI so to use it as a sub VI. A connector pane receives
data at its input terminals and passes the data to the block diagram code through the front
panel controls and receives the results at its output terminals from the front panel indicators.

Figure 1: The front panel and block diagram of a VI.


List of experiments:
In this practical seven experiments have been done which are listed below:
1. Developing a VI that can perform temperature conversion from Celsius to Fahrenheit.
2. Developing a VI that can generate random signals.
3. Developing a VI that can work as a shift register.
4. Developing a VI that can calculate the square root of a number.
5. Developing a VI that can build string.
6. Developing a VI that can write contents into a file.
7. Developing a VI that can read contents from a file.
8. Developing a VI that can blink a LED using a DAQ card.

These experiments are described hereunder:

Experiment 1
Objective: In this experiment the VI is designed to convert any temperature representing in
degrees Centigrade to a temperature representing in degrees Fahrenheit. The block diagram is built
to execute the following formula:
C/5 = (F-32)/9
=˃ 9C/5 = F-32
=˃ 1.8C = F-32
=˃ F = 1.8C+32
For instance, if C = 35.5, then F = 1.8*35.5+32 = 95.9

Procedure: The front panel of the VI contains a numeric control as input and a numeric indicator
as output. On the other hand the block diagram contains one multiply function, one add function
and two numeric constants. The subsequent steps for building this desired VI are given below:
i. Open a new front panel by selecting the New VI button from the startup window and then
double click on “Blank VI” to open the window.
ii. View the front panel and block diagram windows side by side by choosing Tile Left and
Right from the Window menu.
iii. Make the Front panel window the active window by clicking anywhere on it and select
Numeric Control from the Numeric controls subpalette of the Controls palette.
iv. Select Numeric Indicator from the Numeric controls subpalette of the Controls palette.
v. Now make the Diagram window the active window by clicking anywhere on it and select
the Multiply and Add functions one at a time from the Numeric subpalette of the
Mathematics palette and place them in the diagram window.
vi. Select the two numeric constants one at a time from the Numeric subpalette of the
Mathematics palette and type 1.8 into one constant and 32.0 into the other one.
vii. Using the Wiring Tool from the Tools palette, wire the icons as shown in the block diagram
below.

Figure 1: Front panel and block diagram of Experiment 1

Discussion: Though in this experiment it is possible to convert Celsius to Fahrenheit but the
opposite operation is also possible with the environment of LabVIEW. The input can be given up
to four decimal points and the result is also given up to four decimal points without any error.

Experiment 2

Objective: In this experiment the VI is designed to generate a random signal by generating


random data continuously and display the signal on a waveform chart in scope update mode until
it is turned off.

Procedure: The front panel of the VI contains a switch, a knob control and a waveform chart.
On the other hand the block diagram contains the corresponding terminals of switch, knob control
and waveform chart, a random number function which returns a random number from 0 to 1, a
Multiply function and a Wait until next ms multiple function which takes as input a millisecond
multiple which is the input that specifies how many milliseconds lapse when the VI runs and
returns the value of the millisecond timer after the wait. The subsequent steps for building this
desired VI are given below:

i. Open a new front panel by selecting the New VI button from the startup window and then
double click on “Blank VI” to open the window.
ii. View the front panel and block diagram windows side by side by choosing Tile Left and
Right from the Window menu.
iii. Make the Front panel window the active window by clicking anywhere on it and select a
Toggle switch (Power), a Knob (Loop delay) and a Waveform chart (Random signal) from
the Buttons subpalette of the Controls palette, the Numeric controls subpalette of the
Controls palette and the Graph indicators subpalette of the Controls palette respectively.
iv. Now make the Diagram window the active window by clicking anywhere on it and select
a While loop, a Multiply function, a Numeric constant, a Random number function and a
Wait until next ms multiple function respectively from the Structures subpalette of the
Programming library of the Functions palette, the Numeric subpalette of the Mathematics
library of the Functions palette and the Timing subpalette of the Programming library of
the Functions palette.
v. Using the Wiring Tool from the Tools palette, wire the icons as shown in the block
diagram below.

Figure 2: Front panel and Block diagram of Experiment 2

Discussion: In this experiment we can delay the generation of random data by changing the loop
delay of the while loop using the Loop delay timer. Though the random numbers generated each
are within the range from 0 to1 it can be expanded by multiplying a constant to the output of the
random number generator. The loop used in this experiment is an infinite loop so that when we
run the VI it generate random numbers continuously until the switch is turned off.

Experiment 3

Objective: In this experiment the VI is designed to access values from previous iterations by the
use of shift registers.

Procedure: The Front panel of the VI contains four Digital indicators (Numeric indicators). The
X(i) indicator will display the current value, which will shift to the left terminal at the beginning
of the next iteration. The X(i-1) indicator will display the value one iteration ago, the X(i-2)
indicator will display the value two iterations ago and so on. It also has a Stop button. On the other
hand the block diagram contains the corresponding terminals of the Digital indicators and Stop
button, four shift registers, one Add function, three Numeric constants, one Wait until next ms
multiple function and a while loop. The subsequent steps for building this desired VI are given
below:
i. Open a new front panel by selecting the New VI button from the startup window and then
double click on “Blank VI” to open the window.
ii. View the front panel and block diagram windows side by side by choosing Tile Left and
Right from the Window menu.
iii. Make the Front panel window the active window by clicking anywhere on it and select
four numeric indicators and a Stop button from the Numeric indicators subpalette of the
Controls palette and the Buttons subpalette of the Controls palette respectively.
iv. Now make the Diagram window the active window by clicking anywhere on it and select
one Add function, three Numeric constants, one Wait until next ms multiple function and
a While loop structure from the Numeric subpalette of the Mathematics library of the
Functions palette, the Timing subpalette of the Programming library of the Functions
palette and the Structures subpalette of the Programming library of the Functions palette
respectively. A shift register can be added to the loop by popping up on the while border
and selecting shift register. To increase the number of registers pop up on the shift register
on the left and select add elements.
v. Using the Wiring Tool from the Tools palette, wire the icons as shown in the block diagram
below.
Discussion: In this example, the VI retains only the last three values. To retain more values,
more elements can be added to the left terminal of the shift register. The rate of shifting can easily
be varied by varying the input to the loop delay unit.

Figure 3: The Front panel and Block diagram of Experiment 3

Experiment 4

Objective: In this experiment the VI is designed to check whether a number is positive or not
and then calculate the square root of the number otherwise, the VI returns a message.

Procedure: The Front panel of the VI contains one Numeric control and one Numeric indicator.
On the other hand the block diagram contains the corresponding terminals of the Numeric control
and indicator, one Greater or Equal to 0? Function, one Square Root function, one Numeric
Constant, One Button Dialog function and one String Constant. The subsequent steps for building
this desired VI are given below:
i. Open a new front panel by selecting the New VI button from the startup window and then
double click on “Blank VI” to open the window.
ii. View the front panel and block diagram windows side by side by choosing Tile Left and
Right from the Window menu.
iii. Make the Front panel window the active window by clicking anywhere on it and select one
Numeric control and one Numeric indicator from the Numeric controls subpalette of the
Controls palette and the Numeric indicators subpalette of the Controls palette respectively.
iv. Now make the Diagram window the active window by clicking anywhere on it and select
one Greater or Equal to 0? Function, one Square Root function, one Numeric Constant,
One Button Dialog function and one String Constant from the Comparison subpalette of
the Programming library of the Functions palette, the Numeric subpalette of the
Mathematics library of the Functions palette, the Dialog & user interface subpalette of the
Programming library of the Functions palette and the Strings subpalette of the
Programming library of the Functions palette respectively.
v. Using the Wiring Tool from the Tools palette, wire the icons as shown in the block
diagram below.

Figure 4: The front panel and block diagram for Experiment 4

Discussion: In this experiment, the VI will execute either the True case or the False case. If the
number is greater than or equal to zero, the VI will execute the True case. The True case returns
the square root of the number. The False case outputs a -99999.0 and displays a dialog box with
the message “Error...Negative Number”.
Experiment 5

Objective: In this experiment the VI is designed to convert a number to a string and concatenate
the string to other strings to form a single output string. It is also designed to determine the output
string length and to test if a password matches a given password.

Procedure: The Front panel of the VI contains three String controls, one Numeric control, two
String indicator, one Numeric indicator and one LED.
On the other hand the block diagram contains the corresponding terminals of the Numeric controls
and indicators, one Format Into String function which converts the number specified in the digital
control to a string, one Concatenate Strings function which concatenates all input strings into a
single output string. To increase the number of inputs, resize the function using the Positioning
tool, one String Length function which returns the number of characters in the concatenated string
and a Case structure. The subsequent steps for building this desired VI are given below:
i. Open a new front panel by selecting the New VI button from the startup window and then
double click on “Blank VI” to open the window.
ii. View the front panel and block diagram windows side by side by choosing Tile Left and
Right from the Window menu.
iii. Make the Front panel window the active window by clicking anywhere on it and select
three String controls, one Numeric control, two String indicator, one Numeric indicator
and one LED from the String controls subpalette of the Controls palette, the Numeric
controls subpalette of the Controls palette, String indicators subpalette of the Controls
palette, the Numeric indicators subpalette of the Controls palette and LEDs subpalette of
the Controls palette.
iv. Now make the Diagram window the active window by clicking anywhere on it and select
one Format Into String function, one Concatenate Strings function, one String Length
function and a Case structure from the String subpalette of the Programming library of the
Functions palette and the Structures subpalette of the Programming library of the Functions
palette respectively.
v. Using the Wiring Tool from the Tools palette, wire the icons as shown in the block diagram
below.

Discussion: In this experiment the VI is able to add a specific number of strings and variables
together. The LED blinks when a match is found in password.
Figure 5.1: Front panel of Experiment 5

Figure 5.2: Block diagram of Experiment 5 when password matched


Figure 5.3: Block diagram of Experiment 5 when password not matched

Experiment 6

Objective: In this experiment the VI is designed to write data to a file.


Procedure: The Front panel of the VI contains two String control, one Numeric control and one
File path indicator to indicate location of the file which can be selected in run time. On the other
hand the block diagram contains the corresponding terminals of the String controls, Numeric
control and File path indicator, one Build String.vi which concatenates the three input strings to
one combined string, one Open/Create/Replace File VI which displays an interactive file dialog
box to open or create or replace a file, one Write File function which writes the concatenated
strings to the file, one Close File function which closes the file, one String constant, one Enum
constant to create a list of string labels with corresponding integer values which can be selected on
the Block diagram and one Simple error handler.vi to indicate whether an error occurred and when
an error occurred, this VI returns a description of the error and optionally displays a dialog box.
The subsequent steps for building this desired VI are given below:
i. Open a new front panel by selecting the New VI button from the startup window and then
double click on “Blank VI” to open the window.
ii. View the front panel and block diagram windows side by side by choosing Tile Left and
Right from the Window menu.
iii. Make the Front panel window the active window by clicking anywhere on it and select two
String controls, one Numeric control and one File path indicator from the String controls
subpalette of the Controls palette, the Numeric controls subpalette of the Controls palette
and Text indicators subpalette of the Controls palette respectively.
iv. Now make the Diagram window the active window by clicking anywhere on it and select
one Build String.vi, one Open/Create/Replace File VI, one Write File function, one Close
File function, one string constant, one enum constant and one Simple error handler.vi from
the “Select a VI” option of the Functions palette, the File I/O subpalette of the
Programming library of the Functions palette, the String subpalette of the Programming
library of the Functions palette, Numeric subpalette of the Mathematics library of the
Functions palette and the Dialog and user interface subpalette of the Programming library
of the Functions palette respectively.
v. Using the Wiring Tool from the Tools palette, wire the icons as shown in the block diagram
below.

Figure 6.1: Front panel of Experiment 6

Figure 6.2: Block diagram of Experiment 6


Discussion: From the block diagram it is evident that the VI is now working in the mode which
first create or replace a file and then writes data to the file. Others modes such as “open”, “open or
create”, “create”, “open (read only)” can also be selected by changing the labels in the enum
terminal of the Block diagram.

Experiment 7

Objective: In this experiment the VI is designed to read data from a file, displays the information
read in a string indicator and in a Numeric indicator if the information contains any number.

Procedure: The Front panel of the VI contains one File path indicator, one String indicator and
one Numeric indicator. On the other hand the block diagram contains the corresponding terminals
of the String indicator, Numeric indicator and File path indicator, one Open/Create/Replace File
VI, one Read File function, one Close File function, one Match Pattern Function which Searches
for regular expression in string beginning at offset, and if it finds a match, splits string into three
substrings, one Scan from string function which scans the input string and converts the string
according to format string, two String constants, one Enum constant and one Simple error
handler.vi. The subsequent steps for building this desired VI are given below:
i. Open a new front panel by selecting the New VI button from the startup window and then
double click on “Blank VI” to open the window.
ii. View the front panel and block diagram windows side by side by choosing Tile Left and
Right from the Window menu.
iii. Make the Front panel window the active window by clicking anywhere on it and select one
File path indicator, one String indicator and one Numeric indicator from the Text indicators
subpalette of the Controls palette, the String indicators subpalette of the Controls palette
and the Numeric indicators subpalette of the Controls palette respectively.
iv. Now make the Diagram window the active window by clicking anywhere on it and select
one Open/Create/Replace File VI, one Read File function, one Close File function, one
Match Pattern Function, one Scan from string function, two String constants, one Enum
constant and one Simple error handler.vi from the “Select a VI” option of the Functions
palette, the File I/O subpalette of the Programming library of the Functions palette, the
String subpalette of the Programming library of the Functions palette, Numeric subpalette
of the Mathematics library of the Functions palette and the Dialog and user interface
subpalette of the Programming library of the Functions palette respectively.
v. Using the Wiring Tool from the Tools palette, wire the icons as shown in the block diagram
below.

Figure 7.1: Front panel of Experiment 7

Figure 7.2: Block diagram of Experiment 7

Discussion: From the Block diagram we see that here the label “open” is selected so that the
Sub VI can open the file and read the information from it. Actually this is the desired label for this
experiment.
Experiment 8

Objective: In this experiment the VI is designed to blink an LED using Data Acquisition Card.
Procedure: The Front panel of the VI contains one VISA Resource Name Control which
specifies the resource to which a VISA session will be opened and to maintain the session and
class where a VISA session is a unique logical identifier used by VISA to communicate with a
resource and one LED. On the other hand the block diagram contains the corresponding terminals
of the VISA Resource Name Control and the LED, one DAQ-DO.vi, one Label Controller and a
while loop. The subsequent steps for building this desired VI are given below:
i. Open a new front panel by selecting the New VI button from the startup window and then
double click on “Blank VI” to open the window.
ii. View the front panel and block diagram windows side by side by choosing Tile Left and
Right from the Window menu.
iii. Make the Front panel window the active window by clicking anywhere on it and select one
VISA Resource Name Control and one LED from the I/O subpalette of the Modern library
of the Controls palette and from the Buttons subpalette of the Controls palette respectively.
iv. Now make the Diagram window the active window by clicking anywhere on it and select
one DAQ-DO.vi from the “Select a VI” option of the Functions palette, one Label
Controller by popping up on the DAQ-DO.vi and select Create and then select Constant
and finally select one While loop from the Structures subpalette of the Programming library
of the Functions palette.
v. Using the Wiring Tool from the Tools palette, wire the icons as shown in the block diagram
below.

Figure 8.1: Front panel of Experiment 8


Figure 8.2: Block diagram of Experiment 8

Discussion: It should be noted that when the switch is on the DAQ card only passes a single
pulse to the digital output pin specified in the label controller. So the LED blinks only for a little
time and therefore to see the LED blinking an infinite while loop must be used. Further through
which port the card is connected to the PC that port should be selected in the VISA Resource Name
Controller terminal in the front panel.

You might also like