Multitasking on a clock tick – Remote Processing CAMBASIC User Manual
Page 202
Event Multitasking - 13
MULTITASKING ON A CLOCK TICK
T h e th r e e 2 0 0 H z ( 10 0 H z i n 9 M H z sy s te m s ) t ic k ti m er s ar e u se d fo r a nu m b er o f m u lt it a sk in g fu n ct io n s i n C A M B A SI C .
In multitasking, it is used as a periodic interrupt. The ON T ICK statement can call a subroutine as often as 200 (100 in 9
MH z systems) times per second, or once ever y 327.6 7 seconds. The syntax is:
ON TIC K number, time GOS UB line/label
On every multiple of the specified time, program execution branches to the subroutine at the line/label. Pr ogram
execution resumes when the RETUR N statement is reached in the subroutine.
A simple exam ple would be as follows:
10 ON TICK 0,1 GOSUB 50
20 PRINT "foreground"
30 FOR C=0 TO 1000:NEXT
40 GOTO 20
50 INC A%
60 PRINT A
70 RETURN
Line 10 tells CAMBASIC to interrupt every 1.00 seconds and br anch to line 50.
Lines 20 through 40 represent a foregr ound program. It prints, does a short delay and prints again.
Line 50 increm ents a variable and r epresents the num ber of seconds.
In some a pplications m ultiple interr upts are r equired . T his can be don e with the T ICK statem ent. The only lim itation is
that the interrupt times must be multiples of each other. For exam ple, 1. 0 and 3.0 seconds would be acceptable, but 1.0
and 2. 7 seconds w ould not.
Below is a progr am that demo nstrates clock interr upts every 1 and 5 seco nds.
10 ON TICK 0,1 GOSUB 50
20 PRINT "foreground"
30 DELAY .25
40 GOTO 20
50 PRINT TAB(20);"tick";
60 INC A%:IF A%=5 THEN A%=0:GOSUB 70 ELSE PRINT:RETURN
70 PRINT " tock"
80 RETURN
Line 10 sets up an interrupt every 1.00 seconds
Lines 20 through 40 simulate your foreground program, as in the first example.
Line 50 prints “tick” every second
Line 60 increments a second counter. When it reaches 5, the counter is reset and "tock" is printed at
line 70.