An
Introduction To Using LabView - Adding Two Numbers
This note is for those just starting to program in LabVIEW. In this
exercise, you will create a vi (Virtual Instrument) that adds two numbers.
You have to take care of the following tasks.
-
You need to input two
numbers
-
You need to add the two
numbers that were put in in the first step.
-
You need to display the
results (sum).
In the process, you should create a diagram
like the one below. Follow the steps below, which tell you what you
need to do, and which provide explanations of what is going on as you do
things.

-
Start LabView. Choose
New
vi.
-
On the Front
Panel of that new vi, add two numeric controls
and a numeric indicator. You may need to get the Controls Palette
using Window-Show Controls Palette
to show the controls palette, then click to show all functions and open
the Numeric sub-palette
to get the numeric control tool to place numeric controls on the front
panel.
-
You will use the two numeric
controls to input the two numbers that you
want to add. You will do that on the front panel when you run the
program. When you add the numeric controls on the front panel, you
will find that you have added the elements shown above on the block diagram.
If the block diagram is not showing, then click Window-Show
Block Diagram (from the menus on the front
panel!) to show the block diagram.
-
In the diagram above,
those controls are labelled "A" and "B". We used the Text
Tool to change to those labels from the default
labels. If the text tool is not showing, click on Window-Show
Tools Palette to show the tools palette, and
click on the panel in that palette that shows the letter A to indicate
the text tool.
-
Add a numeric
indicator to show the result on the front
panel. Find the numeric indicator tool and add one numeric indicator
to the front panel. Again, you can change the label to "C" - as we
did above.
-
Now, you need to go to
the block diagram. If the block diagram is not showing use Window-Show
Block Diagram to show the block diagram.
(Or, if you have the windows not taking up the full screen, you can just
click between them.
-
On the Block
Diagram, add the addition element - the "summer".
You will need to show the Functions Palette using Window
- Show Functions Palette (using the block
diagram menus).
-
This is the element that
will actually do the addition.
-
In the diagram above,
the yellow triangle with the "+" sign is the addition element.
-
Wire the output of the
two numeric controls to the addition element. You need to locate
the wiring tool (It looks like a spool of wire.), then wire your circuit
by holding down the mouse button as you drag the tool from connector to
connector on the various elements.
-
Wire the output of the
summer to the numeric control.
Note the following:
-
The two numeric controls
that you use for input and the numeric indicator that you use for output
must all be put onto the front panel. You can't add them to the block
diagram. When you add these elements to the front panel, the terminals
for these elements appear on the diagram at an arbitrary position, and
you will need to position those elements where you want them.
-
The summer appears only
on the block diagram. There is no indication that it even exists
if you look on the front panel.
-
You can make a better
looking program by putting some appropriate label(s) on the elements on
the front panel.
Now, you can run the program. Do the following:
-
Type in the two numbers
you want to add. Do that in the two numerical controls on the front
panel.
-
Hit the run button - the
one with the arrow that points to the right.
What can go wrong?
-
You might mis-wire something.
Then the run button will have a broken arrow, but if you click it anyway
you will get an error message that points to where things have gone wrong.
-
You might have used a
wrong element. For example, you might have used the multiplier element
instead of the summer. Then you would get one of those hard-to-debug
kinds of problems. Note that you can always right-mouse-click on
an element to get help.
There are some other considerations with the vi that you have just constructed
and run.
The data representation is a "double" i.e. a more precise floating point
representation. (Click
here to review what that means.) You can right-mouse-click on
the icon on the block diagram and change the representation (and there
are numerous choices.)
Problems