Rpbasic-52 programming guide – Remote Processing BASIC 52 User Manual
Page 10

RPBASIC-52 PROGRAMMING GUIDE
1-7
HARDWARE AND SOFTWARE
INTERRUPTS
RPB ASIC5 2 generate s two kinds o f interrupts:
hardware and so ftware. Hardware types are tho se
generated by a voltage change and go directly to the
processor. Software types require program execution
and set memory flags that are read by some other
program.
NOTE: Not all products support all or the same
interrupts. Make sure the "Cards:" category
in each com mand lists you r card or re fer to
your hardw are manua l.
There are six interrupts in RPBASIC-52, version 1.11
and later. In the unlikely scenario that all interrupt
conditions are met at exactly the same time, they
would be serviced in the following order:
ONTICK
Periodic
ONITR
External line
ON COUNT
Counter
ON LINE
Line change
O N C O M $
Serial input
ON KEYPAD
Keypad
Interrupt priority is based on hardware or software
type. ONTICK and ONITR are co nsidered hardware
types. Should either one of these interrupts become
active, ON COUN T, ON LINE , ON KEY PAD, and
ON C OM$ interrupts are n ot run until either o ne is
finished. If an ONTICK interrupt is running, an
ONIT R interrupt is no t serviced until O NTIC K is
complete. ON TICK a nd ONIT R have the highest
priority.
ON C OUN T, ON LINE, a nd ON COM $ interrupts
are serviced after ONT ICK and ONIT R are com plete.
Should any these last three interrupts occur
simultaneou sly, ON C OUN T would be execute d first.
However, if any of these three interrupts occur after
one has starte d, then it would take priority.
Interrupts oc cur any time d uring prog ram execu tion.
The RP BASIC operating sys tem sets app ropriate
flags indicating which kind of interrupt needs
services. At the end of the current statement it checks
these flags. The time interval between the actual
interrupt and start of the interrupt routine is called
latency.
Latency varies a great deal, depending upon the type
of interrupt an d comm and curre ntly executed . A
"typical" tim e in RPB ASIC is less th an 1 ms.
However, it can be as short as several micro-seconds
to several sec onds. Th e reason it ca n take so long is
due to the Basic subroutine. Suppose an ONTICK
interrupt is in progress and it is written so it takes
several seconds to com plete. Since it is the highest
priority, all other interrupts are locked out. The best
way to correct this situation is to make all interrupt
routines as short as possible. This is handled by
setting a flag using a variable in the interrupt routine
then exiting. Then at some other non-critical time,
the interrupt is serviced.
WARNING:
RPB ASIC-5 2 offers a op portunity
for all interrupts to occur
simultaneously. It can handle all 21
interrupts simu ltaneously.
However, it cannot handle them
when they occur at a rate faster than
they are serviced. Servicing all 21
interrupts requires a minimum of 21
ms. If interrupts consistently come
in faster than they can be handled,
the program will stop and a control
stack error returned.
Whenever an ON COUNT or ON LINE multitasking
command is enabled, overall program speed slows
down. If all O N CO UNT and ON LINE in terrupts
were enabled (but lines were not changing), program
s p ee d sl o ws d ow n by a bo u t 6 % .