© 2004 Microchip Technology Inc. DS70059C-page 12-11
Section 12. Timers
Timers
12
12.4.3 Type A Timer Asynchronous Counter Mode Using External Clock Input
A Type A time base has the ability to operate in an Asynchronous Counting mode, using an
external clock source connected to the TxCK pin. When the TSYNC control bit (TxCON<2>) is
cleared, the external clock input is not synchronized with the device system clock source. The
time base continues to increment asynchronously to the internal device clock.
The asynchronous operation time base is beneficial for the following applications:
• The time base can operate during Sleep mode and can generate an interrupt on period
register match that will wake-up the processor.
• The time base can be clocked from the low power 32 kHz oscillator for real-time clock
applications.
Example 12-3: Initialization Code for 16-bit Asynchronous Counter Mode Using an
External Clock Input
Note 1: Only Type A time bases support the Asynchronous Counter mode.
2: The external input clock must meet certain minimum high time and low time
requirements when Timerx is used in the Asynchronous Counter mode. Refer to the
device data sheet “Electrical Specifications” section for further details.
3: Unexpected results may occur when reading Timer1, in asynchronous mode.
; The following code example will enable Timer1 interrupts, load the
; Timer1 Period register and start Timer1 using an asynchronous
; external clock and a 1:8 prescaler setting.
; 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 #0x7FFF, w0 ; Load the Period register
MOV w0, PR1 ; with the value 0x7FFF
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
MOV #0x8012, w0 ; Start Timer1 with prescaler settings at
; 1:8 and clock source set to the external
MOV w0, T1CON ; clock in the asynchronous mode
; Example code for Timer1 ISR
__T1Interrupt:
BCLR IFS0, #T1IF ; Reset Timer1 interrupt flag
; User code goes here.
RETFIE ; Return from ISR