LabVIEW Workbook v1.2
LabVIEW Workbook v1.2
Laboratory Exercises
1
Content
B. Course Project...................................................................................................3
C. Exercises
1. Navigating LabVIEW
Exercise 1-1 Concept: Exploring a VI.....................................................................4
Exercise 1-2 Concept: Navigating Palettes ...........................................................5
Exercise 1-3 Concept: Selecting a Tool .................................................................6
Exercise 1-4 Concept: Data Flow...........................................................................9
3. Implementing a VI
Exercise 3-1 Determine Warnings VI ..................................................................15
Exercise 3-2 Auto Match VI.................................................................................19
Exercise 3-3 Concept: While Loops versus For Loops .........................................22
Exercise 3-4 Average Temperature VI.................................................................24
Exercise 3-5 Temperature Multiplot VI ..............................................................27
Exercise 3-6 Determine Warnings VI ..................................................................30
Exercise 3-7 Self-Study: Square Root VI..............................................................34
Exercise 3-8 Self-Study: Determine Warnings VI (Challenge)..............................37
FURTHER EXERCISES............................................................................................38
2
INSTRUCTIONS
Design
What inputs are you given?
What outputs are you expected to produce?
What is the relationship/conversion between the inputs and outputs?
Create an algorithm or a flowchart that demonstrates the relationship between
the inputs and outputs.
Implementation
During this stage, you implement the program from the algorithm or flowchart.
Testing
Use a set of known values to test the algorithm or flowchart you designed.
Maintenance
If a test value set has failed, return to the design phase and check for errors.
B. Course Project
Throughout this course, the project illustrates concepts, both as hands-on exercises and as a case
study. The project meets the following requirements:
Inputs
• Current Temperature (T)
• High Temperature Limit (X)
• Low Temperature Limit (Y)
• Stop
Outputs
• Warning Levels: Heatstroke Warning, No Warning, Freeze Warning
• Current Temperature Display
• Data Log File
3
Exercise 1-1: Exploring a VI
Goal
Identify the parts of an existing VI.
Description
You received a VI from an employee that takes the seconds until a plane arrives at an airport and
converts the time into a combination of hours/minutes/seconds. You must evaluate this VI to see if
it works as expected and can display the remaining time until the plane arrives.
5. Test the VI using the values given the values shown below.
❑ Enter the input value in the Total Time in Seconds control.
❑ Click the Run button.
❑ For each input, compare the given outputs to the outputs listed in
If the VI works correctly, they should match. Testing Values for Seconds Breakdown.vi:
Input Output
0 seconds 0 hours, 0 minutes, 0 seconds
60 seconds 0 hours, 1 minute, 0 seconds
3600 seconds 1 hour, 0 minutes, 0 seconds
3665 seconds 1 hour, 1 minutes, 5 seconds
4
Exercise 1-2: Navigating Palettes
Goal
Learn to find controls and functions.
Description
1. Open Navigating Palettes.exe in the C:\Exercises\LabVIEW
Basics I\Navigating Palettes directory.
3. Using the instructions given in the simulation, place the DAQ Assistant
Express VI in the Favourites category of the Functions palette.
5
Exercise 1-3: Selecting a Tool
Goal
Use the Automatic Tool Selection to learn about its operation.
Description
During this exercise, you complete tasks in a partially built front panel and block diagram. These
tasks give you experience in using the Auto tool.
6
3. Rename the numeric control to Number of Measurements using the
Labelling Tool
❑ Move the cursor to the text Numeric.
❑ Double click the word Numeric.
❑ Enter the text Number of Measurements.
❑ Complete the entry by pressing the <Enter> key on the numeric
keypad, pressing the Enter Text button on the toolbar, or clicking
the mouse outside of the control.
5. Change the value of the pointer on the horizontal pointer slide using the
Operating tool.
❑ Move the cursor to the pointer on the slide.
❑ When the cursor changes to the Operating tool icon, as shown at left,
press the mouse button and drag to the value you want.
❑ Leave the value at a value greater than 0.
7
7. Open the block diagram.
10. Change the value of the Delay (sec) control to something greater than
zero (0).
12. Try moving other objects, deleting wires and rewiring them, and wiring
objects and wires together until you are comfortable with using these
tools.
13. Select File»Close to close the VI and click the Don’t save - All button.
You do not need to save the VI.
8
Exercise 1-4: Data Flow
Goal
Understand how data flow determines the execution order in a VI.
Description
1. Open the Dataflow.exe simulation from the C:\Exercises\
LabVIEW Basics I\Dataflow directory.
9
Exercise 2-1: Using Help
Goal
Become familiar with using the Context Help window, the LabVIEW Help, and the NI Example Finder.
Description
This exercise consists of a series of tasks designed to help you become familiar with the LabVIEW
Help tools. Complete the following steps.
NI Example Finder
1. You have a GPIB device in your computer, and you want to learn how to
communicate with it using LabVIEW. Use the NI Example Finder to find a VI that communicates with
a GPIB device.
❑ Open LabVIEW.
❑ Select Help»Find Examples to open the NI Example Finder.
❑ Confirm that the Task option is selected on the Browse tab.
❑ Double-click the Hardware Input and Output task to find examples related to hardware input and
output.
❑ Double-click the GPIB task.
❑ Select the VI shown in this directory.
❑ Notice that a description of the VI is provided in the Information window so that you can verify
that this VI meets your needs.
❑ Double-click the VI name to open the VI.
❑ Close the VI after you finish exploring it.
2. You want to learn more about Express VIs, especially their use in filtering signals. Use the NI
Example Finder to find an appropriate VI.
❑ The NI Example Finder should still be open from the previous step. If not, open the NI Example
Finder.
❑ Click the Search tab in the NI Example Finder.
❑ Enter express in the Enter keyword(s) field to find VIs that contain Express VIs.
❑ Double-click the Express result that appears in the Double-click keyword(s) field.
❑ This keyword is associated with many example VIs, as demonstrated by the number of VIs
returned. You can select any one of these Vis and read the description in the Information window.
❑ Double-click Express Filter.vi to open it.
10
❑ Double-click the Tone Measurements Express VI to open the configuration dialog box. Notice that
the selections in the configuration dialog box match the information in the Context Help window.
❑ Click the OK button to close the configuration dialog box.
4. Anchor the Context Help window so that you can move your mouse without the contents of the
window changing. The Context Help window should show information about the Simulate Signal
Express VI.
❑ Move your mouse over the Simulate Signal Express VI.
❑ To anchor the context help window, select the Lock button in the
lower left corner of the window.
Tip If the contents of the window change before you lock the window, avoid passing your mouse
over other objects on the way to the Context Help window. Move the window closer to the object of
interest to view Context Help for that item.
❑ Move your mouse over another object. Notice the contents of the window do not change while
the Lock button is selected.
❑ Deselect the Lock button to resume normal operation of the window.
5. Modify the Description and Tip associated with the Simulated frequency control to change the
content shown in the Context Help window.
❑ Select Window»Show Front Panel to open the front panel of the VI.
❑ Move your mouse over the Simulated frequency control.
❑ Read the contents of the Context Help window.
❑ Right-click the Simulated frequency control.
❑ Select Description and Tip from the shortcut menu.
❑ Replace the text in the "Simulated frequency" Description box with the text This is the
description of the control.
❑ Replace the text in the "Simulated frequency" Tip box with the text This is the tip for the control.
❑ Click the OK button.
❑ Move your mouse over the Simulated frequency control.
❑ Notice that the contents of the Context Help window changed to match the text you typed in the
Description field of the Description
and Tip dialog box.
❑ Run the VI.
❑ Place your mouse cursor over the Simulated frequency control.
❑ Notice that the tool tip that appears matches the text you typed in the
Tip field of the Description and Tip dialog box.
❑ Click the Stop button.
LabVIEW Help
6. Use the LabVIEW Help to learn more information about the Filter Express VI.
❑ Select Window»Show Block Diagram to open the block diagram of the Express Filter VI.
❑ Right-click the Filter Express VI and select Help from the shortcut menu. This opens the LabVIEW
Help topic for the Filter Express VI.
Note To access the LabVIEW Help for this topic, you can also select the Detailed Help
link in the Context Help window while the Filter Express VI is selected, or click the
question mark in the Context Help window.
❑ Explore the topic. For example, what is the purpose of the Phase Response dialog box option?
❑ Close the LabVIEW Help window.
11
7. Close the Express Filter VI when you finish. Do not save changes.
Goal
Use the debugging tools built into LabVIEW.
Description
Complete the following steps to load a broken VI and correct the errors. Use single-stepping and
execution highlighting to step through the VI.
❑ Notice the Run button on the toolbar appears broken indicating that the VI is broken and cannot
run.
2. Display and examine the block diagram of Debug Exercise (Main) VI.
❑ Select Window»Show Block Diagram to display the block diagram shown.
12
❑ The Random Number (0-1) function produces a random number between 0 and 1.
❑ The Multiply function multiplies the random number by 10.0.
❑ The numeric constant is the number multiplied with the random number.
❑ The Debug Exercise (Sub) VI, located in the C:\Exercises\LabVIEW Basics I\Debugging\Supporting
Files directory, adds 100.0 and calculates the square root of the value.
13
❑ Data appear on the front panel as you step through the VI. The VI generates a random number
and multiplies it by 10.0. The subVI adds 100.0 and takes the square root of the result.
❑ When a blinking border surrounds the entire block diagram, click the Step Out button to stop
single-stepping through the Debug Exercise (Main) VI.
11. Place breakpoints on the block diagram to pause execution at that location.
❑ Use the Breakpoint tool to click nodes or wires. Place a breakpoint on the block diagram to pause
execution after all nodes on the block diagram execute.
❑ Click the Run button to run the VI. When you reach a breakpoint during execution, the VI pauses
and the Pause button on the toolbar appears red.
❑ Click the Continue button to continue running to the next breakpoint or until the VI finishes
running.
❑ Use the Breakpoint tool to click the breakpoints you set and remove them.
14
Exercise 3-1: Determine Warnings VI
Goal
Create and document a simple VI.
Scenario
You must create a portion of a larger project. The lead developer gives you
the inputs of the VI, the algorithm, and the expected outputs. Build and
document a VI based on the design given.
Design
Inputs and Outputs
Type Name Properties
Numeric control Current Temp Double-precision, floating point
Numeric control Max Temp Double-precision, floating point
Numeric control Min Temp Double-precision, floating point
String indicator Warning Text Three potential values:
Heatstroke Warning, No Warning, and Freeze Warning
Round LED indicator Warning? —
Flowchart
Determine Warnings VI Flowchart
15
Implementation
Follow the instructions given below to create a front panel similar to the front panel shown, which
retrieves from the user the current temperature, the maximum temperature, and the minimum
temperature, and displays to the user the warning string and the warning Boolean LED. This VI is part
of the temperature weather station project studied throughout the
course.
16
5. Create a string indicator for the warning text.
❑ Place a string indicator on the front panel.
❑ Change the label text of the string indicator to Warning Text.
6. Create a Round LED or other Boolean indicator for the warning Boolean.
❑ Place a Round LED on the front panel.
❑ Change the label text of the Boolean indicator to Warning?.
10. If the Current Temp is equal to or greater than the Max Temp, generate a Heatstroke Warning
string, otherwise generate a No Warning string.
❑ Add the Select function to the block diagram to the right of the Greater Or Equal? function.
❑ Wire the output of the Greater Or Equal? function to the s input terminal of the Select function.
❑ Add a string constant to the block diagram to the upper left of the Select function.
❑ Enter Heatstroke Warning in the string constant.
❑ Wire the Heatstroke Warning string to the t input of the Select function.
❑ Hold down the <Ctrl> key and click and drag the Heatstroke Warning string constant to the lower
left of the Select function to create a copy of the constant.
❑ Enter No Warning in the second string constant.
❑ Wire the No Warning string to the f input of the Select function.
17
11. If the Current Temp is equal to or less than the Min Temp, generate a Freeze Warning string,
otherwise use the string generated in step 10.
❑ Create a copy of the Select function and place it to the right of the Less Or Equal?.
❑ Wire the output terminal of the Less Or Equal? function to the s input terminal of the Select
function.
❑ Create a copy of the string constant and place it to the upper left of the Select function.
❑ Enter Freeze Warning in the string constant.
❑ Wire the Freeze Warning string to the t input terminal of the Select function.
❑ Wire the output of the previous Select function to the f input terminal of the new Select function.
13. Generate the Warning? Boolean control by determining if the value of Warning Text is equal to
No Warning.
❑ Add a Not Equal? function to the left of the Warning? Boolean function.
❑ Wire the output of the second Select function to the x input terminal of the Not Equal? function.
❑ Wire the No Warning string constant to the y input terminal of the Not Equal? function.
❑ Wire the output of the Not Equal? function to the Warning? Function.
14. Document the code using the following suggestions on the front panel.
❑ Create tip strips for each control and indicator stating the purpose of the object and the units
used. To access tip strips, right-click a control, and select Description and Tip.
❑ Document the VI Properties, giving a general description of the VI, a list of inputs and outputs,
your name, and the date the VI was created. To access the VI Properties dialog box, select File»VI
Properties.
❑ Document the block diagram algorithm with a free label.
Test
1. Test the VI by entering a value for Current Temp, Max Temp, and Min Temp, and running the VI
for each set.
The expected Warning Text string and Warning? Boolean value for each set of input values:
What happens if you input a Max Temp value that is less than the Min Temp? What would you
expect to happen?
18
Exercise 3-2: Auto Match VI
Goal
Use a While Loop and an iteration terminal and pass data through a tunnel.
Scenario
Build a VI that continuously generates random numbers between 0 and 1000
until it generates a number that matches a number selected by the user.
Determine how many random numbers the VI generated before the
matching number.
Design
Inputs and Outputs
Flowchart
19
Implementation
Open a blank VI and build the following front panel. Modify the controls and indicators as shown in
the following front panel and as described in the following steps.
2. Set the properties for the Number to Match control so that the default value is 50, the data range
is from 0 to 1000, the increment value is 1, and the digits of precision is 0.
❑ Right-click the Number to Match control and select Data Range from the shortcut menu. The
Data Range page of the Numeric Properties dialog box appears.
❑ Remove the checkmark from the Use Default Range checkbox.
❑ Set the Default Value to 50.
❑ Set the Minimum value to 0 and select Coerce from the Out of Range Action pull-down menu.
❑ Set the Maximum value to 1000 and select Coerce from the Out of Range Action pull-down
menu.
❑ Set the Increment value to 1 and select Coerce to Nearest from the Out of Range Action pull-
down menu.
❑ Select the Format and Precision tab.
❑ Select Floating Point and change Precision Type from Significant digits to Digits of precision.
❑ Enter 0 in the Digits text box and click the OK button.
20
❑ Add the Round To Nearest function to the block diagram. This function rounds the random
number to the nearest integer.
8. Compare the randomly generated number to the value in the Number to Match control.
❑ Add the Not Equal? function to the block diagram. This function compares the random number
with Number to Match and returns True if the numbers are not equal; otherwise, it returns False.
9. Repeat the algorithm until the Not Equal? function returns True.
❑ Add a While Loop from the Structures palette to the block diagram.
❑ Right-click the conditional terminal and select Continue if True from the shortcut menu.
10. Display the number of random numbers generated to the user by adding one to the iteration
terminal value.
❑ Wire the iteration terminal to the border of the While Loop. A blue tunnel appears on the While
Loop border.
Tip Each time the loop executes, the iteration terminal increments by one. Wire the iteration value
to the Increment function because the iteration count starts at 0. The iteration count passes out of
the loop upon completion.
❑ Add the Increment function to the block diagram. This function adds 1 to the While Loop count.
11. Save the VI as Auto Match.vi in the C:\Exercises\LabVIEW Basics I\Automatch directory.
Testing
4. Change Number to Match and run the VI again. Current Number updates at every iteration of the
loop because it is inside the loop. # of iterations updates upon completion because it is outside the
loop.
21
Exercise 3-3: While Loops versus For Loops
Goal
Understand when to use a While Loop and when to use a For Loop.
Description
For the following scenarios, decide whether to use a While Loop or a For Loop.
Scenario 1
Acquire a pressure every second for one minute.
1. If you use a While Loop, what is the condition that you need to stop the loop?
2. If you use a For Loop, how many iterations does the loop need to run?
3. Is it easier to implement a For Loop or a While Loop?
Scenario 2
Acquire a pressure until the pressure is 1400 psi.
1. If you use a While Loop, what is the condition that you need to stop the loop?
2. If you use a For Loop, how many iterations does the loop need to run?
3. Is it easier to implement a For Loop or a While Loop?
Scenario 3
Acquire a pressure and a temperature until both values are stable for two minutes.
1. If you use a While Loop, what is the condition that you need to stop the loop?
2. If you use a For Loop, how many iterations does the loop need to run?
3. Is it easier to implement a For Loop or a While Loop?
Scenario 4
Output a voltage ramp starting at zero, increasing incrementally by 0.5 V every second, until the
output voltage is equal to 5 V.
1. If you use a While Loop, what is the condition that you need to stop the loop?
2. If you use a For Loop, how many iterations does the loop need to run?
3. Is it easier to implement a For Loop or a While Loop?
Answers
Scenario 1
Acquire a pressure every second for one minute.
1. While Loop: Time = 1 minute
2. For Loop: 60 iterations
3. Both are possible.
Scenario 2
Acquire a pressure until the pressure is 1400 psi.
1. While Loop: Pressure = 1400 psi
2. For Loop: unknown
3. A While Loop. Without more information, a For Loop is impossible.
Scenario 3
Acquire a pressure and a temperature until both values are stable for two minutes.
22
1. While Loop: [(Last Temperature = Previous Temperature) for 2 minutes or more] AND [(Last
Pressure = Previous Pressure) for 2 minutes or more]
2. For Loop: unknown
3. A While Loop. Without more information, a For Loop is impossible.
Scenario 4
Output a voltage ramp starting at zero, increasing incrementally by 0.5 V every second, until the
output voltage is equal to 5 V.
1. While Loop: Voltage = 5 V
2. For Loop: 11 iterations
3. Both are possible.
23
Exercise 3-4: Average Temperature VI
Goal
Use a For Loop and shift registers to average data.
Scenario
The Temperature Monitor VI acquires and displays temperature. Modify the VI to average the last
three temperature measurements and display the running average on the waveform chart.
Design
Temperature Monitor VI Front Panel
To modify this VI, you need to retain the temperature values from the previous two iterations, and
average the values. Use a shift register with an additional element to retain data from the previous
two iterations. Initialize the shift register with a reading from the temperature sensor. Chart only the
average temperature.
Implementation
1. Test the VI. If you have hardware, follow the instructions in the Hardware Installed column.
Otherwise, follow the instructions in the No Hardware Installed column.
24
• Open Temperature Monitor (Demo) VI in the C:\Exercises\LabVIEW Basics I\No Hardware
Required\Average Temperature directory.
• Run the VI. Notice the variation in the simulated temperature reading.
2. Stop the VI by changing the state of the Power switch on the front panel.
Notice that the Power switch immediately switches back to the On state. The mechanical action of
the switch controls this behavior. In the following steps, modify the VI to reduce the number of
temperature spikes.
❑ Right-click the right or left border of the While Loop and select Add Shift Register from the
shortcut menu to create a shift register.
❑ Right-click the left terminal of the shift register and select Add Element from the shortcut menu
to add an element to the shift register.
❑ Press the <Ctrl> key while you click the Thermometer VI and drag it outside the While Loop to
create a copy of the subVI.
The Thermometer VI returns one temperature measurement from the temperature sensor and
initializes the left shift registers before the loop starts.
❑ Place the Compound Arithmetic function on the block diagram.
Configure this function to return the sum of the current temperature and the two previous
temperature readings.
❑ Use the Positioning tool to resize the Compound Arithmetic function to have three left terminals.
❑ Place the Divide function on the block diagram. This function returns the average of the last three
temperature readings.
❑ Wire the functions together as shown in Figure 4-24.
❑ Right-click the y terminal of the Divide function and select Create»Constant.
❑ Enter 3 and press the <Enter> key.
25
5. Save the VI.
Testing
1. Run the VI.
2. If you have hardware installed, place your finger on the temperature sensor of the DAQ Signal
Accessory to increase the temperature reading.
During each iteration of the While Loop, the Thermometer VI takes one temperature measurement.
The VI adds this value to the last two measurements stored in the left terminals of the shift register.
The VI divides the result by three to find the average of the three measurements, the current
measurement plus the previous two. The VI displays the average on the waveform chart. Notice that
the VI initializes the shift register with a temperature measurement.
3. Stop the VI by changing the state of the Power switch on the front panel.
26
Exercise 3-5: Temperature Multiplot VI
Goal
Plot multiple data sets on a single waveform chart and customize the chart
view.
Scenario
Modify the VI from Exercise 3-4 to plot both the current temperature and the running average on
the same chart. In addition, allow the user to examine a portion of the plot while the data is being
acquired.
Design
Average Temperature VI Front Panel
To allow the user to examine a portion of the plot while the data is being acquired, display the scale
legend and the graph palette for the waveform chart. Also, expand the legend to show additional
plots.
To modify the block diagram you must modify the chart terminal to accept multiple pieces of data.
Use a Bundle function to combine the average temperature and the current temperature into a
cluster to pass to the Temperature History chart terminal.
27
Implementation
Tip Select the Substitute Copy for Original option to close the Average Temperature VI and work in
the Temperature Multiplot VI. You can create the directory if it does not
exist.
In the steps below, you modify the block diagram similar to that shown. Modify the block diagram
first, then modify the front panel.
3. Pass the current temperature and the average temperature to the Temperature History chart
terminal.
❑ Delete the wire connecting the Divide function to the Temperature History chart terminal.
❑ Add a Bundle function between the Divide function and the Temperature History chart terminal.
If necessary, enlarge the While Loop to make space.
❑ Wire the output of the Divide function to the top input of the Bundle function.
❑ Wire the current temperature to the bottom input of the Bundle function. The current
temperature is the output of the Thermometer subVI inside the While Loop.
❑ Wire the output of the Bundle function to the Temperature History chart terminal.
In the following steps, modify the front panel similar to the one shown.
28
Temperature Multiplot VI Front Panel
6. Show the scale legend and graph palette of the waveform chart.
❑ Right-click the Temperature History waveform chart and select Visible Items»Scale Legend from
the shortcut menu.
❑ Right-click the Temperature History waveform chart and select Visible Items»Graph Palette from
the shortcut menu.
Test
1. Run the VI. Use the tools in the scale legend and the graph palette to examine the data as it is
generated.
2. Change the Power switch to the Off position to stop the VI.
29
Exercise 3-6: Determine Warnings VI
Goal
Modify a VI to use a Case structure to make a software decision.
Scenario
You created a VI where a user inputs a temperature, a maximum temperature, and a minimum
temperature. A warning string is generated depending on the relationship of the given inputs.
However, a situation could occur that causes the VI to work incorrectly. The user could enter a
maximum temperature that is less than the minimum temperature. Modify
the VI so that a different string is generated to alert the user to the error:
"Upper Limit < Lower Limit." Set the Warning? Boolean indicator to True to indicate the error.
Design
Modify the flowchart created for the original Determine Warnings VI as
Shown.
The original block diagram: This VI must have a Case structure added to execute the code
if the maximum temperature is greater than or equal to the minimum temperature. Otherwise, the
code will not execute. Instead, a new string is generated and the Warning? Boolean indicator is set
to True.
30
Determine Warnings VI Block Diagram
Implementation
Follow the instructions given below to modify the block diagram similar to
that shown. This VI is part of the temperature weather station project.
3. Create space on the block diagram to add the Case structure. The Max Temp and Min Temp
controls and the Warning Text and Warning? indicators should be outside of the new Case
structure, because both cases of the Case structure use these indicators and controls.
❑ Select the Min Temp and Max Temp control terminals.
Tip To select more than one item press the <Shift> key while you select the items.
❑ While the terminals are still selected, use the left arrow key on the keyboard to move the controls
to the left.
❑ Select the Warning Text and Warning? indicator terminals.
❑ Align the terminals by selecting Align Objects»Left Edges.
31
❑ While the terminals are still selected, use the right arrow key on the keyboard to move the
indicators to the right.
5. If Min Temp is less than Max Temp, execute the code that determines
the warning string and boolean.
❑ While the True case is visible, right-click the border of the Case
structure, and select Make This Case False from the shortcut menu.
When you create a Case structure around existing code, the code is
automatically placed in the True case.
6. If Min Temp is greater than Max Temp, create a custom string for the
Warning Text indicator and set the Warning? indicator to True, as Shown.
Testing
1. Switch to the front panel of the VI.
32
2. Resize the Warning Text indicator to a length to accommodate the new string.
3. Test the VI by entering values from Table 4-4 for Current Temp, Max Temp, and Min Temp, and
running for each set.
33
Exercise 3-7 (Self-Study): Square Root VI
Goal
Create a VI that uses a Case structure to make a software decision.
Scenario
Build a VI that calculates the square root of a number the user enters. If the number is negative,
display the following message to the user: Error... Cannot find the square root of a negative
number.
Design
Inputs and Outputs
Flowchart
Implementation
1. Open a blank VI and build the front panel shown.
34
Square Root VI Block Diagram
5. If Number is less than 0, display a dialog box that informs the user of the error.
❑ Add the Case structure to the block diagram.
❑ Click the decrement or increment button to select the False case.
❑ Add a numeric constant to the False case.
❑ Right-click the numeric constant and select Representation»I32.
❑ Enter -99999 in the numeric constant.
❑ Wire the numeric constant to the right edge of the case structure.
❑ Wire the new tunnel to the Square Root Value terminal.
❑ Add the One Button Dialog function to the False case. This function displays a dialog box that
contains a specified message.
❑ Right-click the message input of the One Button Dialog function and select Create»Constant from
the shortcut menu
❑ Enter Error...Negative Number in the constant.
❑ Finish wiring the False case as shown in Figure 4-43.
6. If Number is greater than or equal to 0, calculate the square root of the number.
❑ Select the True case of the Case structure.
❑ Place the Square Root function in the True case. This function returns the square root of Number.
❑ Wire the function as shown.
35
7. Save the VI as Square Root.vi in the C:\Exercises\LabVIEW Basics I\Square Root directory.
Testing
1. Display the front panel.
36
Exercise 3-8 (Self-Study): Determine Warnings VI (Challenge)
Goal
Modify an existing VI to use the Formula Node or a Case structure to make a software decision.
Scenario
In the Determine Warnings VI from Exercise 4-1, you used the Select function to pass a string based
on decision. Revise this block diagram to use either a Formula Node or a Case structure (or a
combination of both) to complete the same purpose.
Design
Inputs and Outputs
Type Name Properties
Numeric Control Current Temp Double-precision, floating-point
Numeric Control Max Temp Double-precision, floating-point
Numeric Control Min Temp Double-precision, floating-point
String Indicator Warning Text Three potential values:
Heatstroke Warning, No Warning, and Freeze Warning
Round LED Warning? —
Flowchart
Flowchart shown was used in Exercise 3-1 to create the Determine Warnings VI.
Implementation
As part of the challenge, no implementation instructions are given for this exercise. The VI you
should start from is located in the C:\Exercises\LabVIEW Basics I\Determine Warnings Challenge
directory.
If you need assistance, ask for the solution VIs.
37
Further Exercises
1. a) Create a VI capable of calculating the roots of a quadratic equation, using the formula
2. Create a VI capable of producing a red LED and textual warning (Freeze warning, Heatstroke
warning and No warning) as the two outputs. The two thresholds (Min Temp and Max Temp
are given), in addition to the Input Temperature.
4. Create a VI capable of controlling a set of traffic lights, following the following rules:
38
Links
Software
http://zone.ni.com/devzone/cda/tut/p/id/4435
Forum
http://forums.ni.com/ni/board?board.id=beta18
39