Telemark University College
Department of Electrical Engineering, Information Technology and Cybernetics
Basic LabVIEW Programming
HANS-PETTER HALVORSEN, 2011.09.29
Faculty of Technology, Postboks 203, Kjlnes ring 56, N-3901 Porsgrunn, Norway. Tel: +47 35 57 50 00 Fax: +47 35 57 54 01
Preface
In this document you will learn basic LabVIEW programming by creating some
simple LabVIEW applications.
LabVIEW is a graphical programming language created by National Instruments
(www.ni.com).
For more information about LabVIEW, please refer to the Tutorial
Introduction to LabVIEW: http://home.hit.no/~hansha/?tutorial=labview .
For a flying start, watch this video (LabVIEW Quickie!):
http://home.hit.no/~finnh/videos/topics/labview/labview/labview.html
3/19
Task 1: Simple Calculator
Create the following simple program that adds 2 numbers:
Simple Calculator.vi
This simple calculator will add 2 numbers together.
Front Panel:
Add 2 Numeric
Controls and name them
Number1 and Number2
Add a Numeric Indicator
and name it Answer
Block Diagram:
Add a Add function from the Functions palette:
http://home.hit.no/~hansha
4/19
Connect (wire) the different objects together like this:
Push the Run button in the Toolbar to do the calculations.
Extend your calculator (make sure to rename your file) so it can handle the 4
basic calculations (Add, Subtract, Multiply, Divide).
Front Panel:
Calculator.vi
For selecting the different Operators (Add, Subtract, Multiply, Divide),
you should use an Enum:
http://home.hit.no/~hansha
5/19
Enter Add, Subtract, Multiply, Divide inside the Enum (right-click
and select Add Item After).
Block Diagram:
The Block Diagram should look like this when you are finished:
Use the Case Structure for this.
http://home.hit.no/~hansha
6/19
Wire the Enum (Operator) to the sign on the Case structure.
Push the Run button in the Toolbar to do the calculations.
[End of Task]
http://home.hit.no/~hansha
7/19
Task 2: While Loop
Create the following program:
While Loop.vi
The program will update the date and time each second using a While loop
until you stop the program using the Stop button.
Front Panel:
Add 2 String Indicators and name them Date and Time.
Block Diagram:
The Block Diagram should look like this when you are finished:
http://home.hit.no/~hansha
8/19
While Loop:
Add a While Loop to your program.
Get Date/Time String:
Use the Get Date/Time String function in order to get the current Date and
Time from the computer:
Wait (ms):
The Date and Time strings should be updated every second. You can use the
Wait (ms) for that:
[End of Task]
http://home.hit.no/~hansha
9/19
Task 3: Advanced Calculator
Create the following program:
Advanced Calculator.vi
Front Panel:
Add the User Interface objects as shown in the Figure above.
The calculations will be performed when you click the Calculate button.
Block Diagram:
You need to use the following in your program:
While Loop:
Event Structure:
Add an Event Structure inside the While Loop.
http://home.hit.no/~hansha
10/19
The Block Diagram should look like this when you are finished:
[End of Task]
http://home.hit.no/~hansha
11/19
Task 4: Arrays
Create the following program:
Arrays.vi
Front Panel:
Creating an Array:
Start by dragging an empty array into your Front Panel and drag a
Numeric Control inside it:
Enter some data inside the array.
Block Diagram:
Index Array:
Next we will use the Index Array function in order to find a spesific
element in the array:
http://home.hit.no/~hansha
12/19
The Block Diagram should look like this when you are finished:
Test your program by using the Run button in the Toolbar.
[End of Task]
http://home.hit.no/~hansha
13/19
Task 5: SubVIs
Create a SubVI from the Calculator created in a previous task.
Calculator.vi
Icon Editor:
This includes creating a nice icon using the Icon Editor:
Right-click in the upper right window and select Edit Icon in order to open
the Icon Editor.
http://home.hit.no/~hansha
14/19
You also need to create input/output Connectors
Using and testing the SubVI:
We will now create a new program that uses the SubVI.
Block Diagram:
Create a new blank VI and open the Block Diagram.
Insert the SubVI by right-click and select Select a VI in the Functions
palette.
Right-click on the SubVI inputs and select CreateControl
http://home.hit.no/~hansha
15/19
The Block Diagram should look like this when you are finished:
Front Panel:
The Front Panel could look like this:
http://home.hit.no/~hansha
16/19
Test of SubVI Calculator.vi
Test your program by using the Run button in the Toolbar.
[End of Task]
http://home.hit.no/~hansha
17/19
Task 6: Plotting
Create the following program:
Plotting.vi
Front Panel:
Use the Waveform Chart Control:
http://home.hit.no/~hansha
18/19
Block Diagram:
Random Number (0-1):
Use the Random Number (0-1) function in order to create some random
data in your plot:
Waveform Chart:
Insert the Waveform Chart inside the While Loop.
Wait (ms):
Update the chart every second by using the Wait (ms):
The Block Diagram should look like this when you are finished:
[End of Task]
http://home.hit.no/~hansha
Telemark University College
Faculty of Technology
Kjlnes 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: [email protected]
Blog: http://home.hit.no/~hansha/
Room: B-237a