25.4.8 Asynchronous External Clock Counter Initialization Steps
The following steps must be performed to configure the timer for 32-bit Asynchronous Counter mode:
- Clear the TON Control bit (TxCON[15] =
0
) to disable the timer. - Set the TCS bit (TxCON[1] =
1
) to enable external clock selection. - Clear the TSYNC Control bit (TxCON[2] =
0
) to disable clock synchronization. - Select the desired prescaler.
- Load/clear the Timer register, TMRx.
- If using period match, load the Timer Period register, PRx, with the desired 32-bit match value.
- If interrupts are used:
- Clear the TxIF Interrupt Flag bit in the IFSx register.
- Configure the interrupt priority levels in the IPCx register.
- Set the TxIE Interrupt Enable bit in the IECx register.
- Set the TON Control bit (TxCON[15] = 1) to enable the timer.
32-bit Asynchronous Counter Mode Code
/* 32-bit Asynchronous Counter Mode Example */
T1CON = 0x0; // Stops the Timer and resets the control register
TMR1 = 0x0; // Clear timer register
T1CON = 0x00000102; // Set prescaler 1:1, external clock,asynchronous mode
PR1 = 0xFFFFFFFF; // Load period register
T1CONbits.ON = 1; // Start timer