You are on page 1of 20

Jordan University of Science and Technology

Faculty of Engineering
Biomedical Engineering Department

Experiment #7: Introduction to Lab VIEW

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.

A VI contains the following three components:

1. Front Panel: user interface.


2. Block diagram: Contains the graphical source code that defines the functionality of the VI.
3. Icon and connector pane: identifies the VI so that you can use the VI in another VI (a Sub
VI).

1. Front Panel:

It's the user interface of the VI. Figure 7.1 shows an example of a front panel.

Figure (7.1): 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

Figure (7.2): Example of a block diagram

Lab view Environment

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

Figure (7.3): Tools Palette

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:

1. Select file >>new to open a new front panel.


2. Create four numeric digital controls (right click the panel>>numeric>>digital control) and
type X1, X2, Y1 and Y2 inside each label.
3. Create a numeric digital indicator and type Slope (m) inside the label.

Page 3
Jordan University of Science and Technology
Faculty of Engineering
Biomedical Engineering Department

Figure (7.4): Slope VI front panel

*Lab View creates corresponding control and indicator terminals on the block diagram.

Block diagram:

Figure (7.5): Slope VI block diagram

1. Display the block diagram by selecting window>>show diagram.


2. Select subtract and divide functions on the functions numeric palette.
3. Use the wiring tool to wire the icons as shown in the previous block diagram.
4. Enter numbers in the digital controls (front panel) and run the VI

3. Icon and Connector Pane:


After you build a VI front panel and block diagram, build the icon and the connector pane so
you can use the VI as a SubVI. The icon and connector pane correspond to the function
Page 4
Jordan University of Science and Technology
Faculty of Engineering
Biomedical Engineering Department

prototype in text-based programming languages. Every VI displays an icon in the upper right
corner of the front panel and block diagram windows.

Creating the Icon:


1. Use Icon Editor to design the icon. From the Panel or Diagram window, right-click on the
icon and select "Edit Icon".
2. Double-click on Select tool and press delete to clear icon.
3. Double-click on Rectangle tool to add border around icon.
4. Keep it simple.

Creating the Connector:

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.

Figure (7.6): Creating a Sub VI

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

Experiment #8: Loops & Structures

Structures are graphical representation of loops and case statements of test-based


programming languages.

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.

Exercise # 1: Auto Match VI

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.

Figure (8.1): Auto match VI front panel

*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)??

1. The random number function produces a random number between 0 and 1,


multiply the random by 10 to produce random numbers between 0 and 10.

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).

Exercise # 2: Temperature monitor VI

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).

Exercise #3: Boolean Case Structure

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

Figure (8.4): Boolean Case Structures

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

Accessing Previous Loop - Data 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.

Exercise #1: Shift Register Example VI

1. Build the following front panel.

Figure (9.1): Shift register exercise front panel

2. Display the following block diagram:

Page 11
Jordan University of Science and Technology
Faculty of Engineering
Biomedical Engineering Department

Figure (9.2): Shift register exercise block diagram

* 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.

* Click the highlight Execution button to enable execution step by step.

*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.

*Creating 1D array of random numbers (0-1):


Front Panel: Select an array on the controls>>arrays and cluster palette, place it on the
front panel and drag a control or indicator into the array shell.

Page 12
Jordan University of Science and Technology
Faculty of Engineering
Biomedical Engineering Department

Figure (9.3): 1D array front panel

Block diagram: Build the following block diagram

Figure (9.4): 1D array block diagram


2D array stores elements in a grid, it requires a column index and a row index to locate an
element, both of which are zero based.

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.

*Creating 2D arrays of random numbers (0-1):


You can use two for loops, one inside the other to create a 2D array. The outer loop creates
the row elements and the inner loop creates the column elements.

Figure (9.5): 2D array examples

Exercise #2: Array functions

Build a VI that first accumulates an array of temperature values using the digital
thermometer VI. Incorporate these items:

* Set the array size with a control on the front panel.


* Initialize an array using the initialize array function of the same size where all values are
equal to 10.
* add the two arrays, calculate the size of the final array and extract the middle value from
the final array.
* display the temperature array, initialized array, final array and mid value.

Page 14
Jordan University of Science and Technology
Faculty of Engineering
Biomedical Engineering Department

Experiment #10

Data Acquisition Devices in Lab VIEW

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.

Figure (10.1): Data acquisition system

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)

5. Display the front panel, and run the VI.


6. To remove noise from the output waveform, Add digital filter (use Digital IIR Filter.vi)
as shown below:

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.

Figure (10.3): Digital IIR filter

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

Figure (10.4): Export waveform to spreadsheet file

Lab VIEW File I/O


When conducting experiments with equipment it is important to record data for analysis and
calibration of instruments. Lab VIEW has several functions for writing data to files – both
continuous writing (online, while the VI runs) and batch (offline) writing. Lab VIEW has also
functions for reading data in such log-files. These functions are available on the
Programming > File I/O palette.

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:

• Opening and closing data files.


• Reading data from and writing data to files.
• Reading from and writing to spreadsheet-formatted files.
• Moving and renaming files and directories.
• Changing file characteristics.
• Creating, modifying, and reading a configuration file.

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.

Exercise #3: Reading Data from 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

Build Array links multiple arrays. It appends elements to an array.

And it concatenates multiple arrays

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

You might also like