0% found this document useful (0 votes)
285 views

11 LabVIEW

This document describes how to create programs in LabVIEW by building graphical block diagrams and front panels. It provides instructions for building two example programs: 1) A "Hello World" program that displays a string, and 2) A dial-controlled meter program that continuously updates a meter based on dial input. It also demonstrates how to perform mathematical operations in LabVIEW, including solving quadratic equations, using numeric operators and a formula node.

Uploaded by

Sbo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
285 views

11 LabVIEW

This document describes how to create programs in LabVIEW by building graphical block diagrams and front panels. It provides instructions for building two example programs: 1) A "Hello World" program that displays a string, and 2) A dial-controlled meter program that continuously updates a meter based on dial input. It also demonstrates how to perform mathematical operations in LabVIEW, including solving quadratic equations, using numeric operators and a formula node.

Uploaded by

Sbo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

GET130 Intro to Engineering Technology Lab 11: LabVIEW

Figure 1: LabVIEW VI Front Panel (l) and Block Diagram (r) windows

7. Now we can begin LabVIEW “programming”. Right-click anywhere on the front panel and LabVIEW will show
the Controls palette containing many goodies you can place on your front panel. The Modern category
should already be open. Point to String & Path to expose that subpalette and select String Indicator. Back on
the front panel, click where you’d like this indicator placed. You should also notice an icon appear in your
block diagram representing this front panel indicator. Front panel indicators are the standard method of
presenting LabVIEW program output data.
8. Next we will create a string constant for the output message. Right-click anywhere on the block diagram and
LabVIEW will show the Functions palette containing numerous program elements and subVIs you can add to
your program. The Programming category should already be open. Point to String to expose that subpalette
and then select String Constant. Back on the block diagram, click to the left of the String indicator icon and
immediately type in the “Hello World!” message you’d like to display (see figure 2). Notice the concept of
how program elements are graphically displayed on the block diagram window. Click anywhere outside the
string constant icon to complete its placement.
9. Now for the fundamental concept of LabVIEW programming – “wiring”. In the block diagram, hover the
mouse pointer just to the right of the string constant to reveal a spool of wire near its output terminal.
(Left)click to anchor that end of your wire. Move the wire spool to the left side of the string indicator icon
and click again to anchor the other end of your first wire. Things should appear as shown in figure 2.

Figure 2: Completed “Hello World” LabVIEW VI

2
GET130 Intro to Engineering Technology Lab 11: LabVIEW

10. Believe it or not, you have just completed your first LabVIEW VI! To see if it works properly, click the run
button also shown in figure 2. Your message string should appear in the string indicator. Hurrah, you have
just run your first LabVIEW program! Save your masterpiece then close this VI.
11. To demonstrate a bit more LabVIEW programming, let’s build a “dial-controlled meter”. In the LabVIEW
project explorer window, right-click on My Computer and create another new VI. Save this new VI as
Meter.vi.
12. Right-click on the front panel then select Modern -> Numeric -> Dial (or Knob) and place it on the front
panel. Right-click again and place a Modern -> Numeric -> Meter (see figure 3).
13. You should now see two icons on the block diagram, one for the Dial and one for the Meter. Hover the
mouse pointer near the right side of the Dial icon to reveal the wire spool. Notice how the Dial, being a front
panel control, produces an output terminal on the block diagram. Front panel controls are the standard
method of accepting user input into a LabVIEW program. Connect the Dial’s output to the Meter’s input.
Things should appear similar to that shown in figure 3. Save the updated VI.

Figure 3: Completed Dial-Meter VI

14. Change the dial setting to arbitrary values and click Run each time. Verify that the meter updates to the
same dial value each time you run. Now, if it would only run continuously…
15. Although there is a Run Continuously button next to the regular Run button, this is not the desired method
to getting a VI to repeat. Note that when you run continuous (try it!), the graph paper background in the
front panel disappears to indicate the VI is running and the meter updates instantly as you change the dial
setting; however, the only way to stop the VI is to abort it with the stop sign button to the right of run
continuous. This technique is so not cool.
16. The proper way to make a VI iterate, as in any programming language, is to add a loop. Make sure your VI is
stopped as you cannot modify a running VI. Right-click on the block diagram and select Programming ->
Structures -> While Loop. Left click and drag a while loop to completely enclose both dial and meter icons as
shown in figure 4.

3
GET130 Intro to Engineering Technology Lab 11: LabVIEW

Figure 4: While Loop added

17. Notice that at this point, the Run button now appears broken because you have at least one error in your VI.
Click the Run button to see the Error list dialog with descriptions of your error(s). Click the Show Error button
and LabVIEW will even show where in your block diagram it has detected the problem. LabVIEW seems
almost smart enough to automatically correct programming errors! Close the Error list window.
18. The current problem is that the “termination condition” for the while loop is not defined. Let’s add a “stop”
button to the VI… On the block diagram immediately to the left of the stop icon in the while loop, right-click
once you see the wire spool and select Create Control. Notice how LabVIEW adds a second control to the
block diagram and its corresponding STOP button to the front panel. You can reposition the stop icon in the
block diagram and the STOP button on the front panel for a better layout as shown in figure 5. You can also
resize the STOP button and turn off the redundant “stop” label on the front panel (right-click on the stop
button then select Visible Items -> Label to remove its check mark). Note the asterisk to the right of the
block diagram window title indicating that program changes have been made but not yet saved to disk. Save
your VI noting that the asterisk disappears.

Figure 5: Dial-Meter VI, version 2

19. Run this new version and verify for correct operation. When finished, click the STOP button to properly
terminate the VI. Now it’s cool.

4
GET130 Intro to Engineering Technology Lab 11: LabVIEW

Part 2: Do the Math!


Objectives:
• To demonstrate mathematical operations in LabVIEW using both conventional and “formula node”
methods.
Recall from a previous lab where we used the calculator to solve the quadratic equation:
−𝑏 ± √𝑏 2 − 4𝑎𝑐
𝑥=
2𝑎
Not to be outdone by a calculator, LabVIEW also performs mathematical calculations easily. Let’s see how to
perform mathematics in LabVIEW.
20. As done previously, create another new VI in your lab project named Quadratic.vi.
21. Referring to figure 6a, place three numeric controls named a, b, and c on the front panel. Also place two
numeric indicators named x1 and x2 as shown. Notice how controls show in white editable boxes while
indicators are grayed and non-editable. To rename these controls and indicators, just click on the default
label and overtype with your desired name. Do not hit Enter here! The yellow boxed text is just a text label;
simply double-click on the front panel and type to place such a label.

Figure 6a: Quadratic Solver Front Panel

22. Referring to figure 6c, construct the block diagram as shown. All of the math operators used in this VI are
found on the Programming -> Numeric subpalette and are summarized in figure 6b. Note that you do not
need to place the box around the discriminant; it is only shown for emphasis. To properly configure the
compound arithmetic operator:
a. after placing it on the block diagram, right-click it and select Change Mode -> Multiply
b. grab either its top or bottom ‘handle’ and increase its height to three “stories”

Figure 6b: Numeric palette operators

5
GET130 Intro to Engineering Technology Lab 11: LabVIEW

Figure 6c: Quadratic Solver Block Diagram

23. Save your VI. Using the coefficients in the two examples of the calculator lab (ex. 4.1 and 4.2), run your
quadratic solving VI and verify for proper results. And to think, you did this all with “graphical
programming”!
24. Alternatively, mathematic problems can also be solved using LabVIEW’s “Formula Node” feature as shown in
figure 7. Copy your Quadratic.vi to a new version, Quadratic2.vi using File -> Save As. In the Save dialog box,
be sure to select Open additional copy. Also make sure Add copy to project is checked.
25. In this new version, delete all the math operators in the block diagram then select Edit -> Remove Broken
Wires (or just type Ctrl-B). Place a Programming -> Structures -> Formula Node as shown in figure 7. Right-
click on the formula node’s borders and select Add Input for each of the three coefficients on the left and
Add Output for the outputs on the right. Name the inputs a, b, c and the outputs x1, x2. Inside the formula
node box, type the formulae exactly as shown. Also complete the wiring as shown.

Figure 7: Quadratic Solver using a Formula Node

26. Save your alternate version. Run it as in step 23 and verify the same answers. Graphical method or
mathematical method – LabVIEW does not discriminate. 

6
GET130 Intro to Engineering Technology Lab 11: LabVIEW

Part 3: LabVIEW Blackjack


Objectives:
• To demonstrate additional LabVIEW functions including random number generator and time delay.
• To show use of a “shift register” on a loop as a history mechanism.
• To understand the basic concept of dataflow execution and how LabVIEW can visually animate this.
• To demonstrate use of front panel LEDs as Boolean logic indicators.
In this section, we will see how LabVIEW can be used to play a basic version of the card game Blackjack. In
Blackjack, players compete against the dealer in each hand in the pursuit of achieving the highest point score
not exceeding 21. Cards are assigned point values per their numeric card value with “face” cards (jacks, queens,
kings) valued at 10 and aces valued at either 1 or 11. A hand total of 21 is a Blackjack while anything over 21 is a
“bust”. Upon completion of this part, we will play a few class-wide hands of Blackjack for “bragging rights”.
27. Create another new VI in your lab project named Blackjack.vi.
28. Referring to figure 8a and the tips below, construct the block diagram as shown. This VI has three front
panel numeric indicators: Card #, Current Card, and Total. New operators for this VI are summarized in
figure 8b.

Figure 8a: Blackjack VI

Figure 8b: New operators


Tips:
• If you have trouble finding these operators in the Functions palettes, use of the Search feature on the
Functions palette (figure 8c) will show you exactly where they are located by double-clicking an entry in
the resulting search list.
• The 11, 18, and 500 are all numeric constants. Orange items indicate floating-point real numbers and
blue indicate integer numbers.
• The 18 sets a minimum hand total desired and represents a “risk factor”. Lower values are safer but less
likely to win; higher are harder to achieve but more likely to win. Experiment with this at will!

7
GET130 Intro to Engineering Technology Lab 11: LabVIEW

• The Wait (ms) function injects a time delay into the loop so that we can visually follow the front panel as
it is updated. Feel free to try different values here.
• The up/down arrows on the while loop’s borders are a “shift register” which serves as a history
mechanism from one loop iteration to the next. In this VI, this shift register accumulates the total value
of all the cards in a hand. Right-click on the loop’s border and select Add Shift Register. The 0 to the far
left sets the initial value to zero.

Figure 8c: Using Search Feature

29. Once you complete building this VI, save it then run it a few times to see how it works. Card # will display
how many cards are “dealt” to your hand, Current Card is the value each card as they are dealt, and Total is
the total sum of the hand.
A highly useful feature of LabVIEW is its built-in help system. In addition to a fully-detailed help facility, LabVIEW
also features a “context” help feature.
30. On the Help menu of any LabVIEW window, turn on Show Context Help - a check mark should appear there
along with a separate context help window. Mouse over the various (yellow) operators and program
elements in your block diagram to see an instantaneous help display in that window. This is very handy!
Another very ‘kewl’ feature of LabVIEW is its “execution highlighting” feature which visually shows the flow of
data through your VI as it executes. Indeed, LabVIEW is known as a “dataflow” language. So if you’ve ever
wondered how a computer runs a program, you came to right place!
31. Click the Highlight execution button on (figure 9) then run your VI while watching the block diagram “come
to life” via execution animation. Amazing, no?

Figure 9: Highlight execution button

You might also like