Information
PIC18F46J11
DS80000435K-page 8 2009-2013 Microchip Technology Inc.
13. Module: Timer1/Timer3
When the timer is operated in Asyncronous
External Input mode, unexpected interrupt flag
generation may occur if an external clock edge
arrives too soon following a firmware write to
TMRxH:TMRxL register. An unexpected
interrupt flag may also occur when enabling the
module or switching from Synchronous to
Asynchronous mode.
Work around
This issue only applies when operating the timer
in Asynchronous mode. Whenever possible
operate the timer module in Synchronous mode
to avoid spurious timer interrupts.
Example 3 shows a method to suppress the
spurious interrupt flag if it occurs upon writing to
the timer.
EXAMPLE 3:
ASYNCHRONOUS TIMER MODE WORK AROUND TO AVOID SPURIOUS INTERRUPT
//Timer1 update procedure in asynchronous mode
T1CONbits.TMR1ON = 0; //Stop timer from incrementing
PIE1bits.TMR1IE = 0; //Temporarily disable Timer1 interrupt vectoring
TMR1H = 0x00; //Update timer value
TMR1L = 0x00;
T1CONbits.TMR1ON = 1; //Turn on timer
//Now wait at least two full T1CKI periods before re-enabling Timer1 interrupts.
//Depending upon clock edge timing relative to TMR1H/TMR1L firmware write operation,
//a spurious TMR1IF flag event may sometimes assert. If this happens, to suppress
//the actual interrupt vectoring, the TMR1IE bit should be kept clear until
//after the "window of opportunity" (for the spurious interrupt flag event has passed).
while(TMR1L < 0x02); //Wait for 2 timer increments more than the Updated Timer
//value (indicating more than 2 full T1CKI clock periods elapsed)
PIR1bits.TMR1IF = 0; //Clear TMR1IF flag, in case it was spuriously set
PIE1bits.TMR1IE = 1; //Now re-enable interrupt vectoring for timer 1
A2 A4
X
X