LabView, An Easy Introduction

Day 1

What is LabView and Why do people use it?

LabView is a graphical programming language developed by National Instruments sometime in the mid to late 80’s by Jeff Kodosky. A program in LabView is called a VI, which stands for Virtural Instrument. To create a VI, the programmer uses the LabView programming environment to make the user interface by dragging and dropping objects, and arranging them as desired. To add functionality to the interface, the diagram, which resembles a flow chart is “wired” with the various structures and functions. So, in most LabView programs, no lines of code are written, the functionality of the program is provided by the diagram. For this reason LabView is called a graphical programming language.

Another nicety of LabView is that it closely supports a multitude of processing cards available from National Instruments. Other vendors also build cards that are LabView compatible. The cards are so tightly coupled to the LabView system that it is not uncommon to be collecting data within a few hours of receiving the data collection cards in the mail.

For these reasons, LabView has become one of the most popular data collection systems in recent years. Within the framework of Labview, user interfaces can be created, data can be collected, signals can be generated and transmitted from LabView cards, data can be analyzed and stored, etc. etc. If LabView does not provide what is needed, C code or MatLab programs can be tied to it to provide the required functionality.

In summary, LabView is a powerful graphical programming system that is compatible with a multitude of data collection cards and equipment. People use it because it is convenient and no knowledge of conventional programming languages is required.

1-1 to 1-2 , Getting Started with LabView

1-2, LabView Tutorial Manual

1, LabView, Data Acquisition & Analysis for the Movement Sciences

Getting Started

· Demo of basic random.vi

· User interface of random.vi. Notice even though it is simple, to hand program this interface in C would require a little work. Without graphics libraries available, it would reaquire a lot of work.

· Diagram. Here is where to “coding” is done. All the variables and programmatic structures are represented pictorially. If you had access a random number generator and a graphing function, could you sketch out the algorithm for this program?

· Demonstration of the LabView programming environment.

o Build the user interface. (Watch the instructor)

o Go to the Diagram. Notice the objects that were placed onto the screen in the user interface are in the diagram in different colors.

§ Colors are different for each data type.

§ A bold border means that a variable is a “control”. A control provides input.

§ A non bold border means that a variable is an “indicator”. An indicator provides output.

o Wire the Diagram using the wiring tool. Notice the little arrow is broken when there are mistakes.

o Run it. (click on the white arrow at the upper left of the diagram)

Detailed instructions for a very similar VI are given on the pages indicated below.

Page 2-4, Getting Started with LabView

Page 3-3, LabView Tutorial Manual

Numbers

The best way to learn LabView is by doing it. A good place to start is by writing some programs using the basic data types. Number are pretty basic so that’s a good place to start.

First off, numbers, whether in math or in computers, come in a few different ways. For computers, we are mostly concerned with integer or real numbers. Real numbers have decimals, integers don’t.

3.14….

This is a real number because it has a decimal. If you were in algebra 2, they would say it is irrational, but since we have to estimate pi’s value, we represent it as a real number. (pi, one of my favorite foods, uh numbers)

7

This an integer. It is also the minimum number of ice creams a healthy person should eat in a week.

In LabView there are real, integer, unsigned integer, and complex numbers. There are several sizes for each. By size we mean the number of bits used to represent the number. This is nothing to worry about. When in doubt, pick I32 for integers, and double for real numbers.

· Numbers.vi. See the figure below. Compared to the basic random.vi it is dull, but its diagram shows how to use some of the various numeric operators provided by LabView.

· Looking at the numbers.vi interface, notice that X and Y have up down arrows next to them, that means they are controls. Controls accept inputs. Sum, difference, product and quotient do not. They are indicators, they display output.

· All the controls come from the Controls/Numeric pallet. X and Y are digital controls. Sum, difference, product, and quotient are digital indicators.

· To make the interface, you click on a digital control and drop it onto the interface where you want it. Right after you drop it on you can give it a name. You can change the name anytime by clicking on the A in the tools pallet and highlighting the name and then changing it, or by clicking on Mr. Hand in the tools pallet and clicking on the variable name in the diagram. A cursor will appear and the name can be changed.

· Look at the diagram. X and Y have bold boxes around them, again indicating they are controls. Their boxes say I16, meaning that they are 16 bit integers. That means they are integers with a range from –32k to +32k. The lines and boxes associated with them are blue, for integer.

· The dots on the wires indicate junctions.

· All the math operations accept two inputs and have one output.

· The math operators are found under the Functions/Numeric palette.

· To wire the diagram the little wire spool from the tools pallet is selected. To wire you click on where you want the wire to start (left click) and then trace the wire to it destination and let go of the mouse button. If the wire is correct its trace will be the color where it started. If not it will be a dashed line.

· Running it is fun. One thing to remember, when operating a VI, you need to use Mr. Hand from the tools palette. The arrow will run the VI, but if you try to put input into a control using the arrow it will just move the control around. That may not be what you want to do.

Numbers (formula)

Sometimes using the graphic operators of math operations can get hard to understand. For example, if an equation has many parts, then there could be wires going everywhere. A note of caution, while doing VI’s it is easy to understand what is being done at the moment, but when looking at complex VI’s, it can be hard to understand later. This applies doubly when looking at someone else’s work. See figure below.

Although this looks ridiculous, what is shown is really only about 1/8th of the VI’s diagram.

Using the formula node, complex math operations can be tidied up a bit. Below the numbers formula.vi is shown along with its diagram. This program does the same thing as the numbers program, but the diagram is much different.

· The user interface is the same as numbers.vi.

· The formula structure replaces the numeric operators.

· It is found under the Functions/Stuctures palette.

· The formula structure has inputs and outputs. To make them you have to right click on the border of the box and hit the “add input” or “add output” menu item.

· To type formulas into the box you have to select Mr. Hand from the Tools pallete. Remember any variables used in the formula box must be defined, meaning they have to be an input or an output that was defined by clicking on the edge of the box.

· After the formulas are typed in, all that’s left is wiring up the inputs and outputs.

· Running it gives the same results as the earlier VI.

Basic Boolean Logic

The next VI is the Boolean equivalent of number.vi. Boolean logic is a kind of logic that is usually associated with binary operations.

The basic Boolean functions are AND, OR, and NOT. The one that will be of concern immediately is NOT.

In LabView the NOT function usually has a single bit input. NOT can thought of as a function that produces the opposite of its input.

So

NOT(0) = 1

NOT(1) = 0

Usually the NOT function is used to control WHILE loops. More on that soon. Below is the basic Boolean.vi and its diagram.

· The Boolean interface objects and functions are found under Controls/Boolean and Functions/Boolean. The controls are push buttons, the indicators are round LEDs.

· In the diagram the functions are the AND, OR and NOT functions.

· The following are tables for Boolean functions.

o AND

§ 1 AND 1 = 1

§ 0 AND 1 = 0

§ 1 AND 0 = 0

§ 0 AND 0 = 0

o OR

§ 1 OR 1 = 1

§ 0 OR 1 = 1

§ 1 OR 0 = 1

§ 0 OR 0 = 0

o NOT

§ NOT(1) = 0

§ NOT(0) = 1

Exercises

Try to make these VI’s. The diagrams will be presented in the next lecture.

· Add five numbers.

· Add five numbers, input with sliders.

· Average five numbers, input with sliders, show sum with a dial, average with a temp gauge.

· Average five numbers, input with sliders, show sum with a dial, average with a temp gauge, try a formula structure.

· Make a Fahrenheit to Celsius, and pounds to kilos to converter.

Pounds = (2*Kilos)*1.1

Celsius = (F – 32) * 5/9

Heres the last one to try.

2