EasyManua.ls Logo

Microchip Technology dsPIC30F - 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...
© 2004 Microchip Technology Inc. DS70059C-page 12-9
Section 12. Timers
Timers
12
12.4 Modes of Operation
Each timer module can operate in one of the following modes:
As a synchronous timer
As a synchronous counter
As a gated timer
As an asynchronous counter (Type A time base only)
The Timer modes are determined by the following bits:
TCS (TxCON<1>): Timer Clock Source Control bit
TSYNC (T1CON<2>): Timer Synchronization Control bit (Type A time base only)
TGATE (TxCON<6>): Timer Gate Control bit
Each timer module is enabled or disabled using the TON Control bit (TxCON <15>).
12.4.1 Timer Mode
All types of timers have the ability to operate in Timer mode. In Timer mode, the input clock to
the timer is provided from the internal system clock (F
OSC/4). When enabled, the timer
increments once per instruction cycle for a 1:1 prescaler setting. The Timer mode is selected by
clearing the TCS control bit (TxCON<1>). The Synchronous mode control bit, TSYNC
(T1CON<2>), has no effect, since the system clock source is used to generate the timer clock.
Example 12-1: Initialization Code for 16-bit Timer Using System Clock
Note: Only Type A time bases support the External Asynchronous Clock mode.
; The following code example will enable Timer1 interrupts,
; load the Timer1 Period register and start Timer1.
; When a Timer1 period match interrupt occurs, the interrupt
; service routine must clear the Timer1 interrupt status flag
; in software.
CLR T1CON ; Stops the Timer1 and reset control reg.
CLR TMR1 ; Clear contents of the timer register
MOV #0xFFFF, w0 ; Load the Period register
MOV w0, PR1 ; with the value 0xFFFF
BSET IPC0, #T1IP0 ; Setup Timer1 interrupt for
BCLR IPC0, #T1IP1 ; desired priority level
BCLR IPC0, #T1IP2 ; (this example assigns level 1 priority)
BCLR IFS0, #T1IF ; Clear the Timer1 interrupt status flag
BSET IEC0, #T1IE ; Enable Timer1 interrupts
BSET T1CON, #TON ; Start Timer1 with prescaler settings
; at 1:1 and clock source set to
; the internal instruction cycle
; Example code for Timer1 ISR
__T1Interrupt:
BCLR IFS0, #T1IF ; Reset Timer1 interrupt flag
; User code goes here.
RETFIE ; Return from ISR

Table of Contents

Other manuals for Microchip Technology dsPIC30F