You are on page 1of 14

Telemark University College

Department of Electrical Engineering, Information Technology and Cybernetics

Virtual Instruments with LabVIEW


HANS-PETTER HALVORSEN, 2011.01.04

Faculty of Technology, Postboks 203, Kjølnes ring 56, N-3901 Porsgrunn, Norway. Tel: +47 35 57 50 00 Fax: +47 35 57 54 01
2 Virtual Instruments with LabVIEW

Introduction
LabVIEW (short for Laboratory Virtual Instrumentation Engineering Workbench) is a platform and development
environment for a visual programming language from National Instruments. The graphical language is named
"G". Originally released for the Apple Macintosh in 1986, LabVIEW is commonly used for data acquisition,
instrument control, and industrial automation on a variety of platforms including Microsoft Windows, various
flavors of UNIX, Linux, and Mac OS X. The latest version of LabVIEW is version LabVIEW 2010. Visit National
Instruments at www.ni.com.

LabVIEW programs are called Virtual Instruments, or VIs, because their appearance and operation imitate
physical instruments, such as oscilloscopes and multimeters. LabVIEW contains a comprehensive set of tools
for acquiring analyzing, displaying, and storing data, as well as tools to help you troubleshoot your code.

Here we will go through some simple LabVIEW examples in order to learn basic LabVIEW programming. For
more background information about LabVIEW, see the tutorial “Introduction to LabVIEW”.

Hans-Petter Halvorsen – Blog: http://home.hit.no/~hansha/


3 Virtual Instruments with LabVIEW

http://home.hit.no/~hansha/?tutorial=labview

You may also want to take a closer look at the “Interactive Training” called “LabVIEW Starter”:

http://home.hit.no/~hansha/training/labview/starter/

Hans-Petter Halvorsen – Blog: http://home.hit.no/~hansha/


4 Virtual Instruments with LabVIEW

Front Panel and Block Diagram


In this task you will learn to create a simple user interface in LabVIEW and how to create the code for it.

When you open a blank VI, an untitled front panel window appears. This window displays the front panel (the
user interface) and is one of the two LabVIEW windows you use to build a VI. The other window contains the
block diagram (the code).

In LabVIEW, you build a user interface, or front panel, with controls and indicators. Controls are knobs, push
buttons, dials, and other input devices. Indicators are graphs, LEDs, and other displays.

Front Panel Example:

If you right-click on the Front Panel, the Controls palette appears:

Hans-Petter Halvorsen – Blog: http://home.hit.no/~hansha/


5 Virtual Instruments with LabVIEW

Block Diagram Example:

If you right-click on the Front Panel, the Functions palette appears:

Hans-Petter Halvorsen – Blog: http://home.hit.no/~hansha/


6 Virtual Instruments with LabVIEW

Task 1: Create a simple Calculator

Step 1: Create the following front panel (user interface) in LabVIEW:

Hans-Petter Halvorsen – Blog: http://home.hit.no/~hansha/


7 Virtual Instruments with LabVIEW

Step 2: Create the block diagram (code) to make the program work as expected.

Step 3: Push the Run button to do the calculations.

[End of Task]

Loops and Structures


Like other programming languages have LabVIEW different Loops and structures available. The different Loops
and Structures available are located in the “Structures” sub palette in the Functions palette on the Block
Diagram.

Task 2: Using While Loops

Step 1: Create the following front panel:

Step 2: Create the block diagram for the program using a While Loop. The Date and Time strings should be
updated every second.

Hans-Petter Halvorsen – Blog: http://home.hit.no/~hansha/


8 Virtual Instruments with LabVIEW

You may want to use the following built-in functions in LabVIEW:

[End of Task]

Task 3: Create an advanced Calculator

Create the following program:

You need to use a While Loop and an Event Structure inside the While loop to solve the problem.

The Event structure is used to respond to buttons clicks, such as when the user clicks the “Calculate” or “Stop”
buttons. When the user clicks the “Calculate” button, the answer should be calculated. When the user clicks
the “Stop” button, the program should stop running.

[End of Task]

Arrays
Arrays are very powerful to use in LabVIEW. In all your applications you would probably use both one-
dimensional arrays and two-dimensional arrays.

Task 4: Arrays

Create the following program:

Hans-Petter Halvorsen – Blog: http://home.hit.no/~hansha/


9 Virtual Instruments with LabVIEW

[End of Task]

SubVIs
Creating and using SubVIs are very important in LabVIEW. A SubVI is like a function or subroutine in other
languages. Here we will learn to create and use existing SubVIs.

Task 5: SubVIs

Step 1: Create a SubVI from the simple Calculator created in a previous task.

You have to create an Icon for you SubVI using the Icon Editor:

Hans-Petter Halvorsen – Blog: http://home.hit.no/~hansha/


10 Virtual Instruments with LabVIEW

You also need to create input/output Connectors

Step 2: Create a new program that uses the SubVI, like this:

[End of Task]

Plotting Data
LabVIEW have powerful features for plotting different kind of data. Below we see the Graph palette in
LabVIEW.

Hans-Petter Halvorsen – Blog: http://home.hit.no/~hansha/


11 Virtual Instruments with LabVIEW

Task 6: Plotting

Create the following program:

You may want to use the following function in order to create some random data:

Create a Chart and use it inside a While Loop.

[End of Task]

Virtual Instruments
Now you have learned the basic features in LabVIEW and you are ready to create your own “Virtual
Instruments”.

Task 7: Virtual Instruments

Hans-Petter Halvorsen – Blog: http://home.hit.no/~hansha/


12 Virtual Instruments with LabVIEW

In this task you will need everything you have learned so far (and probably a little more).

Create a “Virtual Instrument” with the following components:

1. Toolbar
2. Owned Label
3. Numeric Control
4. Free Label
5. Numeric Control Terminal
6. Knob Terminal
7. Numeric Constant
8. Multiply Function
9. Icon
10. Knob Control
11. Plot Legend
12. XY Graph
13. Wire Data Path
14. XY Graph Terminal
15. Bundle Function
16. SubVI
17. For Loop Structure

Below we see the front panel and the block diagram for the virtual instrument.

Hans-Petter Halvorsen – Blog: http://home.hit.no/~hansha/


13 Virtual Instruments with LabVIEW

The SubVI (number 16) could be reading the temperature from a temperature sensor using a DAQ (Data
Acquisition) device, but in our case we will just create a simple “simulator” using, e.g. the built-in “Random
Number” VI to create random temperature values.

We will learn more about acquiring data from DAQ devices later.

Hans-Petter Halvorsen – Blog: http://home.hit.no/~hansha/


Telemark University College

Faculty of Technology

Kjølnes Ring 56

N-3914 Porsgrunn, Norway

www.hit.no

Hans-Petter Halvorsen, M.Sc.

Telemark University College

Department of Electrical Engineering, Information Technology and Cybernetics

Phone: +47 3557 5158

E-mail: hans.p.halvorsen@hit.no

Blog: http://home.hit.no/~hansha/

Room: B-237a

Faculty of Technology, Postboks 203, Kjølnes ring 56, N-3901 Porsgrunn, Norway. Tel: +47 35 57 50 00 Fax: +47 35 57 54 01

You might also like