Use a while loop and a waveform chart to build a VI that demonstrates software timing.
Front Panel
1. Open a new VI.
2. Build the following front panel.
- Select the horizontal pointer slide on the Controls»Numeric Controls palette and place it on the front panel. You will use the slide to change the software timing.
- Type millisecond delay inside the label and click outside the label or click the Enter button on the toolbar, shown at left.
- Place a Stop Button from the Controls»Buttons palette.
- Select a waveform chart on the Controls»Graph Indicators palette and place it on the front panel. The waveform chart will display the data in real time.
- Type Value History inside the label and click outside the label or click the Enter button.
- The waveform chart legend labels the plot Plot 0. Use the Labeling tool to triple-click Plot 0 in the chart legend, type Value, and click outside the label or click the Enter button to relabel the legend.
- 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.
- Change –10.0 in the y-axis to 0.
- Label the y-axis Value and the x-axis Time (sec).
Block Diagram
1. Select Window»Show Diagram to display the block diagram.
2. Enclose the two terminals in a While Loop, as shown in the following block diagram.
a. Select the While Loop on the Functions»Execution Control palette.
b. Click and drag a selection rectangle around the two terminals.
c. Use the Positioning tool to resize the loop, if necessary.
2. Select the Random Number (0-1) on the Functions»Arithmetic and Comparison»Numeric palette. Alternatively you could use a VI that is gathering data from an external sensor.
3. Wire the block diagram objects as shown in the previous block diagram.
4. Save the VI as Use a Loop.vi because you will use this VI later in the course.
5. Display the front panel by clicking it or by selecting Window»Show Panel.
6. 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.
7. Click the STOP button to stop the acquisition. The condition is FALSE, and the loop stops executing.
8. 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.
1. Right-click the waveform chart and select Data Operations»Clear 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 Functions»Execution 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.
2. Save the VI, because you will use this VI later in the course.
3. Run the VI.
4. Try different values for the millisecond delay and run the VI again. Notice how this effects the speed of the number generation and display.
5. Close the VI.
No comments:
Post a Comment