Rabbit 4000 Microprocessor User's Manual |
15. Timer C
15.1 Overview
The Timer C peripheral is a 16-bit up-counter clocked by the peripheral clock divided by 2, by the peripheral clock divided by 16, or by the output of countdown timer A1. The counter counts from zero to the limit programmed into the Timer C divider registers and then restarts at zero, so the overall cycle count is the value in the divider registers plus one. There are four Timer C outputs that are called Timers C0C3. Each output is controlled by a 16-bit set value and a 16-bit reset value. Each output is set to one when the count matches the value in the corresponding set register and is cleared when the count matches the value programmed in the corresponding reset register. This allows the creation of quadrature signals or three-phase signals with a variable frequency for motor-control applications. The values in all of the Timer C registers are transferred to holding registers for use during the count cycle when the counter is reloaded with zeros, allowing the control registers to be reloaded at any time during the count cycle.
Timer C can generate an interrupt when the count limit value is reached.
A separate Timer C Block Access Register (TCBAR) and Timer C Block Pointer Register (TCBPR) are available to allow DMA control of Timer C. The pointer register contains the address of the Timer C register to be accessed via the access register. Each read or write of the access register automatically increments the pointer register through the sequence shown below. Note that only the lower five bits of the pointer actually change. This allows the DMA to write to a fixed internal I/O location but still program all of the relevant Timer registers. The pointer register can be written and read if necessary. Normally the pointer register is initialized to 0x02 (the Timer C Divider Low Register), and the DMA then transfers blocks of 18 bytes to completely reprogram Timer C.
0x502 -> 0x503 -> 0x508 -> 0x509 -> 0x50A -> 0x50B ->
0x50C -> 0x50D -> 0x50E -> 0x50F -> 0x518 -> 0x519 ->
0x51A -> 0x51B -> 0x51C -> 0x51D -> 0x51E -> 0x51F ->When the DMA destination address is the TCBAR, the DMA request from Timer C is connected automatically to the DMA.
15.1.1 Block Diagram
15.1.2 Registers
15.2 Dependencies
15.2.1 I/O Pins
The four Timer C outputs can be directed to PC0-PC3, PD0-PD3, or PE0-PE3.
15.2.2 Clocks
The timer in Timer C is a 16-bit up-counter clocked by the peripheral clock divided by 2, by the peripheral clock divided by 16, or by the output of timer A1 as selected in TCCR.
15.2.3 Other Registers
GCSR
Select peripheral clock mode.
PCFR, PCALR
PDFR, PDALR
PEFR, PEALR
Alternate port output selection
15.2.4 Interrupts
A Timer C interrupt is enabled in TCCR, and will occur whenever the count limit value is reached. The interrupt request is cleared when TCCSR is read.
15.3 Operation
The following steps explain how to set up a Timer C timer.
- Select perclk/2, perclk/16, or countdown timer A1 in TCCR.
- Load the desired upper limit for the counter into TCDLR and TCDHR. The overall clock count per Timer C cycle will be the value loaded into the divider registers plus one.
- Load the desired set and reset values for the Timer C outputs into the set and reset registers (TCSxLR, TCSxHR, TCRxLR, and TCRxHR).
- If you intend to use DMA control of Timer C, use TCBAR to access the Timer C register pointed to by TCBPR.
- Enable the desired output pins for Timer C by writing to the appropriate parallel port function and alternate output registers.
- Enable Timer C by writing a 1 to bit 0 of TCCSR.
15.3.1 Handling Interrupts
The following steps explain how an interrupt is used.
- Write the vector to the interrupt service routine to the internal interrupt table.
- Configure TCCR to select the interrupt priority (note that interrupts will be enabled once this value is set).
The interrupt request is cleared by reading from TCCSR.
15.3.2 Example ISR
A sample interrupt handler is shown below.
timerC_isr::
push af ; save used registers
ioi ld a, (TCCSR) ; clear the interrupt request and get status
; handle all interrupts flagged in TCCSR here
pop af ; restore used registers
ipres
ret15.4 Register Descriptions
The eight LSBs of the divider limit value for Timer C are stored.
The eight MSBs of the divider limit value for Timer C are stored.
Eight LSBs of the match value to set Timer C Output x.
Eight MSBs of the match value to set Timer C Output x.
Eight LSBs of the match value to reset Timer C Output x.
Eight MSBs of the match value to reset Timer C Output x.
Access the Timer C register pointed to by TCBPR. TCBPR is automatically updated to the next Timer C register address in the sequence.
These bits always read as 0x0.
Five least significant bits of the Timer C register address for indirect access.
Rabbit Semiconductor www.rabbit.com |