Rockwell Automation 6008-SI IBM PC I/O SCNNR 6008-SI User Manual
Page 109

Chapter 9
General Support Features
9-2
g_accum
is an unsigned integer timer accumulator for the exclusive use of your
program. Since g_accum has a capacity of 65,535 ticks, it flips back to
zero in about an hour if not reset by your program during that time.
Your program can write a loop using the accumulator timer by setting it to
zero, then repeatedly testing for some desired value. For instance, to wait
for approximately half a second the following code would suffice:
for ( g_accum = 0; g_accum < 9; )
; /* null wait loop: 495 ms max */
This technique, while easy, is not terribly accurate. Why? When you set
g_accum you are not necessarily synchronized with a clock tick. If you
happen to set g_accum just after a clock tick, it will be almost 55 ms until
the next tick and your program will spend almost 495 ms in the loop. But
if you happen to set g_accum just before a tick, the time spent in the loop
will be almost a full tick short. In general, you should code loops that wait
for external events to allow one more tick than necessary.
g_decrem
decrement timer (negative timer accumulator), an integer whose value
decreases once for every clock tick. The time base is the same as for
g_accum, and therefore g_decrem flips from negative to positive about
once an hour.
This counter is intended primarily for use by your program, but is also
used by the driver routines start_6008, setup_6008, mr_wait, and update.
Therefore you should not use g_decrem to control any timing loop that
contains a call to any of those routines. (In any case, start_6008 and
setup_6008 should not be in a loop.)
Timer decrement loops start with a certain value and wait until g_decrem
reaches zero. A pure wait loop can test for g_decrem nonzero, but a loop
that does something and is also terminated by time should test g_decrem
not positive in case one pass through the loop takes more than one clock
tick.
Here’s a sample of a pure one second wait loop, using a while loop rather
than a for loop for variety:
g_decrem = 19; /* 990 to 1045 ms */
while ( g_decrem )
; /* null loop for waiting */
Please read the explanation of g_accum above for the 55 ms uncertainty in
timing.