User manual
RP6 ROBOT SYSTEM - 4. Programming the RP6
4.4.10. Program flow and interrupts
As discussed before, a program will be executed basically instruction after instruction
from the top to the bottom. Apart from this standard behaviour, there is flow control
with conditional jumps, loops and functions.
Beneath these usualy things, there are so-called “interrupts”. They may be generated
by several hardware modules (Timer, TWI, UART, external Interrupts etc.) and require
the microcontrollers's immediate attention. In order to respond as soon as possible,
the microcontroller will leave normal program flow and jump into a so-called Interrupt
Service Routine (ISR). This interrupt reaction is virtually independent from the pro-
gram flow. Don't worry! All required ISRs have been prepared in the RP6Library and
take care of all required events. You will not have to implement your own ISRs. All ba-
sic things you need to know about these special interrupt-functions will be discussed
and explained briefly in this section.
Basically the ISR is structured as follows:
ISR ( <InterruptVector> )
{
<command block>
}
e.g. for the left encoder connected to the external interrupt 0:
ISR (INT0_vect)
{
// Here we increment two counters at each signal edge:
mleft_dist++; // driven distance
mleft_counter++; // velocity measurement
}
You can not call these ISRs directly! Calling an ISR is done automatically and may
happen at any time! Any time and in any part of the program an interrupt call may
stop normal program flow (except inside an interrupt service routine or in case inter-
rupts have been disabled). At an interrupt event, the apropriate ISR-function will be
executed and after termination of the ISR, the program will continue execution at the
after the last position in the normal program. This behaviour requires inclusion of all
time critical program parts into the ISR-functions (or disabling interrupts for a short
time). Otherwise delay periods calculated by processor instruction cycles may get too
long, if these delays are interrupted by interrupt events.
The RP6Library uses interrupts for generating the 36kHz modulation signals for in-
frared sensors and IR communication. Additionally they are used for RC5 decoding,
timing and delay functions, encoder measurement, the TWI module (I²C-Bus) and a
few other applications.
- 76 -










