Wednesday, August 18, 2010

Exercise 3 – Using Loops

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.
    1. 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.
    2. Type millisecond delay inside the label and click outside the label or click the Enter button on the toolbar, shown at left.
    3. Place a Stop Button from the Controls»Buttons palette.
    4. 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.
    5. Type Value History inside the label and click outside the label or click the Enter button.
    6. 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.
    7. 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.
    8. Change –10.0 in the y-axis to 0.
    9. 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 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.

End of Exercise

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...

Popular Projects

My Blog List

Give support

Give support
Encourage Me through Comments & Followers