EXERCISE 1
In the following exercise, you will build a VI that generates a signal and displays that signal in a graph. LabVIEW provides templates containing information from which you can build a VI. These templates help you get started with LabVIEW.
Complete the following steps to create a VI that generates a signal and displays it on the front panel.
- Launch LabVIEW.
- In the
LabVIEWdialog box that appears, shown in Figure 1, click theNewbutton to display theNewdialog box.
Figure 1 - Select
VI from Template>>Tutorial (Getting Started)>>Generate and Displayin theCreate newlist. This template VI generates and displays a signal. Notice that previews of the template VI appear in theFront panel previewand theBlock diagram previewsections. The Figure 2 shows theNewdialog box and theGenerate and Display templateVI.
Figure 2 - Click the
OKbutton to open the template. You also can double-click the name of the template VI in theCreate newlist to open the template. - Examine the front panel of the VI. The user interface, or front panel, appears with a gray background and includes controls and indicators. The title bar of the front panel indicates that this window is the front panel for the
Generate and DisplayVI.
NOTE:
If the front panel is not visible, you can display the front panel by selectingWindow>>Show Front Panel. - Examine the block diagram of the VI. The block diagram appears with a white background and includes VIs and structures that control the front panel objects. The title bar of the block diagram indicates that this window is the block diagram for the
Generate and DisplayVI.
NOTE:
If the block diagram is not visible, you can display the block diagram by selectingWindow>>Show Block Diagram. On the front panel toolbar, click the
Runbutton, shown at left. Notice that a sine wave appears on the graph.Stop the VI by clicking the
Stopbutton, shown at left, on the front panel.
1.A) Adding a Control to the Front Panel
Controls on the front panel simulate the input devices on a physical instrument and supply data to the block diagram of the VI. Many physical instruments have knobs you can turn to change an input value. Complete the following steps to add a knob control to the front panel.
TIP:
Throughout these exercises, you can undo recent edits by selectingEdit>>Undo or pressing the Ctrl-Z keys.- If the
Controlspalette is not visible on the front panel, selectWindow>>Show Controls Paletteto display it. - Move the cursor over the icons on the
Controlspalette to locate theNumeric Controlspalette. Notice that when you move the cursor over icons on theControlspalette, the name of that subpalette appears in the gray space above all the icons on the palette. When you idle the cursor over any icon on any palette, the full name of the subpalette, control, or indicator appears. - Click the
Numeric Controlsicon to access theNumeric Controlspalette. - Select the knob control on the
Numeric Controlspalette and place it on the front panel to the left of the waveform graph. You will use this knob in a later exercise to control the amplitude of a signal. - Select
File>>Save Asand save this VI asAcquiring a Signal.viin theC:\Exercises\LabVIEW Basics Idirectory.
NOTE:
Save all the VIs you edit or create in this course in theC:\Exercises\LabVIEW Basics Idirectory.
1.B) Changing the Signal Type
The block diagram has a blue icon labeled
Simulate Signal. This icon represents the Simulate Signal Express VI. The Simulate Signal Express VI simulates a sine wave by default. Complete the following steps to change this signal to a sawtooth wave.- Display the block diagram by selecting
Window>>Show Block Diagramor by clicking the block diagram.Notice the
Simulate SignalExpress VI, shown in Media 5. An Express VI is a component of the block diagram that you can configure to perform common measurement tasks. TheSimulate SignalExpress VI simulates a signal based on the configuration that you specify. - Right-click the
Simulate SignalExpress VI and selectPropertiesfrom the shortcut menu to display theConfigure Simulate Signaldialog box. - Select
Sawtoothfrom theSignal typepull-down menu. Notice that the waveform on the graph in theResult Previewsection changes to a sawtooth wave. TheConfigure Simulate Signaldialog box should appear similar to Figure 3.
Figure 3 - Click the
OKbutton to apply the current configuration and close theConfigure Simulate Signaldialog box. - Move the cursor over the down arrows at the bottom of the
Simulate SignalExpress VI. When a double-headed arrow appears, shown at left, click and drag the border of the Express VI until the
Amplitudeinput appears. Notice how you expanded theSimulate SignalExpress VI to display a new input. Because theAmplitudeinput appears on the block diagram, you can configure the amplitude of the sawtooth wave on the block diagram. In Figure 3, notice howAmplitudeis an option in theConfigure Simulate Signaldialog box. When inputs, such asAmplitude, appear on the block diagram and in the configuration dialog box, you can configure the inputs in either location.
1.C) Wiring Objects on the Block Diagram
To use the knob control to change the amplitude of the signal, you must connect the two objects on the block diagram. Complete the following steps to wire the knob to the
Amplitude input on the Simulate Signal Express VI.Move the cursor over the
Knobterminal, shown at left, until thePositioningtool appears.Notice how the cursor becomes an arrow, or the
Positioningtool, shown in Media 9. Use thePositioningtool to select, position, and resize objects.Click the
Knobterminal to select it, then drag the terminal to the left of theSimulate SignalExpress VI. Make sure theKnobterminal is inside the loop, shown in Media 10. The terminals are representations of front panel controls and indicators. Terminals are entry and exit ports that exchange information between the front panel and block diagram.- Deselect the
Knobterminal by clicking a blank space on the block diagram. Move the cursor over the arrow of the
Knobterminal, shown in Media 11.Notice how the cursor becomes a wire spool, or the
Wiringtool, shown at left. Use theWiringtool to wire objects together on the block diagram.
NOTE:
The cursor does not switch to another tool while an object is selected.When the
Wiringtool appears, click the arrow and then click theAmplitudeinput of theSimulate SignalExpress VI, shown in Media 13, to wire the two objects together. Notice that a wire appears and connects the two objects. Data flows along this wire from the terminal to the Express VI.- Select
File>>Saveto save this VI.
1.D) Running the VI
Running a VI executes your solution. Complete the following steps to run the
Acquiring a Signal VI.- Display the front panel by selecting
Window>>Show Front Panelor by clicking the front panel.
TIP:
Press theCtrl-Ekeys to switch from the front panel to the block diagram or from the block diagram to the front panel. - Click the
Runbutton. - Move the cursor over the knob control.
Notice how the cursor becomes a hand, or the
Operatingtool, shown at left. Use theOperatingtool to change the value of a control or select the text within a control. - Using the
Operatingtool, turn the knob to adjust the amplitude of the sawtooth wave. Notice how the amplitude of the sawtooth wave changes as you turn the knob. Also notice that the y-axis on the graph autoscales to account for the change in amplitude.To indicate that the VI is running, the
Runbutton changes to a darkened arrow, shown at left. You cannot edit the front panel or block diagram while the VI runs. Click the
Stopbutton, shown at left, to stop the VI.
NOTE:
AlthoughAbort Execution button looks like a stop button, the Abort Execution button does not always properly close the VI. National Instruments recommends stopping your VIs using the Stop button on the front panel. Use the Abort Execution button only when errors prevent you from terminating the application using the Stop button.1.E) Modifying the Signal
Complete the following steps to add scaling to the signal and display the results in the graph on the front panel.
On the block diagram, use the
Positioningtool to double-click the wire that connects theSimulate SignalExpress VI to theWaveform Graphterminal shown in Media 17.- Press the
Deletekey to delete this wire. - If the
Functionspalette is not visible on the block diagram, selectWindow>>Show Functions Paletteto display it. Select the
Scaling and MappingExpress VI, shown at left, on theArithmetic & Comparisonpalette and place it on the block diagram inside the loop between theSimulate SignalExpress VI and theWaveform Graphterminal. If there is no room between the Express VI and the terminal, move theWaveform Graphterminal to the right. Notice that theConfigure Scaling and Mappingdialog box automatically opens when you place the Express VI on the block diagram.- Define the value of the scaling factor by entering 10 in the
Slope (m)text box. TheConfigure Scaling and Mappingdialog box should appear similar to Figure 4.
Figure 4 - Click the
OKbutton to apply the current configuration and close theConfigure Scaling and Mappingdialog box. - Move the cursor over the arrow on the
Sawtoothoutput of theSimulate SignalExpress VI. When the Wiring tool appears, click the arrow and then click the arrow on the
Signalsinput of theScaling and MappingExpress VI, shown in Media 20, to wire the two objects together.- Using the
Wiringtool, wire theScaled Signalsoutput of theScaling and MappingExpress VI to theWaveform Graphterminal. Notice 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 toFigure 5.
Figure 5 NOTE:
The terminals in the block diagram are set to display as icons. To display a terminal as a data type on the block diagram, right-click the terminal and selectView As Iconfrom the shortcut menu to remove the checkmark. - Select
File>>Saveto save this VI.
1.F) Displaying Two Signals on the Graph
To compare the signal generated by the
Simulate Signal Express VI and the signal modified by the Scaling and Mapping Express VI on the same graph, use the Merge Signals function. Complete the following steps to display two signals on the same graph.- Move the cursor over the arrow on the
Sawtoothoutput of theSimulate SignalExpress VI. - Using the
Wiringtool, wire theSawtoothoutput to theWaveform Graphterminal.The
Merge Signalsfunction, shown in Media 22, appears where the two wires connect. This function takes the two separate signals and combines them so that both can be displayed on the same graph. The block diagram should appear similar toFigure 6.
Figure 6 - Select
File>>Saveto save this VI. You also can press theCtrl-Skeys to save a VI. - Return to the front panel, run the VI, and turn the knob control. Notice that the graph plots the sawtooth wave and the scaled signal. Also notice that the maximum value on the y-axis automatically changes to be 10 times the knob value. This scaling occurs because you set the slope to 10 in the Scaling and Mapping Express VI.
- Click the
Stopbutton.
1.G) Customizing the Knob
The knob control changes the amplitude of the sawtooth wave so labeling it
Amplitude accurately describes the function of the knob. Complete the following steps to customize the appearance of a control on the front panel.- Right-click the knob and select
Propertiesfrom the shortcut menu to display theKnob Propertiesdialog box. - In the
Labelsection on theAppearancetab, delete the label Knob, and typeAmplitudein the text box. TheKnob Propertiesdialog box should appear similar toFigure 7.
Figure 7 - Click the
Scaletab and, in theScale Rangesection, change the maximum value to 5.0. Notice how the knob on the front panel instantly updates to reflect these changes. - Click the
OKbutton to apply the current configuration and close theKnob Propertiesdialog box. - Save this VI.
TIP:
As you build VIs, you can experiment with different properties and configurations. You also can add and delete objects. Remember, you can undo recent edits by selectingEdit>>Undoor pressing theCtrl-Zkeys. - Experiment with other properties of the knob by using the
Knob Propertiesdialog box. For example, try changing the colors for theMarker Text Colorby clicking the color box located on theScaletab. - Click the
Cancelbutton to avoid applying the changes you made while experimenting. If you want to keep the changes you made, click theOKbutton.
1.H) 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 customize the plots. Complete the following steps to customize the appearance of an indicator on the front panel.- Move the cursor over the top of the
plot legendon thewaveform graph. Notice that while there are two plots on the graph, theplot legenddisplays only one plot. - When a double-headed arrow appears, shown in Figure 8, click and drag the border of the
plot legenduntil the second plot name appears.
Figure 8 - Right-click the
waveform graphand selectPropertiesfrom the shortcut menu to display theGraph Propertiesdialog box. - On the
Plotstab, selectSawtoothfrom the pull-down menu. Click theLine Colorcolor box to display thecolor picker. Select a new line color. - Select
Sawtooth (Scaled)from the pull-down menu. - Place a checkmark in the
Don't use waveform names for plot namescheckbox. - In the
Nametext box, delete the current label and change the name of this plot toScaled Sawtooth. - Click the
OKbutton to apply the current configuration and close theGraph Propertiesdialog box. Notice how the plot color on the front panel changes. - Experiment with other properties of the graph by using the
Graph Propertiesdialog box. For example, try disabling the autoscale feature located on theScalestab. - Click the
Cancelbutton to avoid applying the changes you made while experimenting. If you want to keep the changes you made, click theOKbutton. - Save and close this VI.
No comments:
Post a Comment