Arithmetic and logical operations
Aim: To perform basic arithmetic and logical operations using LabVIEW.
Instructions:
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.
Example 1. Execute a VI to perform the operation of y=3x+4.
Example 2. Execute a VI to perform the operation of checking a given number is odd or even
Example 3. Execute a VI to perform the operation Y=(A*B*C)+(D*E) and y=mx+c
2
Example 4. Execute a VI to Convert Celsius to Fahrenheit.
Hint: F= (1.8C+32)
3
Modular programming
Aim: To perform modular programming in LabVIEW.
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).
B. Creating EXE from a VI
Step 1: Right click ‘build specifications’ in the ‘project explorer’ window and select
‘New’>> ‘Application (EXE)’ from the shortcut menu
Step 2: Modify the file name of the target and destination directory for the application in the
‘Application Information category’.
Step 3: Select the ‘Application Information category’.
Step 4: Change the target filename to your ‘filename .exe’.
Example 1. Execute a VI to perform half adder and full adder.
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.
4
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.
5
6
Example 2. Create a VI to find the decimal equivalent of a binary number using subVI.
7
Example 3: Create a VI to find the grey code equivalent of a BCD number using subVIs.
8
9
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.
10
Example 5: Create a VI to find the average of two numbers and convert a section of a VI into a subVI.
11
12
Loops and shift registers
Aim: To perform the operation using loops in LabVIEW.
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.
Example 2. Programming exercises for loops in virtual instrumentation-Continuous Monitoring of
Temperature (Generated using Random no 0<t<100 ). for every 250 ms.
13
Example 3. Programming exercises for loops in virtual instrumentation-Factorial of a given number
using for loop and shift registers.
Example 4: Create a VI to find the sum of first “n” natural numbers using a while loop with a feedback
node.
14
Example 5: Create a VI to find the sum of first “10” natural numbers using a for loop.
Example 6: Create a VI which converts a decimal number to binary number using for loops.
15
Example 4: Create a VI to find 𝑛𝐶 𝑟 and 𝑛𝑃 𝑟 of a given number using for loop.
16
Clusters and graph & chart
Aim: To perform the operation on clusters and graphs in LabVIEW.
Clusters are group of data with element of mixed type.
Instructions:
To create clusters, select cluster by right clicking in front panel and select ‘controls’>>’All
controls’>>’Arrays & cluster palette’, place it on front panel. Drag and drop objects or elements
into the cluster.
Plotting Data:
1. Graph: display typical data
2. Chart : displays data at continuous rate
a. Strip chart: shows continuous data and continuously scroll from left to the right
b. Scope chart: shows one item, and scroll partway across left to right.
c. Sweep chart: shows old data on right and new data on left.
3. XY graph: two dimension plot
4. 3D plot
5. Intensity graph:
Right click on front panel, select ‘graphs and charts’.
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.
17
18
Structures
Aim: To perform the operation on structures in LabVIEW.
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
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
Example 2. Sorting even numbers using while loop in an array.
20
Example 3. To find the maximum and minimum variable from an array.
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.
21
22
Strings and File I/O
Aim: To perform the operations on strings and file I/O in LabVIEW.
Theory:
String is a sequence of displayable or non-displayable ASCII characters.
String control and indicator is located on the ‘Controls’>> ‘Text controls’>>’Text indicators
palettes’ in the front panel.
File I/O records or reads data in a file. Functions related to file I/O is located by right clicking
the block diagram ‘Functions’>>’All functions’>> ‘File I/O’.
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