Вы находитесь на странице: 1из 8

Lesson 3 Implementing a VI

Exercise 3-2Project: 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

Numeric Control Max Temp Double-Precision

Numeric Control Min Temp Double-Precision

String Indicator Warning Text Three potential values:


Heatstroke Warning, No
Warning, and Freeze Warning

Round LED Warning?

© National Instruments Corporation 3-25 LabVIEW Introduction Course Manual


Lesson 3 Implementing a VI

Flowchart

Current Temp
No
>=Max Temp?

Yes

Warning Text =
Warning Text =
Heatstroke
No Warning
Warning

Current Temp
No
<= Min Temp?

Yes

Warning Text = Pass current value


Freeze Warning of Warning Text

Warning
Text = No No
Warning?

Yes

Warning ? = False Warning ? = True

Figure 3-13. Determine Warnings VI Front Panel

LabVIEW Introduction Course Manual 3-26 ni.com


Lesson 3 Implementing a VI

Implementation
Follow the instructions given below to create a front panel similar to Figure
3-14. This front panel 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 you created in the previous exercise.

Figure 3-14.Determine Warnings VI Front Panel

1. Add a new VI to the temperature weather station project you created in


the previous exercise.

❑ Select File»Open Project.

❑ Open the Weather Station.lvproj in the


C:\Exercises\LabVIEW_Basics_I\Course Project
directory.

❑ Select File»New VI.

2. Save the new VI.

❑ Select File»Save.

❑ Save the VI as Determine Warnings.vi in the


C:\Exercises\LabVIEW_Basics_I\Course Project
directory.

3. Create a numeric control for the current temperature.

❑ Place a Numeric Control on the front panel.


❑ Change the label of the numeric control to Current Temp.

© National Instruments Corporation 3-27 LabVIEW Introduction Course Manual


Lesson 3 Implementing a VI

❑ Right-click the control, select Representation, and confirm that the


representation type is set to double precision.

Tip This subVI could be used for Fahrenheit, Kelvin, or any temperature scale, as long
as all inputs use the same scale. Therefore, it is not necessary to add scale units to the
labels.

4. Create a numeric control for the maximum temperature.

❑ Hold down the <Ctrl> key and click and drag the Current Temp
numeric control to create a copy of the control.

❑ Change the label text of the new numeric control to Max Temp.

5. Create a numeric control for the minimum temperature.

❑ Hold down the <Ctrl> key and click and drag the Max Temp
numeric control to create a copy of the control.

❑ Change the label text of the new numeric control to Min Temp.
6. 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.

7. 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?.
8. Switch to the block diagram.

Tip If you do not want to use the Icon Terminal view on the block diagram, select
Tools»Options, then select Block Diagram from the Category list. Remove the
checkmark from the Place front panel terminals as icons item.

Follow the instructions given below to build a block diagram similar to the
one shown in Figure 3-15.

LabVIEW Introduction Course Manual 3-28 ni.com


Lesson 3 Implementing a VI

Figure 3-15. Determine Warnings VI Block Diagram

9. Compare Current Temp and Max Temp.

❑ Place a Greater Or Equal? function on the block diagram.


❑ Wire the Current Temp terminal to the x input terminal of the
Greater Or Equal? function.

❑ Wire the Max Temp terminal to the y input terminal of the Greater
Or Equal? function.

10. Compare Current Temp and Min Temp.

❑ Place a Less Or Equal? function on the block diagram.


❑ Wire the Current Temp terminal to the x input terminal of the Less
Or Equal? function.

❑ Wire the Min Temp terminal to the y input terminal of the Less Or
Equal? function.

11. If the Current Temp is equal to or greater than the Max Temp, generate
a Heatstroke Warning string, otherwise generate a No Warning
string.

❑ Place the Select function on 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.

© National Instruments Corporation 3-29 LabVIEW Introduction Course Manual


Lesson 3 Implementing a VI

❑ Place a string constant on 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.

12. If the Current Temp is equal to or less than the Min Temp, generate a
Freeze Warning string, else use the string generated in Step 11.

❑ 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 right 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. Display the generated text.

❑ Wire the output of the second Select function to the Warning Text
indicator.

14. Generate the Warning? Boolean by determining if the value of


Warning Text is equal to No Warning.

LabVIEW Introduction Course Manual 3-30 ni.com


Lesson 3 Implementing a VI

❑ Place a Not Equal function to the left of the Warning? Boolean.


❑ 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? Boolean.
15. 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 VI Properties, select File»VI Properties.

❑ Document the block diagram algorithm with a free label.

16. Save the VI.

Testing
1. Test the VI by inputting a value for Current Temp, Max Temp, and
Min Temp, and running for each set.
Table 3-1 shows the expected Warning Text string and Warning?
Boolean for each set of input values.

Table 3-1. Testing Values for Determine Warnings.vi

Current Temp Max Temp Min Temp Warning Text Warning?

30 30 10 Heatstroke True
Warning

25 30 10 No Warning False

10 30 10 Freeze Warning True


What happens if you input a Max Temp value that is less than the Min
Temp? What would you expect to happen? You learn to handle errors
like this one in a Exercise 3-7.

2. Save and close the VI.

© National Instruments Corporation 3-31 LabVIEW Introduction Course Manual


Lesson 3 Implementing a VI

3. Save and close the project.

End of Exercise 3-2

LabVIEW Introduction Course Manual 3-32 ni.com

Вам также может понравиться