User’s Manual
117
11.2.1 Using Timer B
Normally the prescaler is set to divide
PCLK
/2 by a number that provides a counting rate
appropriate to the problem. For example, if the clock is 22.1184 MHz, then
PCLK
/2 is
11.0592 MHz. A Timer B clock rate of 11.0592 MHz will cause a complete cycle of the
10-bit clock in 92.6 µs.
Normally an interrupt will occur when either of the comparators in Timer B generates a
pulse. The interrupt routine must detect which comparator is responsible for the interrupt
and dispatch the interrupt to a service routine. The service routine sets up the next match
value, which will become the match value after the next interrupt. If the clocked parallel
ports are being used, then a value will normally be loaded into some bits of the parallel
port register. These bits will become the output bits on the next match pulse. (It is neces-
sary to keep a shadow register for the parallel port unless the bit-addressable feature of
ports D and E is used.)
If it is desired to read the time from the Timer B counter, either during an interrupt caused
by the match pulse or in some other interrupt routine asynchronous to the match pulse, a
special procedure needs to be used to read the counter because the upper 2 bits are in a dif-
ferent register than the lower 8 bits. The following method is suggested.
1. Read the lower 8 bits.
2. Read the upper 2 bits
3. Read the lower 8 bits again
4. If bit 7 changed from 1 to 0 between the first and second read of the lower 8 bits there
has been a carry to the upper 2 bits. In this case read the upper 2 bits again and decre-
ment those 2 bits to get the correct upper 2 bits. Use the first read of the lower 8 bits.
This procedure assumes that the time between reads can be guaranteed to be less than 256
counts. This can be guaranteed in most systems by disabling the priority 1 interrupts,
which will normally be disabled in any case in an interrupt routine.
It is inadvisable to disable the high-priority interrupts (levels 2 and 3) as that defeats their
purpose.
If speed is critical, the three reads of the registers can be performed without testing for the
carry. The three register values can be saved and the carry test can be performed by a
lower priority analysis routine. Since the upper 2 bits are in the register TBCMR at
address 0x0BE, and the lower 8 bits are in TBCLR at address 0x0BF, both registers can be
read with a single 16-bit I/O instruction. The following sequence illustrates how the regis-
ters could be captured.
; enter from external interrupt on pulse input transition
; 19 clocks latency plus 10 clocks interrupt execution
push af ; 7
push hl
ioi ld a,(TBCLR) ; 11 get lower 8 bits of counter
ioi ld hl,(TBCMR) ; 13 get l=upper, h=lower
Summary of Contents for 2000
Page 1: ...Rabbit 2000 Microprocessor User s Manual 019 0069 041018 M...
Page 12: ...6 Rabbit 2000 Microprocessor...
Page 46: ...40 Rabbit 2000 Microprocessor...
Page 54: ...48 Rabbit 2000 Microprocessor...
Page 76: ...70 Rabbit 2000 Microprocessor...
Page 96: ...90 Rabbit 2000 Microprocessor...
Page 142: ...136 Rabbit 2000 Microprocessor...
Page 154: ...148 Rabbit 2000 Microprocessor...
Page 170: ...164 Rabbit 2000 Microprocessor...
Page 174: ...168 Rabbit 2000 Microprocessor...
Page 180: ...174 Rabbit 2000 Microprocessor...
Page 202: ...196 Rabbit 2000 Microprocessor...
Page 206: ...200 Rabbit 2000 Microprocessor...
Page 226: ......
Page 230: ...224 Rabbit 2000 Microprocessor...