23.4.5.3 Asynchronous External Clock Counter Initialization Steps
The following steps must be performed to configure the timer for 32-bit Asynchronous Counter mode:
- Clear the ON bit (TxCON[15] =
0
) to disable the timer. - Set the TCS bit (TxCON[1] =
1
) to enable external clock selection from TxCK pin. - Clear the TSYNC Control bit (TxCON[2]
=
0
) to disable clock synchronization. - Select the desired prescaler.
- Load/clear the Timer register, TMRx.
- 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 IFS register.
- Configure the interrupt priority levels in the IPC register.
- Set the TxIE Interrupt Enable bit in the IEC register.
- Set the ON 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 Timer1 and resets the control register
TMR1 = 0x0; // Clear timer register
T1CON = 0x00000002; // Set prescaler 1:1, external clock, asynchronous mode
PR1 = 0xFFFFFFFF; // Load period register
T1CONbits.ON = 1; // Start timer