Introduction to LabVIEW

advertisement
Introduction to LabVIEW - Part 2
Create a WHILE Loop and a WAVEFORM Chart
A. Use a WAVEFORM chart
1. Open a new Panel Window and place a vertical switch (Boolean subpalette) on the Panel.
Label the switch Enable. This switch is to be used to stop the data acquisition. Also use the
labeling tool to type in ON and OFF next to the switch (ON at top, OFF at bottom).
2. Place a waveform chart (Graph subpalette) in the Panel Window. Label the waveform chart
Temp History. This waveform chart will display the temperature in real time. The Graph
subpalette resides in the Control palette.
3. The legend label is currently plot 0. Relabel this by using the labeling tool A to triple-click on
plot 0 and then typing in Temp. Then click outside the text area, and the change will be
entered.
1. Since we are measuring room temperature, rescale the waveform chart by double-clicking on
10.0 in the scale and type in 90. Click outside of the area or click on the Enter key. Change
0.0 on the scale to 20 in the same manner. The result should look like that shown in the
figure below.
B. Block Diagram Creation (While Loop)
1. Open the Diagram Window by clicking on the window behind the panel window. Arrange the
two terminals in the approximate locations as shown in the figure. You will need the pointing
tool  to move the objects. When you placed the objects in the desired locations, click your
cursor in any open area within the diagram window to release the objects in the chosen
locations.
2. From the Functions palette, choose the Structures subpalette and in it, choose the While
Loop. Bring the cursor over to the Diagram Window and drag a rectangle enclosing the two
terminals. This rectangle is called the While Loop. You can enlarge or shrink the size of this
rectangle by dragging one corner with a Positioning Tool.
3. From the Functions palette  select a VI and then load a:temp.vi. This is the VI that you
created in the previous laboratory exercise. Locate your object as shown on the sketch.
4. Create a Mode switch for choosing between F or C. This serves as input to the input
terminal of your Temp V1. With your cursor, set as a Pointing Tool, point to the left side of
the VI object, click with the right mouse button and select the Create Control option in the
pop-up menu. Change your tool to a labeling tool and triple-click on the label Temp Scale.
Type in Mode in its stead, and press Enter button on the icon bar.
5. Go back to the Panel Window by clicking on that window. Double-click on the OFF label on
the Mode switch and change it by typing “deg F”. Go to the Tool palette and change the tool
to the Operating Tool (forefinger icon located on the top left hand corner of the Tool palette).
With this operating tool, push (click on) the Mode button. Change the ON to “deg C”, as was
done earlier for the OFF label. To change the states of this Mode switch, click on it with the
Operating Tool.
6. Select the wiring tool in the Tool palette and wire the objects in the Diagram Window as
shown in the figure.
7. Return to the Panel Window. Make sure that the Enable switch is at the ON position, by
clicking it with the Operating Tool. Run the VI by clicking the  button at the icon bar. The
While Loop will cause whatever program which resides inside of the rectangle to operate
indefinitely as long as the specified condition is TRUE. For our case, the TRUE condition
occurs whenever the Enable switch is ON. The Temp.vi that you created will take and return a
new measurement, and will display the measured value on the waveform chart.
8. Stop the data acquisition by clicking the Enable switch. This signals a FALSE state that ends
the While loop.
9. Modify the Enable switch so that it is already ON when you run the VI. Halt the VI if it is still
running. Turn the Enable switch to ON. With the cursor at the Enable switch, click with right
mouse button. Choose Data Operations  Make Current Value Default. This makes the ON
state at the Enable switch the default state of the switch. With the cursor at the Enable switch,
again click with right mouse button. Choose Mechanical Action  Latch When Pressed.
10. Run the VI. Click the Enable switch to stop the data collection process. Note that the switch
moves momentarily to the OFF position and then changes back to ON.
C. Adding Timing
When you run the VI, the While loop operates very rapidly. Exactly how rapidly depends
on the computer that you are using. However if we are interested in taking measurements at
some regular fixed interval, such as once per 500 milliseconds, we need a timer. This timer will
cause the loop to wait for 500 milliseconds before going through the loop again. Hence data
collection will occur only after the wait period is over. This process continues for a fixed time
interval, or until you halt it.
1. We want to modify the VI to take a temperature measurement once every 500 milliseconds, or
once every half second. Switch to the Diagram Window. From the Time & Dialog
subpalette, select the Wait Until Next ms Multiple function. Place this on the Diagram
Window inside the box representing the While loop. Next from the Function palette, select
the Numeric subpalette and then Numeric Constant. Place this on the Diagram Window next
to the Wait Until Next ms Multiple function, again inside the While loop box. Click on the
Numeric Constant box and change the value to 500. The result should look like that shown.
2. Wire the Numeric Constant to the Wait Until Next ms Multiple function. Now the While loop
will once every 500 milliseconds.
3. Run the VI. Then rerun it with a different number of milliseconds in the timing loop.
4. Save the new VI to a:TempMon.vi (or another appropriate name).
Graph Data and Make Use of Analysis VI’s
1. Select the Panel Window. From the Controls palette, select the Graph subpalette, and then
select Waveform Graph. Place this on the Panel Window as indicated in the figure below.
Label the Graph “Temp Graph”. After the data acquisition process is completed, the entire
data set will be plotted in Temp Graph. From the Controls palette, select the Numeric
subpalette. Place three Digital Indicators on the Panel as shown, and label them as Mean,
Max, and Min. These indicators will display the average, maximum and minimum
temperatures respectively. We will use only the Fahrenheit scale, so that we may delete the
Mode switch. Do this by clicking on it with the Pointing Tool, and then using the Delete key.
Because the default input to the Mode input of the Thermometer.vi is False, indicating F, this
will cause no difficulty.
2. Switch to the Diagram Window. Now we want to build the block diagram shown in the figure
below. The circled objects are the new items to be added. From the Functions palette, select
the Array subpalette, and then the Array Max & Min function. Place this as shown on the
figure. Once again select the Functions palette, then the Base Analysis subpalette, then the
Probability & Statistics subpalette. From this, select the Mean function, and locate it as
shown on the figure. Finally, using the Positioning Tool, move the Max, Min, and Mean
indicators to the locations shown on the figure, as well as the Temp Graph icon.
3. Now we are ready to complete the wiring. Using the Wiring Tool, run a wire from a junction
on the wire connecting the Temp History DBL and the Temp icon. Pass the wire through the
While box, and connect it to the input terminal of the Array Max & Min icon. Note that, after
exiting the box, the wire shows the dashed line indicating a bad wire. At the point where the
wire crosses the While box, a small portion of the box will turn gray. This point is known as a
Tunnel. Point to the Tunnel, click on the right mouse button, and select Enable Indexing. At
this point, the bad wire indication should vanish, and the entire wire up to the Array Max &
Min icon should be orange in color. Indexing allows the data to accumulate into an array,
from which we will calculate the maximum, minimum, and mean temperature. Now wire the
Mean icon, the Temp Graph icon, and the Max, Min, and Mean indicators as shown on the
figure.
4. Return to the Panel Window and run the VI for 20-30 seconds. Then halt execution by using
the Enable switch or the Stop button. After execution halts, the Temp Graph will show the
temperature over the time of execution, and the Max, Min, and Mean indicators will display
the maximum, minimum, and mean temperatures over this time interval.
5. Name this new VI a:Templot.vi using the Save As option in the File Menu and save it to your
own diskette. Then close the VI and exit LabVIEW.
Download