Event multitasking – Remote Processing CAMBASIC User Manual
Page 190
Event Multitasking - 1
Event Multitasking
Event Multitasking was developed to give faster response to real time events. It is different than the multitasking that was
originally designed for bu siness applications and later used in som e industrial control language s.
Time Slice Multitasking – The Old W ay
This older form of multitasking usually takes two forms. The most popular is called “time slice.” Each task is written as
if it were a separate progr am. The fir st task starts and , on a clock tick (usu ally 60 times p er secon d), th at task is
suspended a nd the next task sta rts. After a nother clo ck tick, the second task is suspended a nd the third ta sk begins. This
continues until all tasks have had their slice of time and the process starts over.
To get some idea of the performance level of this type of multitasking, assume that there are 10 equal tasks. Tasks are
switched 60 times per second. W ith 10 tasks, each task is serviced only 60/10 or 6 times per second.
The second form is really a version of the first. T asks are switched after each command in each task. This increases the
task switching to severa l hundred times per second, but the switchin g overh ead serio usly slows the th roughp ut.
The problem w ith time slice is that all the tasks are written in BASIC. Since there is only one microprocessor chip, and
task switching takes processor time away from progr am execution, the system will actually run slower than with a
n o n– m u lt it a sk in g pr o g ra m .
Event Multitasking – For Real Time Con trol
Event Multitasking in CAMBASIC solves the speed problem by compiling all tasks into machine code, which executes
much faster than BASIC. CAM BASIC executes about 3600 commands per second, which is very fast by BASIC
standards. It also can execute 5000 tasks per second in the background while maintaining the foreground rate!
NOTE: These num bers are h alf for 9 M Hz systems.
There are some limitations to this method. You can only use the tasks defined by the language. These are:
Output Timing (PULSE)
Input Counting (COUNT)
Keypad (KEYPA D$)
Comm unications (COM$)
Hardware Interrupts (ITR)
Change of state on inputs (INP)
Periodic Interrupts (TICK)
A series of special commands are used for the tasks. You do not use CAM BASIC comm ands like POKE, GOTO , etc. for
the tasks.
Hardware vs Softw are Interrupts
It is important to understand the difference between hardware and software interrupts when dealing with a high level
language. CA MBASIC can respond to hardware interr upts, but only indirectly.
When a hardware interrupt occurs, an internal flag is set within a few microseconds. In the same manner, any task that
can cause an interrupt set an internal flag.