telemark university collegehome.hit.no/~hansha/documents/lab/lab work/labview programming... ·...

19
Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics 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 Basic LabVIEW Programming HANS-PETTER HALVORSEN, 2011.09.29

Upload: vodan

Post on 01-Feb-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Telemark University Collegehome.hit.no/~hansha/documents/lab/Lab Work/LabVIEW Programming... · 3/19 hansha Task 1: Simple Calculator Create the following simple program that adds

Telemark University College

Department of Electrical Engineering, Information Technology and Cybernetics

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

Basic LabVIEW Programming

HANS-PETTER HALVORSEN, 2011.09.29

Page 2: Telemark University Collegehome.hit.no/~hansha/documents/lab/Lab Work/LabVIEW Programming... · 3/19 hansha Task 1: Simple Calculator Create the following simple program that adds

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

Page 3: Telemark University Collegehome.hit.no/~hansha/documents/lab/Lab Work/LabVIEW Programming... · 3/19 hansha Task 1: Simple Calculator Create the following simple program that adds

3/19

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

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:

Page 4: Telemark University Collegehome.hit.no/~hansha/documents/lab/Lab Work/LabVIEW Programming... · 3/19 hansha Task 1: Simple Calculator Create the following simple program that adds

4/19

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

→ 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”:

Page 5: Telemark University Collegehome.hit.no/~hansha/documents/lab/Lab Work/LabVIEW Programming... · 3/19 hansha Task 1: Simple Calculator Create the following simple program that adds

5/19

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

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

Page 6: Telemark University Collegehome.hit.no/~hansha/documents/lab/Lab Work/LabVIEW Programming... · 3/19 hansha Task 1: Simple Calculator Create the following simple program that adds

6/19

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

→ 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]

Page 7: Telemark University Collegehome.hit.no/~hansha/documents/lab/Lab Work/LabVIEW Programming... · 3/19 hansha Task 1: Simple Calculator Create the following simple program that adds

7/19

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

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:

Page 8: Telemark University Collegehome.hit.no/~hansha/documents/lab/Lab Work/LabVIEW Programming... · 3/19 hansha Task 1: Simple Calculator Create the following simple program that adds

8/19

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

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]

Page 9: Telemark University Collegehome.hit.no/~hansha/documents/lab/Lab Work/LabVIEW Programming... · 3/19 hansha Task 1: Simple Calculator Create the following simple program that adds

9/19

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

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.

Page 10: Telemark University Collegehome.hit.no/~hansha/documents/lab/Lab Work/LabVIEW Programming... · 3/19 hansha Task 1: Simple Calculator Create the following simple program that adds

10/19

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

The Block Diagram should look like this when you are finished:

[End of Task]

Page 11: Telemark University Collegehome.hit.no/~hansha/documents/lab/Lab Work/LabVIEW Programming... · 3/19 hansha Task 1: Simple Calculator Create the following simple program that adds

11/19

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

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:

Page 12: Telemark University Collegehome.hit.no/~hansha/documents/lab/Lab Work/LabVIEW Programming... · 3/19 hansha Task 1: Simple Calculator Create the following simple program that adds

12/19

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

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]

Page 13: Telemark University Collegehome.hit.no/~hansha/documents/lab/Lab Work/LabVIEW Programming... · 3/19 hansha Task 1: Simple Calculator Create the following simple program that adds

13/19

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

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.

Page 14: Telemark University Collegehome.hit.no/~hansha/documents/lab/Lab Work/LabVIEW Programming... · 3/19 hansha Task 1: Simple Calculator Create the following simple program that adds

14/19

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

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 “Create→Control”

Page 15: Telemark University Collegehome.hit.no/~hansha/documents/lab/Lab Work/LabVIEW Programming... · 3/19 hansha Task 1: Simple Calculator Create the following simple program that adds

15/19

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

The Block Diagram should look like this when you are finished:

Front Panel:

The Front Panel could look like this:

Page 16: Telemark University Collegehome.hit.no/~hansha/documents/lab/Lab Work/LabVIEW Programming... · 3/19 hansha Task 1: Simple Calculator Create the following simple program that adds

16/19

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

Test of SubVI Calculator.vi

→ Test your program by using the Run button in the Toolbar.

[End of Task]

Page 17: Telemark University Collegehome.hit.no/~hansha/documents/lab/Lab Work/LabVIEW Programming... · 3/19 hansha Task 1: Simple Calculator Create the following simple program that adds

17/19

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

Task 6: Plotting

Create the following program:

Plotting.vi

Front Panel:

Use the “Waveform Chart” Control:

Page 18: Telemark University Collegehome.hit.no/~hansha/documents/lab/Lab Work/LabVIEW Programming... · 3/19 hansha Task 1: Simple Calculator Create the following simple program that adds

18/19

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

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]

Page 19: Telemark University Collegehome.hit.no/~hansha/documents/lab/Lab Work/LabVIEW Programming... · 3/19 hansha Task 1: Simple Calculator Create the following simple program that adds

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: [email protected]

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

Room: B-237a