CHAPTER 1
Building a Virtual Instrument
From the previous lesson, you had build a VI that generates a signal and displays that signal in a graph. After you complete the exercises, the front panel of the VI will look similar to the front panel in Figure 1-1.| Figure 1.1 Front Panel of the Acquiring a Signal VI |
Now, we continued the second part of Chapter 1.
Changing a Signal Type
The block diagram has a blue icon labeled Simulate Signal. This iconrepresents the Simulate Signal Express VI. An Express VI is a component of the block diagram that you can configure to perform common measurement tasks. The Simulate Signal Express VI simulates a sine wave by default.
Complete the following steps to change this signal to a sawtooth wave.
Locate the Simulate Signal Express VI, shown at left. The Simulate
Signal Express VI simulates a signal based on the configuration that
you specify.
2. Right-click the Simulate Signal Express VI and select Properties from the shortcut menu to display the Configure Simulate Signal
dialog box. (Mac OS X) Press
action as right-click.
💡 Tip You also can double-click the Express VI to display the Configure Simulate Signal dialog box.
3. Select Sawtooth from the Signal type pull-down menu.
The waveform on the graph in the Result Preview section changes to
a sawtooth wave. The Configure Simulate Signal dialog box should
appear similar to Figure 1-5.
| Figure 1.5 Configure Simulate Signal dialog box |
4. Click the OK button to save the current configuration and close the Configure Simulate Signal dialog box.
5. Move the cursor over the down arrows at the bottom of the Simulate Signal Express VI. The down arrows indicate you can reveal hidden inputs and outputs by extending the border of the Express VI.
6. When a double-headed arrow appears, shown at left, click and drag the border of the Express VI to add two rows. When you release the border, the Amplitude input appears.
In Figure 1-5, notice that Amplitude is an option in the Configure
Simulate Signal dialog box. When inputs, such as Amplitude, appear
on the block diagram and in the configuration dialog box, you can
configure the inputs in either location.
Wiring Objects on the Block Diagram
To use the knob to change the amplitude of the signal, you must connect two objects on the block diagram.
Complete the following steps to wire the knob to the Amplitude input of the Simulate Signal Express VI.
Use the Positioning tool to select, position, and resize objects.
📌 Note: You can resize only loops and structures on the block diagram. Go to the front panel to resize objects you have added to the front panel.
The terminals inside the loop are representations of front panel
controls and indicators. Terminals are entry and exit ports that
exchange information between the front panel and block diagram.
3. Deselect the Knob terminal by clicking a blank space on the block
diagram. If you want to use a different tool with an object, you must deselect the object to switch the tool.
5. When the Wiring tool appears, click the arrow on the Knob terminal and then click the arrow on the Amplitude input of the Simulate Signal Express VI, shown at left, to wire the two objects together.
wire from the Knob terminal to the Express VI.
6. Select File»Save to save the VI.
Running a VI
Running a VI executes the solution.
Complete the following steps to run the Acquiring a Signal VI.
1. Display the front panel by pressing the
2. Click the Run button or press the
3. Move the cursor over the knob.
the Operating tool to change the value of a control.
4. Using the Operating tool, turn the knob to adjust the amplitude of the sawtooth wave.
The amplitude of the sawtooth wave changes as you turn the knob. As
you change the amplitude, the Operating tool displays a tip strip that indicates the numeric value of the knob. The y-axis on the graph scales automatically to account for the change in amplitude.
darkened arrow, shown at left. You can change the value of most
controls while a VI runs, but you cannot edit the VI in other ways while the VI runs.
The STOP button stops the VI after the loop completes its current
iteration. The Abort Execution button, shown at left, stops the VI
immediately, before the VI finishes the current iteration. Aborting a VI that uses external resources, such as external hardware, might leave the resources in an unknown state by not resetting or releasing them properly. Design the VIs you create with a stop button to avoid this problem.
Modifying a Signal
Complete the following steps to scale the signal by 10 and display the results in the front panel graph.1. In the block diagram, use the Positioning tool to click the wire that connects the Simulate Signal Express VI to the Waveform Graph
terminal, shown at left.
2. Press the
3. If the Functions palette, shown in Figure 1-6, is not visible, select View»Functions Palette to display it. The Functions palette opens with the Express palette visible by default. If you have selected another palette, you can return to the Express palette by clicking Express on the Functions palette.
| Figure 1.6 Functions Palette |
can move the Waveform Graph terminal to the right to make more
room between the Express VI and the terminal.
The Configure Formula dialog box appears when you place the
Express VI on the block diagram. When you place an Express VI on
the block diagram, the configuration dialog box for that VI always
appears automatically.
📌 Note: If you place an object too close to another object on the block diagram, auto wiring might wire the two objects together. Delete the wires if the automatic wiring is wrong. To configure auto wiring select Tools»Options then select Block Diagram from the Category list. Remove the checkmark from the Enable auto wiring checkbox to turn off auto wiring.
The Formula help topic describes the Express VI, the configuration
dialog box options, and the inputs and outputs of the Express VI. Each Express VI has a corresponding help topic you can access by clicking the Help button in the configuration dialog box or by right-clicking the Express VI and selecting Help from the shortcut menu.
6. In the Formula topic, find the dialog box option whose description indicates that it enters a variable into the formula.
7. Minimize the LabVIEW Help to return to the Configure Formula
dialog box.
9. Define the value of the scaling factor by entering *10 after Sawtooth in the Formula text box.
You can use the Input buttons in the configuration dialog box or you
can use the *, 1, and 0 keyboard buttons to enter the scaling factor. If you use the Input buttons in the configuration dialog box, LabVIEW
places the formula input after the Sawtooth input in the Formula text box. If you use the keyboard, click in the Formula text box after Sawtooth and enter the formula you want to appear in the text box.
The Configure Formula dialog box should appear similar to
Figure 1-7.
| Figure 1.7 Configure Formula dialog box |
📌 Note: If you enter an invalid formula in the Formula text box, the Errors LED in the upper right corner turns from green to gray and displays the text Invalid Formula.
10. Click the OK button to save the current configuration and close the Configure Formula dialog box.
11. Move the cursor over the arrow on the Sawtooth output of the
Simulate Signal Express VI.
12. When the Wiring tool appears, click the arrow on the Sawtooth output and then click the arrow on the Sawtooth input of the Formula Express VI, shown at left, to wire the two objects together.
13. Use the Wiring tool to wire the Result output of the Formula Express VI to the Waveform Graph terminal.
Examine the wires connecting the Express VIs and terminals. The
arrows on the Express VIs and terminals indicate the direction that the data flows along these wires. The block diagram should appear similar to Figure 1-8. Use the block diagram figures as a reference. The arrangement of objects on your block diagram does not need to match the figure exactly.
| Figure 1.8 Block Diagram of the Acquiring a Signal VI |
💡 Tip You can right-click any wire and select Clean Up Wire from the shortcut menu to have LabVIEW automatically find a route for the wire around existing objects on the block diagram. LabVIEW also routes a wire to decrease the number of bends in the wire. You
also can click the Clean Up Diagram button on the block diagram toolbar to have LabVIEW automatically reroute all existing wires and rearrange objects on the block diagram to generate a cleaner look.
14. Press the <Ctrl-S> keys or select File»Save to save the VI.
Displaying Two Signals on a Graph
Complete the following steps to display two signals on the same graph.
1. In the block diagram, move the cursor over the arrow on the Sawtooth output of the Simulate Signal Express VI.
2. Use the Wiring tool to wire the Sawtooth output to the Waveform
Graph terminal.
two wires connect. A function is a built-in execution element,
comparable to an operator, function, or statement in a text-based
programming language. The Merge Signals function takes the
two separate signals and combines them so that both can display
on the same graph.
The block diagram should appear similar to Figure 1-9.
| Figure 1.9 Block Diagram showing a Merge Signals Functions |
3. Press the <Ctrl-S> keys or select File»Save to save the VI.
4. Return to the front panel, run the VI, and turn the knob control.
The graph plots the original sawtooth wave and the scaled sawtooth
wave with 10 times the amplitude, as you specified in the Formula
Express VI. The maximum value on the y-axis automatically scales as
you turn the knob.
5. Click the STOP button to stop the VI.
Customizing a Knob Control
The knob control changes the amplitude of the sawtooth wave, so labeling it Amplitude accurately describes the behavior of the knob.
Complete the following steps to customize the appearance of the knob.
1. Right-click the front panel knob and select Properties from the
shortcut menu to display the Knob Properties dialog box. Click the
Appearance tab to display the Appearance page.
2. In the Label section on the Appearance page, delete the label Knob, and enter Amplitude in the text box.
The Knob Properties dialog box should appear similar to Figure 1-10.
3. Click the Scale tab. In the Scale Style section, place a checkmark in the Show color ramp checkbox.
The knob in the front panel window updates to reflect these changes.
4. Click the OK button to save the current configuration and close the Knob Properties dialog box.
5. Save the VI.
| Figure 1.10 Knob Properties Dialog Box |
properties of the knob. For example, on the Scale page, try changing
the colors for the Marker text color by clicking the color box.
7. Click the Cancel button to avoid applying any changes you made
while experimenting. If you want to keep the changes you made, click
the OK button.
CUSTOMIZING THE WAVEFORM GRAPH
The waveform graph indicator displays the two signals. To indicate which plot is the scaled signal and which is the simulated signal, you can customize the plots.
Complete the following steps to customize the appearance of the waveform graph indicator.
1. In the front panel window, move the cursor over the top of the plot legend on the waveform graph.
Though the graph has two plots, the plot legend displays only one plot.
2. When a double-headed arrow appears, shown in Figure 1-11, click and drag the border of the plot legend to add one item to the legend. When you release the mouse button, the second plot name appears.
| Figure 1.11 Expanding a Plot Legend |
3. Right-click the waveform graph and select Properties from the
shortcut menu to display the Graph Properties dialog box.
4. On the Plots page, select Sawtooth from the top pull-down menu. In the Colors section, click the Line color box to display the color picker.
Select a new line color.
5. Select Sawtooth (Formula Result) from the top pull-down menu.
6. Place a checkmark in the Do not use waveform names for plot names
checkbox. This action lets you edit the labels on the graph.
7. In the Name text box, delete the current label and change the name of this plot to Scaled Sawtooth.
8. Click the OK button to save the current configuration and close the Graph Properties dialog box.
The plot color and plot legend change.
9. Reopen the Graph Properties dialog box and experiment with other
properties of the graph. For example, on the Scales page, try disabling automatic scaling and changing the minimum and maximum value of the y-axis.
10. Click the Cancel button to avoid applying any changes you made
while experimenting. If you want to keep the changes you made, click
the OK button.
11. Save and close the VI.
Comments
Post a Comment