Sie sind auf Seite 1von 8

ECE 100 Fundamentals of LabVIEW Programming

TIMING FUNCTIONS AND SHIFT REGISTER


Activity No. 8

I. INTENDED LEARNING OUTCOMES

At the end of this activity, the student shall be able to:


1. Understand the concept of Timing Functions together with the use of Shift Registers.
2. Create an important program using Timing Functions and Shift Registers.

II. BACKGROUND INFORMATION

Normally when a loop, such as a while loop, finishes executing one iteration, it immediately begins
running the next. It is often beneficial to control how often a loop executes, or its frequency. For example, if
you wanted to acquire data in a loop, you would need a method to control the frequency of the data
acquisition. Timing a loop also allows the processor time to complete other tasks such as updating and
responding to the user interface. In the following figures, the processor usage for a simple VI with a while
loop running untimed and timed are shown. Timing a loop can drastically increase performance.

After you create a loop, you can place a wait VI inside of the loop to control how long it waits before
performing the next iteration. There are two basic wait functions in LabVIEW: Wait (ms) and Wait Until Next
ms Multiple.

The Wait (ms) function forces the loop to wait for a user-specified amount of time, in milliseconds,
before running the next iteration. The Wait Until Next ms Multiple function watches the millisecond counter
and waits for it to reach a multiple of the user-specified time, in milliseconds, before running the next
iteration of the loop. You can use this VI to synchronize different activities. For example, you can configure
multiple loops to execute at each multiple of 200 ms.

III. LEARNING ACTIVITIES

ACTIVITY 8.1: IMPLEMENTING A WAIT FUNCTION IN A LOOP


Consider using one of the wait functions in a while loop. Using the information from previous tutorials, create a blank VI in
LabVIEW.

Page 58
ECE 100 Fundamentals of LabVIEW Programming
1. Place a knob numeric control on the front panel by right-clicking on the front panel and navigating to
ControlsModernNumericKnob.

2. Change the knobs limits to 1 and 1000 by double-clicking on the knobs current limits and entering the new values. You
will use the knob to control a while loops wait time.

3. Place a numeric indicator on the front panel by right-


clicking on the front panel and navigating to
ControlModerNumericNumeric Indicator.

4. This indicator displays the while loop iterations.

Page 59
ECE 100 Fundamentals of LabVIEW Programming

5. Change the Representation of the numeric indicator to I-32 (long integer) by right-clicking on the indicator and
selecting Representation. Click on I32.

6. Place a Stop Boolean control on the front panel. You can find this
at ControlsModernBooleanStop Button. Use this Stop button to stop the while loop.

7. Double-click the name of the knob and change its name to Wait Time (ms).

8. Double-click the name of the numeric indicator and change its name to Iteration.

9. View the block diagram by selecting WindowShow Block Diagram or pressing <ctr-E>.

10. On the block diagram, drag a while loop around the front panel controls and indicator. Find the while loop at
FunctionsProgrammingStructuresWhile loop.

Page 60
ECE 100 Fundamentals of LabVIEW Programming

After selecting the while loop, drag it around the three icons. If you miss one icon, just click and drag it into the loop.

11. Wire the Stop control to the while loops stop conditional terminal. Click on the right terminal of the Stop buttons icon,
drag to the left input terminal of the stop conditional terminal, and click to complete the wire.

12. Wire the numeric indicator to the while loop iteration terminal.
13. Right-click on the block diagram to open the Functions palette and then
navigate to and open the Timing palette, which is located
at FunctionProgrammingTiming.
14. Place the Wait (ms) function, located in the Timing palette, inside the while-
loop.

Page 61
ECE 100 Fundamentals of LabVIEW Programming
15. Wire the knob control Wait Time (ms) to the input of the Wait (ms) function. The knob value specifies how long, in
milliseconds, the loop waits before running the next iteration.

16. View the block diagram by selecting WindowShow Front Panel or pressing <ctr-E>. Run the VI.

17. As the VI runs, change the knob value by clicking and


dragging the knob; note that the speed of the loop, as shown by
the iteration indicator, changes accordingly.

19. Stop the VI using the Stop Boolean control.

Iterative Data Transfer


When programming with loops, sometimes you need to call data from previous iterations of the loop. In LabVIEW, you can
use shift registers, which are similar to static variables in text-based programming languages, to pass values from one loop
iteration to the next.

Page 62
ECE 100 Fundamentals of LabVIEW Programming
Data enters the right shift register and is passed to the left shift register on the next iteration of the loop.

IV. MACHINE PROBLEM

1. Create a timed loop program application for Machine Problem No. 1 of Activity 7 with the following
specification:

Create a VI that will allow you to classify the winds speed into the following category using the Case
Structure. Your VI should be customized and be saved as MacPro8_1.VI.
0-20 KPH (Calm Wind)
21-30 KPH (Breezy)
31-50 KPH (Windy)
51-80 KPH (Low Pressure)
80-90 KPH (Tropical Depression)
90-120 KPH (Tropical Storm)
120-150 KPH (Typhoon)
150 and above (Super Typhoon)

2. Create a LabVIEW program of a simulation of any control and instrumentation system. Make your VI
visually presentable and makes use of shift registers and timing functions.

Page 63
ECE 100 Fundamentals of LabVIEW Programming

V. ASSESSMENT TASKS

1. What is the importance of Timing object in dealing with the while loop and for loop structures?

Wait Until Next ms Multiple Function - when in the sequence the Wait Until Next
ms Multiple executes. The behavior of this loop will differ depending on when
the Wait Until Next ms Multiple gets executed. If the Wait Until Next ms Multiple
executes first, then the analog input will be followed immediately by the analog
output. This behavior is usually desired, but is not guaranteed in the example
above. If the Wait Until Next ms Multiple executes immediately after the analog
input, then the analog output will not be able to execute until the Wait Until
Next ms Multiple is finished. Again,

2. How do we use the shift registers to apply in iterative data transfer?

Use shift registers when you want to pass values from previous iterations
through a loop to the next iteration. A shift register appears as a pair of
terminals, shown as follows, directly opposite each other on the vertical sides
of the loop border

3. What are the different timing functions in LabVIEW and state their uses.
Date/Time Converts a cluster of time values into a timestamp measured as the number of seconds
To Seconds that have elapsed since 12:00 a.m., Friday, January 1, 1904, Universal Time,
assuming is DST is set to 1.
Elapsed Indicates the amount of time that has elapsed since the specified start time.
Time
Format Displays a timestamp value or a numeric value as time in the format you specify
Date/Time using time format codes. For example, %c displays locale-specific date/time. Time-
String related format codes include the following: %X (locale-specific time), %H (hour, 24-hour
clock), %I (hour, 12-hour clock), %M (minute), %S(second), %<digit>u (fractional
seconds with <digit> precision), and %p(a.m./p.m. flag). Date-related format codes
include the following: %x (locale-specific date), %y (year within century), %Y (year
including century), %m(month number), %b (abbreviated month name), %d (day of
month), and %a(abbreviated weekday name).
Get Returns a timestamp of the current time. LabVIEW calculates this timestamp using the
Date/Time number of seconds elapsed since 12:00 a.m., Friday, January 1, 1904, Universal Time.
In Seconds
Get Converts a timestamp value or a numeric value to a date and time string in the time
Date/Time zone configured for the computer. The function interprets timestamp and numeric values
String as the time-zone-independent number of seconds that have elapsed since 12:00 a.m.,
Friday, January 1, 1904, Universal Time.
Seconds To Converts a timestamp value or a numeric value to a cluster of time values.
Date/Time
Tick Count Returns the value of the millisecond timer.
(ms)
Time Delay Inserts a time delay into the calling VI.

Page 64
ECE 100 Fundamentals of LabVIEW Programming

Time Stamp Use the time stamp constant to pass a time and date value to the block diagram.
Constant
To Time Converts a number to a timestamp.
Stamp
Wait (ms) Waits the specified number of milliseconds and returns the value of the millisecond
timer. Wiring a value of 0 to the milliseconds to wait input forces the current thread
to yield control of the CPU.
Wait Until Waits until the value of the millisecond timer becomes a multiple of the
Next ms specified millisecond multiple. Use this function to synchronize activities. You can call
Multiple this function in a loop to control the loop execution rate. However, it is possible that the
first loop period might be short. Wiring a value of 0 to the milliseconds multiple input
forces the current thread to yield control of the CPU.

VI. CONCLUSION
This activity is the last activity in this subject and this is the most. Easies but difficult function its
because it has the timing of an interval which the VI can convey. There are a lots of function of
timing function such as wait until next ms multiple, time stamp and wait(ms) this function can be
used in any kind of VI programing. And the most electronic parts of it is the shift register which
indicate the repeating process of a VI

VII. RUBRICS FOR LABORATORY PERFORMANCE8

Page 65

Das könnte Ihnen auch gefallen