Tutorial #11
Time Functions
There are several soft timers available to PL/i. These may be triggered, tested for timeout, checked for present time value, and retriggered. The timers count tenths of seconds. Syntax for timer functions is:
<var> = timer ( <timer> );
<var> = timeout ( <timer> );
trigger ( <timer> , <value> );
<timer> must be an integer timer number. The value returned by timer is a tick count of tenths of seconds remaining before timeout. The value returned by timeout is a boolean which is TRUE if the timer has timed out since the last call to timeout with that timer number, or FALSE if not yet timed out or previously timed out. The timeout function may be used in an expression, for example:
if timeout(2) then seti (10, 0); endif;
The above example will "turn off" the output at register 10 when timer 2 times out. If we wanted to make this more readable, we would have first declared constants such as:
#PumpTimer = 2;
#PumpMotor = 10;
and now our example becomes:
if timeout(#PumpTimer) then

seti (#PumpMotor, 0);
endif;
The trigger function will start, or restart (retrigger), the timer specified, resetting its time value to <value> in tenths of seconds. If the timer had not previously timed out, the new value will take effect without the timeout function returning a TRUE in between. However, if triggered with a value of zero, this will force the timer to zero and cause the timeout function to return TRUE upon its next call.
The function ticks will return the value of a continuously incrementing time counter. Each "tick" represents on tenth of a second, and the counter rolls over to zero when full. Syntax for reading the tick counter is:
myVar = ticks();
The function delay will suspend program execution for some number of seconds, or generate a delay. Examples:
delay (50);
delay (2);
The first example will pause program execution for 5 seconds. The second example will pause for two tenths of a second.