Professional Documents
Culture Documents
You also can open the VI by selecting FileOpen and navigating to labview\examples\apps\tempsys.llb\Temperature System Demo.vi.
Select WindowShow Tools Palette to display the Tools palette. If the Automatic Tool Selection LED in the Tools palette is not lit, click the Automatic Tool Selection button to enable automatic tool selection. Move the cursor over the slider in the System Controls section. LabVIEW selects the Operating tool. Click and drag the slider to change the value. Notice the speed of the simulated acquisition changes as you change the value. You operate LabVIEW controls just as you would similar real controls. Other ways to operate knob controls using the Operating tool include: Clicking the black region of the slider to move the slider to the value at the point you clicked. Clicking the digital display and entering a number. If you use this method, the Enter button appears on the toolbar. LabVIEW does not pass the value to the control until you click this button or press the <Enter> key.
LabVIEW programming, including structures, functions, and subVIs. You also can press the <Ctrl-E> keys to display the block diagram. Double-click the Temperature Status subVI icon to display the front panel of the subVI. Click the Run Continuously button and adjust the value of the High Limit and Low Limit knobs. Notice the Temperature Status VI is a fully functional VI that performs basic comparisons between the Temperature and the High Limit and Low Limit values. When the temperature is greater than the High Limit, the Over Limit indicator turns red. When the temperature is less than the Low Limit, the Under Limit indicator turns blue. When you run the Temperature System Demo VI, it calls the Temperature Status subVI to perform this basic comparison. Click the Run Continuously button again to stop the VI from continuously running. Close the front panel for the Temperature Status VI by selecting FileClose. Do not close the Temperature System Demo VI, because you will use it in the next chapter.
detailed than the information in the Context Help window. Most VIs and functions that ship with LabVIEW have links in the Context Help window to detailed VI and function reference in the LabVIEW Help. Click the blue link at the bottom of the Context Help window to view the function reference information in the LabVIEW Help.
Perform a more specific search. Click the Search button Enter single-buffered analog output and click Search. Double-click the document listed to view the results. When you are finished, close Acrobat Reader.
3. Create a VI
Your objective is to build a simple VI that converts a Celsius temperature reading to Fahrenheit.
If you click outside the text box without entering text, the label defaults to thermometer. To show the label again, right-click the control and select Visible ItemsLabel from the shortcut menu. By default, a thermometer is an indicator because it displays a data value. In this VI, however, use the deg C thermometer as a control because it is the data source. Rightclick the deg C thermometer and select Change to Control from the shortcut menu. To make it easier to precisely enter a value into the deg C thermometer, make the Digital Display visible. To do this, right-click the thermometer and select Visible ItemsDigital Display from the shortcut menu.
Now that you have a thermometer control for the Celsius temperature, you need an indicator to display the Fahrenheit value. Select another thermometer from the ControlsNumeric palette and place it on the front panel. Label this thermometer deg F as you did in step 3 and make the Digital Display visible as you did in step 5.
Because this thermometer will display temperatures in degrees Fahrenheit, change the scale of the thermometer so it can display readings higher than 100 degrees. To change the scale of the deg F thermometer, double-click the topmost value of the scale and type 212, which is the Fahrenheit equivalent of 100 degrees Celsius, the highest visible value on the deg C thermometer. Press the <Enter> key. (Optional) Use the Positioning tool to rearrange or resize objects. Move the cursor over the center of an object to select the Positioning tool. o To move an object, click the object and release the mouse button to select the object. A moving dashed outline called a marquee highlights the object. Drag the object to move it.
o To resize an object, move the cursor over a corner of the object to display resizing handles . Move the Positioning tool over a resizing handle to change the tool to the resizing cursor. Use the resizing cursor to drag the resizing handles until the dashed border outlines the size you want, and release the mouse button. Your front panel should look similar to the following image.
o Move the cursor over the black arrow on the right side of the deg C terminal. The terminal blinks, and LabVIEW selects the Wiring tool. o Click the deg C terminal to tack a wire to the terminal. You do not need to hold down the mouse button. o Move the cursor to a terminal on the Multiply function until the terminal blinks. o Click to tack down the wire and wire the two terminals together. You need to multiply the deg C value by 1.8. Right-click the unwired input terminal on the Multiply function and select CreateConstant. LabVIEW creates a numeric constant value and wires it to the input terminal, with the numeric value highlighted for you to enter a value. Type 1.8 and click the Enter button, or click anywhere on the block diagram. from the You need to add 32 to complete the calculation. Select an Add function FunctionsNumeric palette and drag it to the block diagram. Before you click the mouse to place the Add function on the block diagram, drag the function just to the right of the output terminal of the Multiply function. When a wire that connects the output terminal of the Multiply function and one of the input terminals of the Add function appears, click the mouse button to place the function on the block diagram. LabVIEW automatically wires the two functions together. If the functions are not wired together, use the Wiring tool as described in step 4. Right-click the unwired input terminal of the Add function and select CreateConstant, as you did in step 4. Type 32 and click the Enter button or click anywhere on the block diagram. Now that youve multiplied the deg C value by 1.8 and added 32, you need to pass the value to the deg F terminal. Wire the output terminal of the Add function to the deg F terminal, as described in step 4. Your block diagram is now complete, and should look similar to the following image.
Select FileSave and save the VI as Convert C to F.vi in the labview\activity directory.
Run the VI by clicking on the Run button. Notice that LabVIEW converts the Celsius temperature to 98.6 degrees Fahrenheit and displays it on the deg F thermometer and its digital display. Enter other values in the deg C thermometer and run the VI. Close the VI by selecting FileClose to close the VI.
4. Document a VI
Your objective is to document a VI that you have created.
Right-click the deg C thermometer and select Description and Tip from the shortcut menu. Type the description and tip information for the control, as shown in the following illustration, and click the OK button.
Right-click the deg F thermometer and select Description and Tip from the shortcut menu. Enter Displays the calculated Fahrenheit temperature for the description, and Fahrenheit temperature for the tip. Click the OK button. Move the cursor over the deg C thermometer. Notice the information you entered in the deg C Tip field of the Description and Tip dialog box shows up as a tip strip. Select HelpShow Context Help to display the Context Help window. Move the cursor over the deg C thermometer and then over the deg F thermometer. Notice the information you entered in the Description and Tip dialog box appears in the Context Help window. Move the cursor over the icon in the upper right corner of the block diagram or front panel window. The description you entered in the Documentation page of the VI Properties dialog box appears in the Context Help window. Save the VI.
5. Debug a VI
Your objective is to use the probe tool and the probe window and to examine data flow in the block diagram using execution highlighting.
5.1. Probes
If it is not already open from Chapter 4, open the Convert C to F VI by selecting FileOpen and navigating to labview\activity\solution\Convert C to F.vi.
Block Diagram
Select WindowShow Diagram. If the Tools palette is not open, select WindowShow Tools Palette.
Select the Probe tool from the Tools palette and click the wire coming out of the Multiply function. A Probe window appears with the title [1] Probe and a yellow glyph with the number of the probe appears on the wire, as shown in the following illustration.
If automatic tool selection is enabled and you move the cursor over objects on the front panel or block diagram, LabVIEW automatically selects the corresponding tool from the Tools palette. However, you must manually select the Breakpoint, Probe, and Coloring tools.
Front Panel
Return to the front panel. Move the Probe window so you can view the probe value and both of the thermometer values. Run the VI. The value at the probe appears in the [1] Probe window. Close the [1] Probe window by clicking the close box at the top of the Probe window title bar.
Block Diagram
On the block diagram, begin execution highlighting by clicking the Highlight Execution button illuminated light bulb , in the toolbar. The Highlight Execution button changes to an .
Click the Run button to run the VI. Notice that execution highlighting animates the VI block diagram execution. Moving dots represent the flow of data through the VI. Also notice that data values appear on the wires and display the values contained in the wires at that time, as shown in the following block diagram, just as if you had probed the wire.
in the toolbar. 9
Finish executing the block diagram by clicking the Step Out button in the toolbar. Clicking this button completes all remaining steps in the block diagram.
6.1. VI Templates
In addition to the example VIs, LabVIEW includes several VI templates you can use to create common VIs, including state machines, custom dialog boxes and about boxes, and continuous analog input. Access the VI templates by selecting FileNew and selecting Start from template.
10
o Use the Positioning tool to drag out the plot legend to include two plots. Move the Positioning tool over the corner of the legend to display resizing handles . Move the Positioning tool over a resizing handle to change the tool to the resizing cursor, which you drag out to enlarge the legend. o Rename Plot 1 to Random Average by double-clicking the label and entering the new text. You can resize the label area by using the Positioning tool to drag either of the left corners. o Change the plot style of the Current Value plot. Right-click the plot and select the plot style from the Common Plots shortcut menu. o Change the color of the Current Value plot. Right-click the plot and select the Color shortcut menu. Select a light blue color from the color picker that appears.
11
The order of the inputs to the Bundle function determines the order of the plots on the chart. For example, if you wire the raw data to the bottom input of the Bundle function and the average to the top, the first plot corresponds to the running average, and the second plot corresponds to the raw data. Use the Wiring tool to connect the new element of the Bundle function to the wire that connects the Random Number function and the right-most shift register . The Bundle function bundles the running average and the current value into a cluster. Notice that when you wire the second element of the Bundle function, the Random Plot terminal changes appearance to indicate that its data type is now a cluster of numbers.
o Choose absolute time by selecting the Time & Date option from the Format pull-down menu. For the waveform chart to start at a certain time and increment at certain intervals, you can edit the Xo and dX values respectively. Format the chart to display the data starting from noon, April 1, 2000, and increment every 10 minutes, as shown in the following image. Click the OK button to save your changes.
Select the relative time format and select Decimal from the Format pull-down menu. Modify the dialog box, as shown in the following illustration, and click the OK button.
13
Click the Run button to run the VI. Save the VI as Multiple Random Plot.vi in the labview\activity directory.
14
For this chapter, transpose the 2D array to have each column of the spreadsheet file contain a data array. Use the Wiring tool to right-click the Transpose? (no:F) terminal and select CreateConstant from the shortcut menu. This Boolean constant controls whether or not LabVIEW transposes the 2D array before writing the data to file. Move the cursor over the center of the Boolean constant. LabVIEW selects the Operating tool. Click the Boolean constant to change the value to TRUE. Your block diagram should look similar to the following illustration.
Select FileSave As to save a copy of the VI. From the standard File dialog box that appears, name the new VI Arrays to File.vi and save it in the labview\activity directory.
15
o Digital Control located on the ControlsNumeric palette. Label it Square Duty Cycle (%). o Enum Control located on the ControlsRing & Enum palette. Label it Signal Source. o Digital Control located on the ControlsNumeric palette. Label it Phase. o Boolean Push button located on the ControlsBoolean palette. Label it Reset Phase. o Waveform Graph located on the ControlsGraph palette. Leave its label as Waveform Graph. o Boolean Stop button located on the ControlsBoolean palette. o (Optional) Use the Coloring tool to color the button red. Add elements to the Signal Source enum control. o Click in the text box of the enum. o Type Sine Wave and press <Shift-Enter> to add another element. o Type Triangle Wave <Shift-Enter>, Square Wave <Shift-Enter>, and Sawtooth Wave. o Click the Enter button on the toolbar or click anywhere on the background of the front panel to enter the elements.
Arrange the objects on the front panel to appear similar to the following illustration.
The Signal Source control selects the type of waveform that you want to generate. The square duty cycle control is used only for setting the duty cycle of the square wave.
Add a While Loop that fills up most of the visible area of the block diagram window. The While Loop causes the block diagram inside it, the subdiagram, to repeat until a TRUE or FALSE value is passed to the continuation terminal . o Select the While Loop from the FunctionsStructures palette and drag it to one of the corners of the block diagram. Do not release the mouse button. o While still holding the mouse button, drag out a region to the opposite corner of the block diagram window. o When the region fills most of the block diagram window, as indicated by the dotted rectangle, release the mouse button. LabVIEW creates the While Loop.
Because the Stop button will control the While Loop, wire the Stop terminal to the continuation terminal. o Move the Stop terminal next to the continuation terminal of the While Loop. As you drag the Boolean terminal close to the terminal, press the spacebar to activate automatic wiring. When LabVIEW draws a wire connecting the two terminals, release the mouse button. You also can use the Wiring tool to wire the two terminals together. o Right-click the continuation terminal of the While Loop and select Stop if True from the shortcut menu. Notice the continuation terminal changes its appearance to the Stop if True state . When the user presses the Stop button, it passes a TRUE value to the continuation terminal, which stops the While Loop.
Because it is the indicator, move the Waveform Graph terminal to the right side of the While Loop. Arrange all the other terminals, which are controls, to the left side of the While Loop. Between the controls and the Waveform Graph terminal, add a Case structure. The Case structure contains different subdiagrams, which only execute when the specific case is selected. The selector terminal of the Case structure determines which case is selected. The case selector label at the top of the Case structure indicates which case is currently visible. o Select the Case structure from the FunctionsStructures palette and drag it near the middle of the While Loop. Do not release the mouse button. o While still holding the mouse button, drag out a region between the control terminals and the Waveform Graph terminal. o When the region fills up most of the area between the control terminals and the Waveform Graph terminal, release the mouse button. LabVIEW creates the Case structure.
Because the Signal Source Enum will control which waveform is displayed on the graph, wire the Signal Source terminal to the selector terminal of the Case structure. o Move the Signal Source terminal just to the left of the selector terminal of the Case structure. o Use the Wiring tool to wire the Signal Source terminal to the selector terminal of the Case structure. Notice the case selector label now shows the name of one of the elements you entered in the Signal Source enum control.
17
By default, the Case structure has two cases. Because the Signal Source enum control contains four elements, you must add two more cases to the Case structure. o Right-click the Case structure and select Add Case After from the shortcut menu. Notice the case selector label indicates the new case is the Square Wave case. o Add another case as you did in step 7a. Notice the case selector label indicates the new case is the Sawtooth Wave case.
Add the waveform generation VIs to their respective cases in the Case structure. Click the increment or decrement arrow on each side of the case selector label to switch between cases. o Add the Sine Waveform VI located on the FunctionsAnalyzeWaveform Generation palette to the Sine Wave case. o Add the Triangle Waveform VI located on the FunctionsAnalyzeWaveform Generation palette to the Triangle Wave case. o Add the Square Waveform VI located on the FunctionsAnalyzeWaveform Generation palette to the Square Wave case. o Add the Sawtooth Waveform VI located on the FunctionsAnalyzeWaveform Generation palette to the Sawtooth Wave case.
Use the Wiring tool to wire the terminals from each waveform generation VI to the terminals outside the Case structure. Rearrange the position of the terminals as necessary to maintain an orderly block diagram. The first time you wire a terminal on the VI to a terminal outside the Case structure, a tunnel appears at the border of the Case structure. Thereafter, as you increment through the cases, the wire from the tunnel to the terminal outside the Case structure remains, so you only need wire from the tunnel to the terminal on the VI to complete the wire connection. o o o o o o Wire the reset phase terminal of each VI to the Reset Phase control terminal. Wire the frequency terminal of each VI to the Frequency control terminal. Wire the amplitude terminal of each VI to the Amplitude control terminal. Wire the phase terminal of each VI to the Phase control terminal. Wire the signal out terminal of each VI to the Waveform Graph terminal. Because it pertains only to the Square Wave VI, move the Square Duty Cycle (%) control terminal inside the Square Wave case of the Case structure. Wire the duty cycle (%) terminal of the Square Wave VI to the Square Duty Cycle (%) control terminal.
The sampling info terminal of each VI allows you to control the sample rate and number of samples. Add a sampling info cluster to your VI. o Use the Wiring tool to right-click the sampling info terminal and select Create Control from the shortcut menu. o Use the Positioning tool to drag the sampling info terminal outside the Case structure. When you move the terminal outside the Case structure, the wire connection is broken.
18
o Select EditRemove Broken Wires or press <Ctrl-b> to remove the broken wire. o Use the Wiring tool to wire the sampling info terminal outside the Case structure to the sampling info terminal on each VI as you did in step 9. o (Optional) You might need to move the sampling info front panel control. Select WindowShow Panel, click the front panel window, or press <Ctrl-e> to display the front panel. Use the Positioning tool to move the sampling info control. Arrange the objects on the block diagram. Your block diagram should be similar to the following illustration. Each case is shown below the While Loop to illustrate the contents of each case. Do not create separate Case structures.
19
Change #s to 200, 300, and 400. How many cycles of the waveform do you see? Why? Reset the #s control to 100 and change frequency to 10.01 Hz. What happens? Why? Change reset phase to ON. Now what happens? Why? (Optional) Select different waveforms from the Signal Source enum and repeat steps 1 through 5.
20
21
o Select a color box constant from the FunctionsNumericAdditional Numeric Constants palette and place it in the Case structure. o Click the color box constant. Select a blue color from the color picker that appears. You also can use the Coloring tool to right-click the constant to change the color. o Click the increment button at the top of the Case structure to switch cases. Add another color box constant to this case. Place it in the same place as you placed the constant in the other case. o Change the color of this constant to red as you did in step 10b. Create a Property Node for the Tank terminal. o Right-click the Tank terminal and select CreateProperty Node from the shortcut menu. A Tank Property Node appears next to the terminal. o Right-click the Property Node and select PropertiesFill Color from the shortcut menu. o Because this Property Node will change the fill color of the Tank, rather than read its color, right-click the Property Node and select Change to Write from the shortcut menu. o Move the Tank Property Node to the right of the Case structure. Move the Normal Image terminal into the case that has the blue color box constant. Move the High Image terminal into the case that has the red color box constant. Add an Invoke Node. o Select an Invoke Node from the FunctionsApplication Control palette. Place it to the right of the Case structure and across from the High Image terminal. o Right-click the Invoke Node and select Select VI Server ClassVI from the shortcut menu. o Right-click the Invoke Node and select MethodsSet VI Icon from the shortcut menu. Wire each color box constant to the Fill Color terminal of the Tank property node. Wire each image terminal to the Image File terminal of the Invoke Node. Add timing to the VI. o Select the Wait Until Next ms Multiple function from the FunctionsTime & Dialog palette and place it in an open area of the While Loop. o Use the Wiring tool to right-click the input terminal of the Wait Until Next ms Multiple function and select CreateConstant. Enter 1000. This causes the While Loop to wait 1 second (1000 milliseconds) between iterations. Use the Positioning tool to arrange the objects on the block diagram. Your block diagram should look similar to the following illustration.
22
23