Virtual Instrumentation Lab Manual
Virtual Instrumentation Lab Manual
DEPARTMENT OF MECHATRONICS
ENGINEERING
NAME…………………………………………
………………….
USN……………………………………………
…………………..
SEMESTER……………………………………
…………………
BATCH
NO………………………………………………
……...
1
CONTENTS
0 Introduction to LabVIEW 3
2 Modular programming 7
5 Structures 13
6 Arrays 14
2
EXPERIMENT NO. : 0 DATE:
Introduction to LabVIEW
3
simulate instrument output devices and display data the block diagram acquires or
generates. After the front panel is build, add code 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.
Block diagram - Contains the graphical source code that defines the functionality of VI.
Icon and connector panel - Identifies the VI so that the VI can be used in another VI. A
VI within another VI is called a subVI. A subVI corresponds to a subroutine in text-based
programming languages. Additionally, the block diagram contains functions and
structures from built-in LabVIEW VI libraries. Wires connect each of the nodes on the
block diagram, including control and indicator terminals, functions, and structures.
LabVIEW Palettes- LabVIEW palettes give provide the options needed to create and edit
the front panel and block diagram. The Tools palette is available on the front panel and the
block diagram. A tool is a special operating mode of the mouse cursor. By selecting a tool,
the cursor icon changes to the tool icon. Use the tools to operate and modify front panel and
block diagram objects. Select Window » Show Tools Palette to display the Tools palette.
The Tools palette can be placed anywhere on the screen. If automatic tool selection is
enabled and as the cursor is moved over objects on the front panel or block diagram,
LabVIEW automatically selects the corresponding tool from the Tools palette.
The Controls palette: The Controls palette is available only on the front panel. The Controls
palette contains the controls and indicators used to create the front panel. to display the
Controls palette, Select Window » Show Controls Palette or right-click the front panel
workspace. The Controls palette can be placed anywhere on the screen.
The Functions palette: The Functions palette is available only on the block diagram. The
Functions palette contains the VIs and functions used to build the block diagram. To display
the Functions palette, select Window » Show Functions Palette or right-click the block
diagram workspace. The Functions palette can be placed anywhere on the screen.
Dataflow Programming: LabVIEW follows a dataflow model for running VIs. A block
diagram node executes when all its inputs are available. When a node completes execution, it
supplies data to its output terminals and passes the output data to the next node in the
dataflow path. Procedure:
1. Open NI LabVIEW and press <Ctrl_N> to open a blank VI.
2. Press <Ctrl_T> to tile front panel and block diagram windows.
4
EXPERIMENT NO. : 1 DATE:
Step 1: Select controls by right clicking on the front panel and choose the specific type of
control similarly choose indicators.
Step 2: Different operators such as addition, subtraction, multiplication, less than, greater
than, Boolean, etc can be performed by right clicking on block diagram.
Step 3: Using wires inputs and outputs are connected to the respective operators in the
block diagram panel.
Step 4: Enter the input values in front panel.
Step 5: Observe the output by performing single step and continuous mode execution.
5
Example 3. Execute a VI to perform the operation Y=(A*B*C)+(D*E) and y=mx+c
6
EXPERIMENT NO. : 2 DATE:
Modular programming
Instructions:
A. Creating SubVI
Step 1: Build a VI with front panel and block diagram
Step 2: Assign terminals to control and indicators using control panel.
Step 3: Create icon
Step 4: Save the file with extension .vi
Step 5: Call the file in the main program using ‘select vi’ option in block diagram pane.
Step 6: If multiple SubVI are to be used group can be saved as .llb (LabVIEW library).
Half adder: A half-adder is an arithmetic circuit block that can be used to add two bits. Such
a circuit thus has two inputs that represent the two bits to be added and two outputs, with one
producing the sum output and the other producing the carry.
7
Full adder:
A full adder circuit is an arithmetic circuit block that can be used to add three bits to
produce a sum and a carry output.
8
Example 2. Create a VI to find the decimal equivalent of a binary number using subVI.
9
Example 3: Create a VI to find the grey code equivalent of a BCD number using subVIs.
10
Example 4: Create a VI to find the roots of a quadratic equation using subVIs. Find both the values of
the roots and nature of the roots.
11
Example 5: Create a VI to find the average of two numbers and convert a section of a VI into a
subVI.
12
13
EXPERIMENT NO. : 3 DATE:
Instructions:
A. While loop: to be used when condition needs to be checked after an iteration.
Step 1: In block diagram panel, right click and select ‘Programming’>> ‘structures’
>> ‘while loop’.
Step 2: choose the terminating condition.
B. For loop: to be used when condition needs to be checked before every iteration.
Step 1: In block diagram panel, right click and select ‘Programming’ >> ‘Structures’
>> ‘for loop’.
Step 2: Assign the number ‘N’, which means number of times loops should be execute.
Example 1. Creating Virtual Instrumentation for simple applications- invert the state of
boolean indicator twice a second until program is stopped by user.
14
Example 2. Programming exercises for loops in virtual instrumentation-Continuous
Monitoring of Temperature (Generated using Random no 0<t<100 ). for every 250 ms.
15
Example 4: Create a VI to find the sum of first “n” natural numbers using a while loop with a
feedback node.
Example 5: Create a VI to find the sum of first “10” natural numbers using a for loop.
16
Example 6: Create a VI which converts a decimal number to binary number using for loops.
17
EXPERIMENT NO. : 4 DATE:
Example 1. Programming exercises for graphs- Display Random Number Into 3 different
CHARTS (STRIP, SLOPE,SWEEP) and understand the difference between these in the UI.
18
EXPERIMENT NO. : 5 DATE:
Structures
Theory:
Structures are used in block diagram to repeat blocks of code and to execute code
conditionally or in a specific order. Section of block diagram inside the structure border is
called ‘subdiagram’. The terminals that feed data into and out of structures are called
‘tunnels’. Following structures can be used in LabVIEW
1. Loop’s
2. Case structure
3. Sequence structure
4. Event structure
5. Timed structure
6. Diagram disable structure
7. Conditional disable structure
To add structures right click on block diagram, select ‘programming’>> ‘structures’.
Example 1. Programming Exercises on case and sequence structures:-Design the simple Calculator,
making use of the inherent GUI present in the virtual instrumentation software.
19
EXPERIMENT NO.: 6 DATE:
Arrays
Aim: To perform the array operations in LabVIEW
Instructions:
Creating a one-dimensional array control/indicators/constant
Step 1: In front panel right click >>’Controls’ >> ‘Modern’>>’Array, Matrix & Clusters
palette’.
Step 2: Insert an object in the array. The array data type will be assigned as that of the
object inserted.
Step 3: To create multidimensional array, Right click on array and select ‘Add
Dimension’.
Step 4: From the array particular set of elements can be made visible by varying the
values of ‘index’ provided next to array.
Example 1. Programming Exercises on Arrays– Take a 2D array input from the user and perform
various array (and matrix) manipulations on it.
1. Display array inputs to corresponding outputs
20
Example 2. Sorting even numbers using while loop in an array.
21
Example 4. Create a VI to find the determinant of 2*2 and 3*3 matrix which is represented in the
form of 2D array using Index array function.
22
EXPERIMENT NO. : 7 DATE:
Example 1. Programming Exercises on File Input output System – Read and write from ASCII and
TDMS files
23
Read and write from ASCII file:
24
Read and write from TDMS file:
25