Lab 5
Lab 5
Ref. [1-3]
5. Use the Operating tool, shown at left, to change the Input Signal and the Signal Processing, use the increment or decrement arrows on the control, and drag the pointer to the desired Frequency. 6. Press the More Info button or [F5] to read more about the analysis functions. 7. Press the Stop button or [F4] to stop the VI. Block Diagram 8. Select WindowShow Diagram or press the <Ctrl-E> keys to display the block diagram for the Signal Generation and Processing VI.
(MacOS) Press the <Command-E> keys. (Sun) Press the <Meta-E> keys. (Linux ) Press the <Alt-E> keys.
This block diagram contains several of the basic block diagram elements, including subVIs, functions, and structures, which you will learn about later in this course. 9. Select WindowShow Panel or press the <Ctrl-E> keys to return to the Front Panel. 10. Close the VI and do not save changes.
End of Exercise
Front Panel
2. (Optional) Select WindowTile Left and Right to display the front panel and block diagram side by side. 3. Create a numeric digital control. You will use this control to enter the value for degrees Centigrade. a. Select the digital control on the ControlsNumeric Controls palette. If the Controls palette is not visible, right-click an open area on the front panel to display it. b. Move the control to the front panel and click to place the control. c. Type deg C inside the label and click outside the label or click the Enter button on the toolbar. If you do not type the name immediately, LabVIEW uses a default label. You can edit a label at any time by using the Labeling tool. 4. Create a numeric digital indicator. You will use this indicator to display the value for degrees Fahrenheit. a. Select the digital indicator on the ControlsNumeric Indicators palette. b. Move the indicator to the front panel and click to place the indicator. c. Type deg F inside the label and click outside the label or click the Enter button. LabVIEW creates corresponding control and indicator terminals on the block diagram. The terminals represent the data type of the control or indicator. For example, a DBL terminal represents a double-precision, floating-point numeric control or indicator. Note Control terminals have a thicker border than indicator terminals.
Block Diagram
5. Display the block diagram by clicking it or by selecting WindowShow Diagram.
Note: Block Diagram terminals can be viewed as icons or as terminals. To change the way LabVIEW displays these objects right click on a terminal and select View As Icon.
6. Select the Multiply and Add functions on the FunctionsNumeric palette and place them on the block diagram. If the Functions palette is not visible, right-click an open area on the block diagram to display it. 7. Select the numeric constant on the FunctionsNumeric palette and place two of them on the block diagram. When you first place the numeric constant, it is highlighted so you can type a value. 8. Type 1.8 in one constant and 32.0 in the other. If you moved the constants before you typed a value, use the Labeling tool to enter the values. 9. Use the Wiring tool to wire the icons as shown in the previous block diagram. To wire from one terminal to another, use the Wiring tool to click the first terminal, move the tool to the second terminal, and click the second terminal, as shown in the following illustration. You can start wiring at either terminal.
You can bend a wire by clicking to tack the wire down and moving the cursor in a perpendicular direction. Press the spacebar to toggle the wire direction. To identify terminals on the nodes, right-click the Multiply and Add functions and select Visible ItemsTerminals from the shortcut menu to display the connector pane. Return to the icons after wiring by right-clicking the functions and selecting Visible Items Terminals from the shortcut menu to remove the checkmark. When you move the Wiring tool over a terminal, the terminal area blinks, indicating that clicking will connect the wire to that terminal and a tip strip appears, listing the name of the terminal. To cancel a wire you started, press the <Esc> key, right-click, or click the source terminal. 10. Display the front panel by clicking it or by selecting WindowShow Panel. 11. Save the VI because you will use this VI later in the course. a. Select FileSave. b. Navigate to c:\exercises\LV Intro. Note Save all the VIs you edit in this course in c:\exercises\LV Intro. c. Type Convert C to F.vi in the dialog box. d. Click the Save button. 4
12. Enter a number in the digital control and run the VI. a. Use the Operating tool or the Labeling tool to double-click the digital control and type a new number. b. Click the Run button to run the VI. c. Try several different numbers and run the VI again. 13. Select FileClose to close the Convert C to F VI.
End of Exercise
2. Right-click the icon in the upper right corner of the front panel and select Edit Icon from the shortcut menu. The Icon Editor dialog box appears. 3. Double-click the Select tool on the left side of the Icon Editor dialog box to select the default icon. 4. Press the <Delete> key to remove the default icon. 5. Double-click the Rectangle tool to redraw the border. 6. Create the following icon.
a. Use the Text tool to click the editing area. b. Type C and F. c. Double-click the Text tool and change the font to Small Fonts. d. Use the Pencil tool to create the arrow. Note To draw horizontal or vertical straight lines, press the <Shift> key while you use the Pencil tool to drag the cursor. e. Use the Select tool and the arrow keys to move the text and arrow you created. f. Select the B&W icon and select 256 Colors in the Copy from field to create a black and white icon, which LabVIEW uses for printing unless you have a color printer. g. When the icon is complete, click the OK button to close the Icon Editor dialog box. The icon appears in the upper right corner of the front panel and block diagram. 7. Right-click the icon on the front panel and select Show Connector from the shortcut menu to define the connector pane terminal pattern. LabVIEW selects a connector pane pattern based on the number of controls and indicators on the front panel. For example, this front panel has two terminals, deg C and deg F, so LabVIEW selects a connector pane pattern with two terminals. 6
8. Assign the terminals to the digital control and digital indicator. a. Select HelpShow Context Help to display the Context Help window. View each connection in the Context Help window as you make it. b. Click the left terminal in the connector pane. The tool automatically changes to the Wiring tool, and the terminal turns black. c. Click the deg C control. The left terminal turns orange, and a marquee highlights the control. d. Click an open area of the front panel. The marquee disappears, and the terminal changes to the data type color of the control to indicate that you connected the terminal. e. Click the right terminal in the connector pane and click the deg F indicator. The right terminal turns orange. f. Click an open area on the front panel. Both terminals are orange. g. Move the cursor over the connector pane. The Context Help window shows that both terminals are connected to floating-point values. 9. Select FileSave to save the VI because you will use this VI later in the course. 10. Select FileClose to close the Convert C to F VI.
End of Exercise
Front Panel
1. Open a new VI. 2. Build the following front panel.
a. Select the horizontal pointer slide on the ControlsNumeric Controls palette and place it on the front panel. You will use the slide to change the software timing. b. Type millisecond delay inside the label and click outside the label or click the Enter button on the toolbar, shown at left. c. Place a Stop Button from the ControlsButtons palette. d. Select a waveform chart on the ControlsGraph Indicators palette and place it on the front panel. The waveform chart will display the data in real time. e. Type Value History inside the label and click outside the label or click the Enter button. f. The waveform chart legend labels the plot Plot 0. Use the Labeling tool to tripleclick Plot 0 in the chart legend, type Value, and click outside the label or click the Enter button to relabel the legend. g. The random number generator generates numbers between 0 and 1, in a classroom setting you could replace this with a data acquisition VI. Use the Labeling tool to double-click 10.0 in the y-axis, type 1, and click outside the label or click the Enter button to rescale the chart. h. Change 10.0 in the y-axis to 0. i. Label the y-axis Value and the x-axis Time (sec).
Block Diagram
3. Select WindowShow Diagram to display the block diagram. 4. Enclose the two terminals in a While Loop, as shown in the following block diagram.
a. Select the While Loop on the FunctionsExecution Control palette. b. Click and drag a selection rectangle around the two terminals. c. Use the Positioning tool to resize the loop, if necessary. 5. Select the Random Number (0-1) on the FunctionsArithmetic and ComparisonNumeric palette. Alternatively you could use a VI that is gathering data from an external sensor. 6. Wire the block diagram objects as shown in the previous block diagram. 7. Save the VI as Use a Loop.vi because you will use this VI later in the course. 8. Display the front panel by clicking it or by selecting WindowShow Panel. 9. Run the VI. The section of the block diagram within the While Loop border executes until the specified condition is TRUE. For example, while the STOP button is not pressed, the VI returns a new number and displays it on the waveform chart. 10. Click the STOP button to stop the acquisition. The condition is FALSE, and the loop stops executing. 11. Format and customize the X and Y scales of the waveform chart. a. Right-click the chart and select Properties from the shortcut menu. The following dialog box appears. b. Click the Scale tab and select different styles for the y-axis. You also can select different mapping modes, grid options, scaling factors, and formats and precisions. Notice that these will update interactively on the waveform chart c. Select the options you desire and click the OK button.
12. Right-click the waveform chart and select Data OperationsClear Chart from the shortcut menu to clear the display buffer and reset the waveform chart. If the VI is running, you can select Clear Chart from the shortcut menu.
Adding Timing
When this VI runs, the While Loop executes as quickly as possible. Complete the following steps to take data at certain intervals, such as once every half-second, as shown in the following block diagram.
a. Place the Time Delay Express VI located on the FunctionsExecution Control palette. In the dialog box that appears, insert 0.5. This function would make sure that each iteration occurs every half-second (500 ms). b. Divide the millisecond delay by 1000 to get time in seconds. Connect the output of the divide function to the Delay Time (s) input of the Time Delay Express VI. This will allow you to adjust the speed of the execution from the pointer slide on the front panel. 13. Save the VI, because you will use this VI later in the course. 14. Run the VI. 15. Try different values for the millisecond delay and run the VI again. Notice how this effects the speed of the number generation and display. 16. Close the VI.
End of Exercise
10
Figure 1 1. Place an array, located on the Controls>>All Controls>>Array & Cluster palette, on the front panel. 2. Label the array Random Array. 3. Place a numeric indicator, located on the Controls>>Numeric Indicators palette, in the array shell. 4. Use the Positioning tool to resize the array control to contain 10 numeric indicators. 5. Press the <Ctrl> key while you click and drag the Random Array control to create two copies of the control. 6. Label the copies Final Array and Subset Array. 7. Place three numeric controls, located on the Controls>>Numeric Controls palette, and label them Scaling Factor, Start Subset, and # of Elements. 8. Right-click the Start Subset and # of Elements controls and select Representation>>I32 from the shortcut menu. 9. Do not change the values of the front panel controls. 1.b) Block Diagram
11
Figure 2 a. Place the Random Number (0-1) function, located on the Functions>>Arithmetic & Comparison>>Express Numeric palette, on the block diagram. This function generates a random number between 0 and 1. Place the For Loop, located on the Functions>>All Functions>>Structures palette, on the block diagram. The loop accumulates an array of 1010 random numbers at the output tunnel. Create a constant of 1010 for the count terminal. Place the Multiply function, located on the Functions>>Arithmetic & Comparison>>Express Numeric palette, on the block diagram. In this exercise this function multiplies Random Array by Scaling Factor and returns Final Array. Place the Array Subset function, located on the Functions>>All Functions>>Array palette, on the block diagram. This function returns a portion of an array starting at Start Subset and containing # of Elements elements.
b.
c.
d.
3. Save the VI as Array Exercise.vi in the C:\Exercises\ LabVIEW Basics I directory. Run the VI 4. Display the front panel, change the values of the controls, and run the VI a few times. 5. Close the VI.
End of Exercise
12
Front Panel
1. Open a new VI and build the following front panel using the following tips.
Do not create the Mean, Max, and Min indicators yet. Create them on the Block Diagram by right clicking on the functions and choosing Create Indicator. Then position them on the Front Panel.
Block Diagram
2. Build the following block diagram. a. Select the FunctionsInputSimulate Signal. b. Choose a frequency, Amplitude, and an offset c. Place the Wait Until Next ms Multiple function located on the FunctionsAll Functions Time & Dialog palette and create a constant of 250. Much like the Time Delay Express VI, this function causes the For Loop to execute every 0.25 s (250 ms). d. Place the Array Max & Min function located on the FunctionsAll Functions Array palette. This function returns the maximum and minimum amplitude of the wave.
13
e. Place the Mean VI located on the FunctionsAll Functions AnalyzeMathematicsProbability and Statistics palette. This VI returns the average of the amplitude of the wave. f. Right-click the output terminals of the Array Max & Min function and Mean VI and select CreateIndicator from the shortcut menu to create the Max, Min, and Mean indicators. g. Place the Write LabVIEW Measurements File Express VI located on the FunctionsOutput palette. Configure the VI to ask the user to choose the file to write and change the delimiter to Tab
3. Save the VI as Temperature Logger.vi. 4. Display the front panel and run the VI. 5. After pressing STOP a dialog box will appear. Enter the name of the file to save the spreadsheet. 6. Open the spreadsheet file to make sure the file was properly created by using Notepad or Excel, or by creating a VI to read the file as follows. Create the following block diagram
Place the Read LabVIEW Measurement File Express VI located on the FunctionsInput palette. Configure the VI to ask the user to choose the file to read and change the delimiter to Tab Right click on the Signals Output and choose create graph indicator 14
End of Exercise
15
1. Open a new VI and build the following front panel using the following tips.
a. Create a waveform graph indicator from the ControlsGraph Indicators palette. Use the position/size/select tool to move the plot legend to the side, and expand it to display two plots. Use the labeling tool to change the plot names and the properties page to choose different colors for your plots. b. Place a Stop button on the front panel. c. Place two vertical pointer slides from the ControlsNumeric Controls palette. Use the properties page again to change the slide fill color.
Block Diagram
2. Build the following block diagram.
16
a. Place a While Loop from FunctionsExecution Control palette. b. Place a Wait Until Next ms Multiple from FunctionsAll Functions Time & Dialog and create a constant with a value of 100. c. Place two Simulate Signal Express VIs from the FunctionsInput and leave the Signal type as Sine for the first Simulate Signal VI and change the Signal Type to Square for the second VI. Wire both of the outputs into the waveform graph. A Merge Signals function will automatically be inserted. d. Expand the Simulate Signal Express VIs to show another Input/Output. By default, error out should appear. Change this to Frequency by clicking on error out and choosing Frequency. 3. Save the VI as Multiplot Graph.vi. 4. Display the front panel and run the VI. 5. Save and close the VI.
End of Exercise
17
1. Open a new VI and build the following front panel using the following tips.
a. Create a numeric control and change the Label to Square Root Input. Create a numeric indicator for Square Root. b. Place Error In 3D.ctl from ControlsAll ControlsArrays & Clusters. c. Place Error Out 3D.ctl from Controls All ControlsArrays & Clusters.
Block Diagram
2. Build the following block diagram.
a. Place a Case Structure from FunctionsExecution Control palette. b. Place a Greater or Equal to 0? from the FunctionsArithmetic and ComparisonComparison palette and wire it to the condition terminal of the case structure. In the True Case: c. Place the Square Root function from FunctionsArithmetic and ComparisonNumeric palette.
18
d. Create a numeric constant from FunctionsArithmetic and ComparisonNumeric palette and type -9999.90. e. Place the Bundle By Name from FunctionsAll FunctionsArrays & Clusters palette. Wire from Error in to the center terminal of Bundle by Name to make status show up. Create constants. Wire from the Error Out indicator to the output of Bundle By name. 3. Save the VI as Square Root.vi. 4. Display the front panel and run the VI. 5. Save and close the VI.
End of Exercise
19
Figure 2-1 Front panel for the Warning Light VI Opening a New VI from a Template To build this VI, you can start from the New dialog box. Complete the following steps to select a new template VI that generates, analyzes, and displays a signal. 1. In the LabVIEW dialog box, click the New button to display the New dialog box. Note You also can access the New dialog box by clicking the arrow on the New button and selecting New from the New pull-down menu or by selecting File>>New from the front panel or block diagram menu bar. 2. Select the VI from Template>>Tutorial (Getting Started)>>Generate, Analyze, and Display template in the Create new list The template VI simulates a signal and analyzes it for its root mean square (RMS) value. 3. Click the OK button to open the template. You also can double-click the name of the template VI in the Create new list to open the template. 4. Display the block diagram by pressing the <Ctrl-E> keys. 5. If the Context Help window, shown in Figure 2-2, is not visible, select Help>>Show Context Help from the block diagram menu bar to display the Context Help window. Note You also can press the <Ctrl-H> keys to display the Context Help window.
20
6. Move the cursor over the Amplitude and Level Measurements Express VI, shown at left. Notice when you move the cursor over the Express VI, the Context Help window displays information about the Express VI, including information about how it is configured. Keep the Context Help window open and notice how it provides useful information as you complete the rest of this exercise. Modifying the Block Diagram The Simulate Signal Express VI simulates a sine wave by default. You can customize the simulated signal by changing the options in the Configure Simulate Signal dialog box. Complete the following steps to change the simulated signal from a sine wave to a DC signal with uniform white noise. 1 Right-click the Simulate Signal Express VI and select Properties from the shortcut menu to display the Configure Simulate Signal dialog box. 2 Select DC from the Signal type pull-down menu. 3 Place a checkmark in the Add noise checkbox to add noise to the DC signal. 4 Type 0.1 in the Noise amplitude text box. Notice that the Result Preview section displays a random signal. The Configure Simulate Signal dialog box should appear similar to Figure 2-3.
21
5 Click the OK button to save the current configuration and close the Configure Simulate Signal dialog box. 6 Display the front panel by pressing the <Ctrl-E> keys. 7. Run the VI. Notice that the signal appears in the graph and the RMS value for the signal appears in the digital indicator. 8. Click the STOP button. 9. Select File>>Save As and save this VI as Analysis.vi to an easily accessible location. Modifying the Front Panel If you decide that you do not want to use an indicator that comes with the template, you can delete it. Complete the following steps to remove the RMS indicator from the front panel. 1 Move the cursor over the RMS indicator until the Positioning tool appears. 2 Click the RMS indicator, shown at left, to select it and press the <Delete> key. 3. Display the block diagram. The block diagram now has a dashed wire with a red X, shown at left. This is a broken wire. Also notice the Run button, shown at left, appears broken to indicate the VI cannot run. 4. Click the broken Run button to display the Error list window. The Error list window lists all errors in the VI and provides details about each error. 5. In the Errors and Warnings listbox, double-click the Wire: has loose ends error to highlight the broken wire. Notice how LabVIEW automatically displays the problem causing the error. Press the <Delete> key to delete the broken wire Tip Press the <Ctrl-B> keys to delete all broken wires on the block diagram. 7. Select Windows>>Show Error List to display the Error list window. Now there are no errors listed in the Errors and Warnings listbox.
6.
Note You also can press the <Ctrl-L> keys to display the Error list window. 8. Click the Close button to close this window. Notice that the Run button is no longer broken. Analyzing the Amplitude of a Signal The Amplitude and Level Measurements Express VI includes options that you can use to analyze the voltage characteristics of a signal. Complete the following steps to reconfigure the Express VI to measure the peak to peak amplitude values of the signal. 1. Right-click the Amplitude and Level Measurements Express VI
22
and select Properties from the shortcut menu to display the Configure Amplitude and Level Measurements dialog box. Tip You also can double-click the Express VI to open the Configure Amplitude and Level Measurements dialog box. 2. Remove the checkmark in the RMS checkbox in the Amplitude Measurements section. 3. Click the Help button, shown at left, in the bottom right corner of the Configure Amplitude and Level Measurements dialog box to display the LabVIEW Help topic for this Express VI. The help topic describes the Express VI, the inputs and outputs for the Express VI, and the configuration options. Each Express VI has a corresponding help topic accessible by pressing the Help button. 4. 5. 6. In the Amplitude and Level Measurements topic, find the output parameter whose description indicates that it takes a measurement from the maximum peak to the minimum peak of the signal. Minimize LabVIEW Help to return to the Configure Amplitude and Level Measurements dialog box. Select the input or output you decided to use.
Notice how the option you selected, Peak to Peak, appears in the Results section with the corresponding value of the measurement. 7. Click the OK button to close the Configure Amplitude and Level Measurements dialog box and return to the block diagram.Notice that the RMS output in the Amplitude and Level Measurements Express VI changed to reflect the new Peak to Peak parameter, shown at left.
Adding a Warning Light If you want a visual cue indicating when a value exceeds a specified limit, use a warning light. Complete the following steps to add a warning light to the VI. 1 From the Controls palette, select the round LED indicator on the LEDs palette, shown in Figure 2-4, and place it on the front panel to the left of the waveform graph.
Figure 2-4 LEDs Palette 2 Right-click the LED and select Properties from the shortcut menu to display the 23
Button Properties dialog box. 3 Change the label of the LED to Warning. 4. Click the OK button to save the current configuration and close the Button Properties dialog box. You will use this LED in a later exercise to signal when a value has exceeded its limit 5. Select File>>Save As and save this VI as Warning Light.vi to an easily accessible location Setting the Warning Level Limit To specify the value at which you want the warning light to turn on, use the Comparison Express VI. Complete the following steps to compare the peak to peak value to a limit you set. 1 On the block diagram, select the Comparison Express VI on the Arithmetic & Comparison>>Express Comparison palette and place it to the right of the Amplitude and Level Measurements Express VI. 2 In the Configure Comparison dialog box, select the > Greater than option from the Compare Condition section. 3 In the Comparison Inputs section, select Use constant value and type 0.195 in the Constant value text box.
4 Close the configuration page and return to the block diagram. Notice how the name of the Comparison Express VI reflects the operation of the Express VI, shown at left. Greater Than indicates that the Express VI does a greater than comparison. 5 Wire the Peak to Peak output of the Amplitude and Level Measurements Express VI to the Operand 1 input of the Comparison Express VI. 6 Move the cursor over the wire connecting the Peak to Peak output to the Operand 1 input. 7 When the Positioning tool appears, right-click the wire connecting the Peak to Peak output to the Operand 1 input and select Create>> Numeric Indicator from the shortcut menu. Notice how a Peak to Peak terminal, shown at left, appears on the block diagram. If the Peak to Peak terminal appears to be on top of the wires of the Express VIs, move the Express VIs and Peak to Peak terminal around to create more space. For example, move the Peak to Peak terminal into the blank space above the Express VIs. Warning the User After specifying the values at which you want the warning light to turn on, you must wire the warning light to the Comparison Express VI. Complete the following steps to provide a visual cue to the user when the peak to peak value of the signal exceeds a specified limit. 1. On the block diagram, move the Warning terminal to the right of the Comparison Express VI. Makesure the Warning terminal is inside the loop, as shown in Figure 25. 2. Wire the Result output of the Comparison Express VI to the Warning terminal.
24
3. Display the front panel. Notice how a numeric indicator also appears on the front panel labeled Peak to Peak. This indicator displays the peak to peak value of the signal. 4. Run the VI. 5. Click the STOP button to stop the VI. 6. Select File>>Save to save this VI. Configuring the VI to Save Data to a File To store information about the data your VI generates, use the Write LabVIEW Measurement File Express VI. Complete the following steps to build a VI that saves peak to peak values and other information to a LabVIEW data file. 1. Select the Write LabVIEW Measurement File Express VI on the Output palette and place it on the block diagram below and to the right of the Amplitude and Level Measurements Express VI. Notice that the File name text box indicates that the output file is test.lvm and displays the full path to the test.lvm file. A .lvm file is a LabVIEW measurement data file, which LabVIEW places in the default LabVIEW Data directory. LabVIEW installs the LabVIEW Data directory in the default file directory of the operating system. When you want to view the data, use the file path displayed in the File name text box to access the test.lvm file. 2. In the Configure Write LabVIEW Measurement File dialog box, select the Append to file option in the If a file already exists section. By selecting Append to file, LabVIEW writes all the data to the test.lvm file without erasing the existing data in the file if a file by that name exists already. 3. Select the One header only option in the Segment Headers section. 4. Enter the following text in the File Description text box: Sample of peak to peak values.
25
5. Close the Configure Write LabVIEW Measurement File dialogbox and return to the block diagram. Saving Data to a File When you run this VI, LabVIEW saves the data to the test.lvm file. Complete the following steps to generate the test.lvm file. 1. Wire the Peak to Peak output of the Amplitude and Level Measurements Express VI to the Signals input of the Write LabVIEW Measurement File Express VI. 2. Select File>>Save As and save this VI as Save Data.vi to an easily accessible location. 3. Display the front panel and run the VI. 4. Click the STOP button on the front panel. 5. To view the data you saved, open the LabVIEW Data\test.lvm file with a spreadsheet or word processing application. 6. Close the file when you finish looking at it and return to the Save Data VI. Adding a Button that Stores Data when Pressed If you want to store only certain data, you can configure the Write LabVIEW Measurement File Express VI to save peak to peak values only when a user presses a button. Complete the following steps to add a button to the VI and configure how the button responds when a user clicks it. 1. On the front panel, select the rocker button on the Buttons & Switches palette and place it to the right of the waveform graph. 2. Using the Button Properties dialog box, change the label of the button to Write to File. 3. On the Operation tab, select Latched When Pressed from the Button Behavior list.Use the Operation tab to specify how a button behaves when a user clicks it. To see how the button reacts to a click, click the button in the Preview Selected Behavior section. 4. Close the Button Properties dialog box. 5. Save this VI. Saving Data when Prompted by a User Complete the following steps to build a VI that logs data to a file when the user clicks a button on the front panel. 1. On the block diagram, double-click the Write LabVIEW Measurement File Express VI to access the Configure Write LabVIEW Measurement File dialog box. 2. Change the file name test.lvm to Selected Samples.lvm in the File name text box to save the data to a different file. 3. Close the Configure Write LabVIEW Measurement File dialog box. 4. Right-click the Signal input of the Write LabVIEW Measurement File Express VI. Select Insert Input/Output from the shortcut menu to insert the Comment input. 5. Right-click the Comment input of the Write LabVIEW Measurement File Express VI. Select Select Input/Output>>Enable from the shortcut menu to insert the Enable input.
26
In the previous exercise you learned to add inputs and outputs by expanding the Express VI using the down arrows. Notice that this method is a different way of displaying and selecting the inputs and outputs of an Express VI. The inputs and outputs of an Express VI appear in a predetermined order when you add new inputs and outputs. To select a specific input, you may need to add an input first, then change the input to the specific one you want to use. 6. Move the Write to File terminal to the left of the Write LabVIEW Measurement File Express VI. 7. Wire the Write to File terminal to the Enable input of the Write LabVIEW Measurement File Express VI. The block diagram should appear similar to Figure 2-6.
8. Display the front panel and run the VI. Click the Write to File button several times. 9. Click the STOP button on the front panel. 10. To view the data you saved, open the Selected Samples.lvm file with a spreadsheet or word processing application. Notice how the Selected Samples.lvm file differs from the test.lvm file. test.lvm recorded all the data generated by the Save Data VI, whereas Selected Samples.lvm only recorded the data when you pressed the Write to File button. 11. Save and close this VI.
27
Exercise 9: [2] Summary: In this exercise, the objective is to use the Formula Node in a VI. Complete the following steps to build a VI that uses the Formula Node to perform a complex mathematical operation and graphs the results. Problem 1 1.a) Front Panel 1. Open a blank VI and build the front panel shown in figure 1. Figure 1
Figure 2 1. Place the Formula Node, located on the Functions>>All Functions>>Structures palette, on the block diagram.
28
2. Create the x input terminal by right-clicking the left border and selecting Add Input from the shortcut menu. Type x in the box that appears. 3. Create the y and a output terminals by right-clicking the right border and selecting Add Output from the shortcut menu. Enter y and a, respectively, in the boxes that appear. You must create output terminals for temporary variables like a. Note: When you create an input or output terminal, you must use a variable name that exactly matches the one in the equation. Variable names are case sensitive. 4. Type the following equations in the Formula Node, where ** is the exponentiation operator. Refer to the LabVIEW Help for more information about syntax for the Formula Node.
a = Tanh( x ) + Cos( x ) y = a3 + a ! 5. Complete the block diagram as shown in figure 2. ! the VI as Formula Node Exercise.vi. 2. Save
1.c) Run the VI 1. Display the front panel and run the VI. The graph displays the plot of the equation y = f ( x ) 3 + f ( x ) where f ( x ) = Tanh ( x ) + Cos( x ) . During each iteration, the VI divides the iteration terminal value by 15.0. The quotient is wired to the Formula Node, which calculates the function value. The VI plots the array as a graph. 2. Close the VI. ! !
29
Exercise 10: Stop Watch * Make a program that starts counting time when you click on run. It should have a switch that you can click on to stop the program, at which time the total elapsed time in displayed in seconds. You will need while loops and sequence structure with sequence locals for this program. Exercise 11: Arrays Build a VI that generates a 2D array of three rows by 10 columns that contains random numbers. After generating the array, index each row, and plot ezaach row on its own graph. The front panel should contain three graphs. REFERENCES 1. http://zone.ni.com/devzone/learningcenter.nsf/webmain/60c2782788a811c986256cd50001a0a6 2. http://cnx.org/content/m12224/latest/ 3. LabView Basics I: Introduction Course manual, National Instruments
30