MOTOROLA
10-12
MAIN TIMER AND REAL-TIME INTERRUPT
M68HC11
REFERENCE MANUAL
performed to the top of the sequence, and all the subroutines are again executed in
sequence. By knowing the time between successive time reference signals, a routine
can measure real time by noting the number of times it is executed and multiplying by
the time between successive time reference signals (in this case, the RTI period).
In the MC68HC11A8, the RTI system can be used to provide this periodic time refer-
ence signal. To accommodate the needs of a variety of applications, four different
rates are available for the RTI signal. These rates are a function of the MCU oscillator
frequency and the value of two software-accessible control bits (RTR1 and RTR0). Al-
though the rate can be changed at any time, it is typically established shortly after reset
and left alone.
The clock source for the RTI function is a free-running clock that cannot be stopped or
interrupted. This clock causes the time between successive RTI time-outs to be a con-
stant, which is independent of the software latencies associated with flag clearing and
service. Thus, an RTI period starts from the previous RTI time-out, not from when RTIF
is cleared.
The most common problem users encounter with the RTI system is that they forget to
clear RTIF after it is recognized. If the flag is not cleared by a specific software write
to the TFLG2 register, it will already be pending the next time it is checked. If the sys-
tem is being used in an interrupt-driven mode, the interrupt will be requested and ser-
viced immediately after the return from interrupt (RTI) instruction is executed at the
end of the RTI service routine. This sequence results in a system lockup where the
RTI service routine is executed continuously to the exclusion of all else. The only way
out of this infinite loop is a system reset. If the RTI system is operating in a polled
mode, the main routine sequence will operate correctly the first time and wait until
RTIF is set the first time. As soon as RTIF is set, the jump is executed back to the top
of the sequence as expected. The routines will be executed the second time and soft-
ware should wait for the end of the next RTI period, but, since RTIF is still set, software
thinks the RTI period has already expired. The result will be that the main sequence is
repeated too quickly.
The following registers and paragraphs explain the RTI flag and RTI enable. The other
bits in these registers are not related to the RTI system.
RTII, RTIF — Real-Time Interrupt Enable, Real-Time Interrupt Flag
The RTIF status bit is automatically set to one at the end of every RTI period. This sta-
TMSK2 —
Timer Interrupt Mask Register 2
$1024
BIT 7
TOI
0
6
5
4
3
0
0
2
0
0
1
BIT 0
PR0
0
RTII
0
PAOVI
0
PAII
0
PR1
0
RESET:
TFLG2 —
Timer Interrupt Flag Register 2
$1025
BIT 7
TOF
0
6
5
4
3
0
0
2
0
0
1
0
0
BIT 0
0
0
RTIF
0
PAOVF
0
PAIF
0
RESET: