Rabbit 4000 Microprocessor User's Manual |
14. Timer B
14.1 Overview
The Timer B peripheral consists of a ten-bit free running up-counter, two match registers, and two step registers. Timer B is driven by perclk/2, by perclk/16, or by the output of timer A1. Timer B generates an output pulse whenever the counter reaches the match value. This output pulse can generate an interrupt and will set a status bit in the status register. The processor may then write a new value to the match register. This allows Timer B to be used for pulse-width or pulse-position modulation because the outputs of Timer B can clock the outputs on Parallel Ports D and E.
The compare value comes from either the match register or the value internally generated via the step register. When using the match register, a new match value must be written to the match register after each match condition, LSB first. When using the step register, the hardware automatically calculates the next match value by adding the contents of the step register to the current match value. This allows Timer B matches to be generated at regular periods without calculating the new match value during the interrupt service routine.
14.1.1 Block Diagram
14.1.2 Registers
14.2 Dependencies
14.2.1 I/O Pins
The output of Timer B does not come out directly on any of the I/O pins. It can be used to control when the output occurs on Parallel Ports DE.
14.2.2 Clocks
The timer in Timer B can be clocked by perclk/2, perclk/16, or by countdown timer A1 as selected in TBCR.
14.2.3 Other Registers
GCSR
Select peripheral clock mode.
14.2.4 Interrupts
A Timer B interrupt can be generated whenever the counter equals one of the match registers by enabling the appropriate bit in TBCSR. The interrupt request is cleared when TBCSR is read.
14.3 Operation
The following steps explain how to set up a Timer B countdown timer.
- Select perclk/2, perclk/16, or countdown timer A1 in TBCR.
- Use TBCR to select whether countdown timers B1B2 operate normally with the match registers or whether they use the step registers to calculate match values.
- Enable Timer B by writing a 1 to bit 0 of TBCSR.
14.3.1 Handling Interrupts
The following steps explain how an interrupt is set up and used.
- Write the vector to the interrupt service routine to the internal interrupt table.
- Configure TBCSR to select which match registers will generate an interrupt.
- Configure TBCR to select the interrupt priority (note that interrupts will be enabled once this value is set; this step should be done last).
The interrupt request is cleared by reading from TBCSR.
14.3.2 Example ISR
A sample interrupt handler is shown below.
timerB_isr::
push af ; save used registers
ioi ld a, (TBCSR) ; clear the interrupt request and get status
; handle all interrupts flagged in TBCSR here
; reload match register(s) if necessary
pop af ; restore used registers
ipres
ret14.4 Register Descriptions
Eight LSBs of the compare value for the Timer B comparator. This compare value will be loaded into the actual comparator when the current compare detects a match.
Eight LSBs of the step size for the Timer B comparator. The new compare value will be loaded into the actual comparator when the current compare detects a match.
The current value of the two MSBs of the Timer B counter are reported.
These bits are always read as zeros.
The current value of the eight LSBs of the Timer B counter are reported.
Rabbit Semiconductor www.rabbit.com |