Professional Documents
Culture Documents
Faculty of Engineering
Biomedical Engineering Department
Virtual Instruments
Lab view programs are called virtual instruments or VIs, every VI uses functions that
manipulate input from the user interface or other sources and display that information or
move it to other files or other computers.
1. Front Panel:
It's the user interface of the VI. Figure 7.1 shows an example of a front panel.
You build the front panel with controls and indicators, which are the interactive input and
output terminals of the VI respectively. Controls are Knobs, Push buttons, and other input
devices. Indicators are Graphs, LED's 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.
2. Block Diagram:
After you build the front panel, you add code using graphical representation of functions to
control the front panel objects. The block diagram contains this graphical source code. Front
panel appear as terminals on the block diagram, Figure 7.2 shows several primary block
diagram objects: Terminals, functions and wires.
Page 1
Jordan University of Science and Technology
Faculty of Engineering
Biomedical Engineering Department
Lab view environment consists of three palettes: the functions, controls and tools palettes.
1. Controls Palette:
The controls palette is available only on the front panel. It contains the front panel controls
and indicators you use to create the user interface. Right click the front panel to Display the
controls palette.
2. Functions Palette:
It’s available only on the block diagram and it contains the objects you use to program your
VI, such as arithmetic, instrument I/O, file I/O and data acquisition operations And functions.
Right click the block diagram to display the function palette.
3. Tools Palette.
It’s available on the front panel and the
Block diagram. A tool is a special operating mode of the mouse cursor, when you select a
tool, the cursor icon changes to the tool icon, Use the tools to operate and modify front panel
and block diagram objects. Select view>> Tools Palette to display the tools palette.
Page 2
Jordan University of Science and Technology
Faculty of Engineering
Biomedical Engineering Department
The Controls and Functions Palette appear with a thumbtack icon in the left corner.
Click the thumbtack to pin the palette so it is no longer temporary.
Exercise 1
Complete the following steps to create a VI that calculates the slope between two X-Y pairs.
Front Panel:
Page 3
Jordan University of Science and Technology
Faculty of Engineering
Biomedical Engineering Department
*Lab View creates corresponding control and indicator terminals on the block diagram.
Block diagram:
prototype in text-based programming languages. Every VI displays an icon in the upper right
corner of the front panel and block diagram windows.
1. Right click the icon on the upper right corner of the front panel and select show
connector from the shortcut menu to define the connector pane terminal pattern.
2. Assign the terminal to the digital controls and indicators as follows:
a. Click the left terminal in the connector pane, the tool automatically changes to the
wiring tool and the terminals turns black, and then clicks the X1 control, the left
terminal changes orange. Repeat for X2, Y1 and Y2.
b. Click the right terminal in the connector pane and click the slope (m) indicator. The
right terminal turns orange.
Exercise 2
Build a VI that generates a random number between 0.0 and 10.0 and divides the random
number by a number specified on the front panel. If the number input is 0, the VI should turn
on a front panel LED to indicate a divide by zero error.
Page 5
Jordan University of Science and Technology
Faculty of Engineering
Biomedical Engineering Department
While Loop:
A while loop executes the sub diagrams until the conditional terminal (an input terminal) is
met (receives a specific Boolean value). The default behavior of the conditional terminal is
Stop if true, the while loop executes its sub diagram until the conditional terminal receives a
true value, the output terminal (iteration) contains the number of completed iterations, the
iteration count always starts at zero.
Complete the following steps to build a VI that generates integer random numbers (0-10)
until the number generated matches a number you specify in the front panel. The loop count
terminal records the number of iterations before a match occurs.
Front Panel:
1. Open a new front panel.
2. Build the following front panel and modify the controls and indicators as shown.
*The number to match control specifies the number you want to match.
*The current number indicator displays the current random number.
*The # of iterations indicator displays the number of iterations before a match.
Block diagram:
1. Build the following block diagram.
Page 6
Jordan University of Science and Technology
Faculty of Engineering
Biomedical Engineering Department
Random
Number
While Loop
Round to nearest
Iteration Number
Tunnel Conditional
Terminal
Figure (8.2): Auto match VI block diagram
*How to translate the question (text based) into graphical representation (source
code)??
2. The round to nearest function rounds the random number to the nearest integer.
3. The not equal function compares the random number with number to match and
returns true if the numbers are not equal; otherwise, it returns false.
4. The tunnel feed data into and out of the while loop structure, data pass out of a loop
after the loop terminates. You can read and process every element after each iteration by
enabling auto indexing (right click the tunnel and select enable indexing)
Disable auto indexing by right clicking the tunnel and selecting disable indexing from the
shortcut menu. For example, disable auto indexing if you need only the last value passed to
the tunnel.
5. The loop executes while no match exists. That is, the not equal function returns
TRUE if the two numbers not match. Each time the loop executes the iteration terminal
increments by one. The iteration count passes out of the loop upon completion. This value
Page 7
Jordan University of Science and Technology
Faculty of Engineering
Biomedical Engineering Department
increments by one outside the loop because the count starts at zero. (You can change the
behavior of the conditional terminal by right –clicking the terminal and selecting Continue if
true).
Complete the following steps to build a VI that selects between two numbers and display it
on a waveform chart until the stop button is pressed. Figure (8.3): Temperature monitor VI
*
The Select Function returns the value wired to the t input or f
input, depending on the value of s. If s is TRUE, this function
returns the value wired to t. If s is FALSE, this function returns
the value wired to f.
* The while loop executes temperature acquiring every one second until the
power is off.
For Loop:
Executes its sub diagram N times. For loop has two numbers associated with - the
Termination count (N is the upper left corner) which is the total number of times the for loop
runs before terminating and the iteration count (i in the lower left corner).
Page 8
Jordan University of Science and Technology
Faculty of Engineering
Biomedical Engineering Department
Case structure:
A case structure has two or more sub diagrams or cases. Only one sub diagram is
visible at a time. And the structure executes only one case at a time. An input value
determines which sub diagram executes.
The case selector identifier at the top of the case structure contains the case
selector identifier in the center and decrement and increment arrow buttons on each side. Use
the decrement and increment arrow buttons to scroll through the available cases.
Wire an input value or selector to the selector terminal to determine which case executes.
You can wire an integer, Boolean value or string. If the selector terminal is Boolean, the
structure has a TRUE case and a FALSE case.
Right click the case structure border to add duplicate, remove or rearrange cases and to
select a default case (you must specify a default case).
In the following example, the numbers a and b are either added or subtracted depending on
the value wired to the selector terminal.
Page 9
Jordan University of Science and Technology
Faculty of Engineering
Biomedical Engineering Department
If the Boolean control wired to the selector terminal is true, the VI adds the numbers,
otherwise the VI subtracts the numbers.
Page 10
Jordan University of Science and Technology
Faculty of Engineering
Biomedical Engineering Department
Experiment # 9
Shift Register and Arrays
Shift Register
Use shift register on for loops and while loops to transfer values from one loop to the next,
create a shift register by right clicking the left or right border of a loop and selecting add
shift register from the shortcut menu.
You can use shift register to remember values from previous iterations. This technique is
useful for averaging data points. To configure a shift register to carry more than one value to
the next iteration, right click the left terminal and select add element from the shortcut menu.
To initialize a shift register, wire any value from outside the loop to the left terminal. If you
don't initialize the register, the loop uses the value written to the register when the loop last
executed or the default value for the data type if the loop has never executed. For example, if
the shift register data type is Boolean, the initial value is false. Similarly, if the shift register
data type is numeric, the initial value is 0.
Page 11
Jordan University of Science and Technology
Faculty of Engineering
Biomedical Engineering Department
* The Xi indicator displays the current value), which shifts to the left terminal at the
beginning of the next iteration. The X (i-1) indicator displays the value one iteration ago, the
X (i-2) indicator displays the value two iterations ago, and so on.
* The 0 wired to the left terminal initializes the elements of the shift register to 0.
*In each iteration of the while loop, the VI transfers the previous values through the left
terminals of the shift register. Each iteration of the loop adds 5 to the current data, Xi .this
value shifts to the left terminal, X (i-1), at the beginning of the next iteration. The values at
the left terminal tunnel downward through the terminals. This VI retains the last three values.
*The output of the first iteration is: Xi=5,X(i-1) =0 ,X(i-2) =0 ,X(i-3) =0.The second iteration
is: Xi=10,X(i-1) =5 ,X(i-2) =0 ,X(i-3) =0 and so on.
Arrays
Arrays group data elements of the same type. An array consists of elements and dimensions.
Elements are the data that make up the array; a dimension is the length, height or depth of
an array. An array can have one or more dimensions.
An array uses an index so you can readily access any particular element. The index is zero
based, which means it is in the range 0 to n-1.where n is the number of elements in the array.
Page 12
Jordan University of Science and Technology
Faculty of Engineering
Biomedical Engineering Department
Column Index
0 1 2
0
1
Row Index 2
3
To add dimension to an array one at a time, right click the index display and select add
dimension.
Auto-indexing:
Page 13
Jordan University of Science and Technology
Faculty of Engineering
Biomedical Engineering Department
If you wire an array to a for loop or while loop input tunnel, you can read and process every
element in that array by enabling auto indexing. When you auto index an array output tunnel,
the output array receives a new element from every iteration of the loop.
Disable auto indexing by right clicking the tunnel and selecting disable indexing from the
shortcut menu. For example, disable auto indexing if you need only the last value
Passed to the tunnel.
Build a VI that first accumulates an array of temperature values using the digital
thermometer VI. Incorporate these items:
Page 14
Jordan University of Science and Technology
Faculty of Engineering
Biomedical Engineering Department
Experiment #10
Lab view includes a set of VI’s that let you configure, acquire data from and send data to
DAQ devices, often one device can perform a variety of functions: analog to digital
conversion, digital to analog conversions and digital I/O.
Exercise #2:
Objective: Using measurement and automation explorer to examine the current DAQ
configuration and adding one virtual channel.
1. Start measurement and automation explorer by selecting tools>>measurement and
automation in lab view; the utility searches your system for installed national
instruments hardware and displays the information. Expand the devices and interfaces
section to view the installed NI devices.
2. Configuring Channels on the DAQ device by right click the Data Neighborhood icon
and select create new, select virtual channel and click the finish button.
3. Enter the necessary information in the panels that appear to configure a channel to take a
reading from a pulse pletheysmograph sensor (analog input and channel 0).
4. Open a new VI and build the following Block diagram:
Page 15
Jordan University of Science and Technology
Faculty of Engineering
Biomedical Engineering Department
Figure (10.2)
IIR specifications:
* Design type of the filter:
Butterworth.
* Type of the filter: Low Pass.
* Order of the filter: third order.
* Lower Cutoff frequency: 0.
* Upper cutoff frequency: 10.
7. Write the data acquired from the analog input channel to a specified file (excel format)
using Export waveforms to spreadsheet file VI.
8. Reopen the file in Microsoft Office Excel.
Page 16
Jordan University of Science and Technology
Faculty of Engineering
Biomedical Engineering Department
File I/O operations pass data to and from files. Use the File I/O VIs and functions located on
the Programming » File I/O palette to handle all aspects of file I/O, including the following:
File Formats
The file formats that are supported by the File I/O functions are:
LVM (Lab VIEW Measurement) which are text files that contain data that can be read by
a human being because numbers are represented as text. For example, the number 0.231
is stored as the text (or string) "0.231". A large benefit of storing numerical data in the
text format is that the file can be opened and displayed in any tool that supports text files,
e.g. MS Word, Notepad, Excel, MATLAB, Web browsers. (It may be necessary to
change the file name extension from lvm to e.g. txt or dat before opening the file in such
tools). Thus, text files provide great portability. However, the text files will be larger than
if the data were written in a binary format, and the data are stored with less accuracy, but
Page 17
Jordan University of Science and Technology
Faculty of Engineering
Biomedical Engineering Department
these issues are not important on ordinary PC's, but may be important on dedicated
computers with limited storage.
TDMS (Technical Data Management - Streaming) which are binary files in an internal
Lab VIEW file format. The TDMS format gives more effective and accurate data storage
than the LVM format. TDMS files may be opened in Lab VIEW, of course, and in NI
DIAdem which is a software tool for managing, analyzing, and reporting data in log files.
TDMS files can save data in an organized way using a number of Groups and a number
of Channels within a given Group. (The older TDM file format is still supported).
Spreadsheet Files (Excel): which are compatible to MS Excel spreadsheet files. With
Lab VIEW we can write data to an Excel spreadsheet file and read data from an Excel
spreadsheet file.
Build a VI that reads a Spreadsheet file of a “Pulse Signal” acquired by Lab Scribe Software.
1. Select “Read From Spreadsheet File.vi” from Programming > File I/O palette.
2. Determine the path of the required file. (The Path is found from the front panel located on
the All Controls» String & Path» File Path Control).
3. Split the output signals into X input (Time) and Y input (Pulse amplitude).
4. Plot the signal on XY Graph.
Page 18
Jordan University of Science and Technology
Faculty of Engineering
Biomedical Engineering Department
Array Size
The Array Size Function returns the number of elements in an array it is wired to.
Initialize Array
Initialize Array crates an array of dimension size elements containing the element value.
Build Array
Page 19
Jordan University of Science and Technology
Faculty of Engineering
Biomedical Engineering Department
Array Subset
Array Subset returns a portion of an array starting at index and containing length elements.
Page 20