EasyManua.ls Logo

Microchip Technology dsPIC30F - 32-Bit Timer Modes of Operation

Microchip Technology dsPIC30F
738 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
dsPIC30F Family Reference Manual
DS70059C-page 12-18 © 2004 Microchip Technology Inc.
12.10 32-bit Timer Modes of Operation
12.10.1 Timer Mode
Example 12-5 shows how to configure a 32-bit timer in Timer mode. This example assumes
Timer2 is a Type B time base and Timer3 is a Type C time base. For 32-bit timer operation, the
T32 control bit must be set in the T2CON register (Type B time base). When Timer2 and Timer3
are configured for a 32-bit timer, the T3CON control bits are ignored. Only the T2CON control
bits are required for setup and control. The Timer2 clock and gate input is utilized for the 32-bit
timer module, but an interrupt is generated with the T3IF flag. Timer2 is the LSWord and Timer3
is the MSWord of the 32-bit timer. TMR3 is incremented by an overflow (carry-out) from TMR2.
The 32-bit timer increments up to a match value preloaded into the combined 32-bit period
register formed by PR2 and PR3, then rolls over and continues. For a maximum 32-bit timer
count, load PR3:PR2 with a value of 0xFFFFFFFF. An interrupt is generated on a period match,
if enabled.
Example 12-5: Initialization Code for 32-bit Timer Using Instruction Cycle as
Input Clock
; The following code example will enable Timer3 interrupts, load the
; Timer3:Timer2 Period Register and start the 32-bit timer module
; consisting of Timer3 and Timer2.
; When a 32-bit period match interrupt occurs, the user must clear
; the Timer3 interrupt status flag in software.
CLR T2CON ; Stops any 16/32-bit Timer2 operation
CLR T3CON ; Stops any 16-bit Timer3 operation
CLR TMR3 ; Clear contents of the Timer3 timer register
CLR TMR2 ; Clear contents of the Timer2 timer register
MOV #0xFFFF, w0 ; Load the Period Register 3
MOV w0, PR3 ; with the value 0xFFFF
MOV w0, PR2 ; Load the Period Register2 with value 0xFFFF
BSET IPC1, #T3IP0 ; Setup Timer3 interrupt for
BCLR IPC1, #T3IP1 ; desired priority level
BCLR IPC1, #T3IP2 ; (this example assigns level 1 priority)
BCLR IFS0, #T3IF ; Clear the Timer3 interrupt status flag
BSET IEC0, #T3IE ; Enable Timer3 interrupts
BSET T2CON, #T32 ; Enable 32-bit Timer operation
BSET T2CON, #TON ; Start 32-bit timer with prescaler
; settings at 1:1 and clock source set to
; the internal instruction cycle
; Example code for Timer3 ISR
__T3Interrupt:
BCLR IFS0, #T3IF ; Reset Timer3 interrupt flag
; User code goes here.
RETFIE ; Return from ISR

Table of Contents

Other manuals for Microchip Technology dsPIC30F