EXERCISE 1
In the following exercises, you will open a blank VI and add Express VIs and structures to the block diagram to build a new VI. When you complete the exercise, the front panel of the VI will appear similar to the Figure 1.
1.A) Opening a Blank VI
If no template is available for the task you want to create, you can start with a blank VI and add Express VIs to accomplish the specific task. Complete the following steps to open a blank VI.
- In the
LabVIEWdialog box, click the arrow on theNewbutton and selectBlank VIfrom the shortcut menu or press theCtrl-Nkeys to open a blank VI. Notice that a blank front panel and block diagram appear. If the
Functionspalette is not visible, right-click any blank space on the block diagram to display theFunctionspalette. Click the thumbtack, shown in Media 2, in the upper left corner of theFunctionspalette to place the palette on the screen.
NOTE:
You can right-click a blank space on the block diagram or the front panel to display theFunctions or Controls palettes.1.B) Adding an Express VI that Simulates a Signal
Complete the following steps to find the Express VI you want to use and then add it to the block diagram.
If the
Context Helpwindow is not visible, press theCtrl-Hkeys to open theContext Helpwindow. You also can press theShow Context Help Windowbutton, shown in Media 3, to open theContext Helpwindow.- Select the
Inputpalette on theFunctionspalette and move the cursor over the Express VIs on theInputpalette. Notice that theContext Helpwindow displays information about the function of each Express VI. - From the information provided in the
Context Helpwindow, find the Express VI that can simulate a sine wave signal. - Select the Express VI and place it on the block diagram. The
Configure Simulate Signaldialog box appears. - Idle the cursor over the various options in the
Configure Simulate Signaldialog box, such asFrequency (Hz),Amplitude, andSamples per second (Hz). Read the information that appears in theContext Helpwindow. - Configure the
Simulate SignalExpress VI to generate a sine wave with a frequency of 10.7 and amplitude of 2. - Notice how the signal displayed in the
Result Previewwindow changes to reflect the configured sine wave. - Close the
Configure Simulate Signaldialog box by clicking theOKbutton. - Move the cursor over the
Simulate SignalExpress VI and read the information that appears in theContext Helpwindow. Notice that theContext Helpwindow now displays the configuration of theSimulate SignalExpress VI. - Save this VI as
Reduce Samples.viin theC:\Exercises\LabVIEW Basics Idirectory.
1.C) Modifying the Signal
Complete the following steps to use the LabVIEW Help to search for the Express VI that reduces the number of samples in a signal.
- Select
Help>>VI, Function, & How-To Helpto open the LabVIEW Help. - Click the
Searchtab and typesample compressionin theType in the word(s) to search fortext box. Notice that this word choice reflects what you want this Express VI to do-compress, or reduce, the number of samples in a signal. - To begin the search, press the
Enterkey or click theList Topicsbutton. - Double-click the
Sample Compressiontopic to display the topic that describes theSample CompressionExpress VI. - After you read the description of the Express VI, click the
Place on the block diagrambutton to select the Express VI. - Move the cursor to the block diagram. Notice how LabVIEW attaches the
Sample CompressionExpress VI to the cursor. - Place the
Sample CompressionExpress VI on the block diagram to the right of theSimulate SignalExpress VI. - Configure the
Sample CompressionExpress VI to reduce the signal by a factor of 25 using the mean of these values. - Close the
Configure Sample Compressiondialog box. - Using the
Wiringtool, wire theSineoutput in theSimulate SignalExpress VI to theSignalsinput in theSample CompressionExpress VI.
1.D) Customizing the Front Panel
In a previous exercise, you added controls and indicators to the front panel using the
Controls palette. You also can add controls and indicators from the block diagram. Complete the following steps to create controls and indicators as shown in Figure 2.- Right-click the
Meanoutput in theSample CompressionExpress VI and selectCreate>>Numeric Indicatorfrom the shortcut menu to create a numeric indicator. - Right-click the
Meanoutput of theSample CompressionExpress VI and selectInsert Input/Outputfrom the shortcut menu to insert theEnableinput. - Right-click the
Enableinput and selectCreate>>Controlfrom the shortcut menu to create theEnableswitch. - Right-click the wire linking the
Sineoutput in theSimulate SignalExpress VI to theSignalsinput in theSignal CompressionExpress VI and selectCreate>>Graph Indicatorfrom the shortcut menu. Notice that you can create controls and indicators from the block diagram. When you create controls and indicators using this method, LabVIEW automatically creates terminals that are labeled and formatted correctly. - Using the
Wiringtool, wire theMeanoutput in theSample CompressionExpress VI to theSinegraph indicator terminal created in the previous step. Notice that theMerge Signalsfunction appears. - Arrange the objects on the block diagram so that they appear similar to Figure 2.
TIP:
You can right-click any wire and selectClean Up Wirefrom the shortcut menu to automatically route an existing wire. - Display the front panel. Notice that the controls and indicators you added automatically appear on the front panel with labels that correspond to their function.
- Save this VI.
1.E) Configuring the VI to Run Continuously Until the User Stops It
In the current state, the VI runs once, generates one signal, then stops executing. To run the VI until a condition is met, you can add a
While Loop to the block diagram. Complete the following steps to add a While Loop.- Display the front panel and run the VI. Notice how the VI runs once and then stops. Also notice how there is no
Stopbutton. - Display the block diagram and select the While Loop on the
Functions>>Execution Controlpalette. - Move the cursor to the upper left corner of the block diagram. Place the top left corner of the
While Loophere. - Click and drag the cursor diagonally to enclose all the Express VIs and wires, as shown in Figure 3.
Figure 3 Notice that the
While Loop, shown in Media 6, appears with aStopbutton wired to the condition terminal. ThisWhile Loopis configured to stop when the user clicks theStopbutton. - Display the front panel and run the VI. Notice that the VI now runs until you click the
Stopbutton. AWhile Loopexecutes the functions inside the loop until the user presses theStopbutton. Refer to Repetition and Loops for more information aboutWhile Loops.
1.F) Controlling the Speed of Execution
To plot the points on the waveform graph more slowly, you can add a time delay to the block diagram. Complete the following steps to control the speed at which the VI executes.
- On the block diagram, select the
Time DelayExpress VI on theFunctions>>Execution Controlpalette and place it inside the loop. - Type .250 in the
Time delay (seconds)text box. This time delay specifies how fast the loop runs. With a .250 second time delay, the loop iterates once every quarter of a second. - Close the
Configure Time Delaydialog box. - Save this VI.
- Display the front panel and run the VI.
- Click the
Enableswitch and notice the change on the graph. Notice how if theEnableswitch is on, the graph displays the reduced signal. If theEnableswitch is off, the graph does not display the reduced signal. - Click the
Stopbutton to stop the VI.
1.G) Using a Table to Display Data
Complete the following steps to display a collection of mean values in a table on the front panel.
- On the front panel, select the Express Table indicator on the
Controls>>Text Indicatorspalette and place it on the front panel to the right of the waveform graph. - Display the block diagram. Notice that the
Tableterminal appears wired to theBuild TableExpress VI automatically. If the
Build TableExpress VI and theTableterminal are not selected already, click an open space on the block diagram to the left of theBuild TableExpress VI and theTableterminal. Drag the cursor diagonally until the selection rectangle encloses theBuild TableExpress VI and theTableterminal, shown in Media 7. A moving dashed outline called a marquee highlights theBuild TableExpress VI, theTableterminal, and the wire joining the two.- Drag the objects into the
While Loopto the right of theMeanterminal. Notice that theWhile Loopautomatically resizes to enclose theBuild TableExpress VI and theTableterminal. - Using the
Wiringtool, wire theMeanterminal of theSample CompressionExpress VI to theSignalsinput of theBuild TableExpress VI. The block diagram should appear similar to Figure 4.
Figure 4 - Display the front panel and run the VI.
- Click the
Enableswitch. The table displays the mean values of every 25 samples of the sine wave. Notice if theEnableswitch is off, the table does not record the mean values. - Stop the VI.
- Experiment with properties of the table by using the
Table Propertiesdialog box. For example, try changing the number of columns to one. - Save and close this VI.
No comments:
Post a Comment