0% found this document useful (0 votes)
60 views16 pages

Experiment #1: Introduction To Lab VIEW: Part 1: Virtual Instruments

This document provides an introduction to LabVIEW and its components. It discusses: 1. Virtual instruments (VIs) in LabVIEW contain a front panel, block diagram, and icon/connector pane. The front panel acts as the user interface, the block diagram contains the graphical code, and the icon/connector pane identifies the VI. 2. Common structures in LabVIEW include while loops, which execute subdiagrams until a conditional is met, and for loops, which execute a set number of times. Case structures contain multiple subdiagrams but only execute one at a time based on an input. 3. Exercises walk through creating VIs using different structures, like one that generates random numbers

Uploaded by

Jad Lakkis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views16 pages

Experiment #1: Introduction To Lab VIEW: Part 1: Virtual Instruments

This document provides an introduction to LabVIEW and its components. It discusses: 1. Virtual instruments (VIs) in LabVIEW contain a front panel, block diagram, and icon/connector pane. The front panel acts as the user interface, the block diagram contains the graphical code, and the icon/connector pane identifies the VI. 2. Common structures in LabVIEW include while loops, which execute subdiagrams until a conditional is met, and for loops, which execute a set number of times. Case structures contain multiple subdiagrams but only execute one at a time based on an input. 3. Exercises walk through creating VIs using different structures, like one that generates random numbers

Uploaded by

Jad Lakkis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Experiment #1: Introduction to Lab VIEW

Part 1: Virtual Instruments

Labview 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 (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
Figure (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
Figure (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
Figure (4): Slope VI front panel

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

Block diagram:

Figure (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
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 (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
Part 2 :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 (7): 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
Figure (8): 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.

Page 7
This value 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 (9): 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
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.

Figure (10): 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 9
Part 3: 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 (11): Shift register exercise front panel

2. Display the following block diagram:

Figure (12): Shift register exercise block diagram

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

Figure (13): 1D array front

Page 11
Block diagram: Build the following block diagram

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

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.

Page 12
*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 (15): 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 13

You might also like