Specifications

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 business applications and later used in some industrial control languages.
Time Slice Multitasking – The Old Way
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 program. The first task starts and, on a clock tick (usually 60 times per second), that task is suspended
and the next task starts. After another clock tick, the second task is suspended and the third task 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. With 10 tasks, each task is serviced only 60/10 or 6 times per second.
The second form is really a version of the first. Tasks are switched after each command in each task. This increases the
task switching to several hundred times per second, but the switching overhead seriously slows the throughput.
The problem with 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 program execution, the system will actually run slower than with a
non–multitasking program.
Event Multitasking – For Real Time Control
Event Multitasking in CAMBASIC solves the speed problem by compiling all tasks into machine code, which executes
much faster than BASIC. CAMBASIC 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 numbers are half for 9 Mhz 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 (KEYPAD$)
Communications (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 CAMBASIC commands like POKE, GOTO, etc. for
the tasks.
Hardware vs Software Interrupts
It is important to understand the difference between hardware and software interrupts when dealing with a high level
language. CAMBASIC can respond to hardware interrupts, 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.
Between each program statement CAMBASIC checks to see if any interrupt flags are set. If so, it branches to the line
number that was specified for that interrupt. The maximum time to service an interrupt is the length of the command
previous to the interrupt. This is called maximum latency time. It ranges from about 0.2 milliseconds to 2 milliseconds.