Datasheet

ADuC7033
Rev. B | Page 76 of 140
Starting Timer2
When starting Timer2, it is recommended to first load Timer2
with the required TxLD value. Next, start the timer by setting
the T2CON bits as required. This enables the timer but only
once the T2CON bits have been latched internally in the
Timer2 clock domain. Therefore, it is advised that a delay of
more than three clock periods (that is, 100 µs for a 32 kHz timer
clock source) is inserted to allow both the T2LD value and the
T2CON value to be latched through the synchronization logic
and reach the Timer2 domain.
After the delay, it is recommended that any (inadvertent)
Timer2 interrupts are now cleared using T2CLRI = 0x00.
Finally, the Timer2 system interrupt can be unmasked by
setting the appropriate bit in the IRQEN MMR. An example
of this code follows (where it is assumed that Timer2 is halted).
Example Code
T2LD = 0x1; //Reload timer
T2CON = 0x02CF; //Enable T2, low power oscillator, 32768 prescaler
Delay(100us); //Include delay to ensure T2CON bits take effect
T2CLRI = 0 ; //*ClearTimerIrq
IRQEN = WAKEUP_TIMER_BIT; //Unmask Timer2