23.4.2.2 Synchronous External Counter Initialization Steps
The following steps must be performed to configure the timer for Synchronous Counter mode:
- Clear the TON Control bit (T1CON[15]
=
0
) to disable the timer. - If available on the device, set the External Clock source using the TCS bit.
- Set the TCS Control bit (T1CON[1] =
1
) to enable the clock selection. - Set the TSYNC Control bit (T1CON[2] =
1
) to enable clock synchronization. - Select the desired timer input clock prescale.
- Load/clear the Timer1 register, TMR1.
- If using period match:
- Load the Timer1 Period register, PR1, with the desired 32-bit match value.
- If interrupts are used:
- Clear the T1IF Interrupt Flag bit in the IFSx register.
- Configure the Interrupt Priority Levels in the IPC1 register.
- Set the T1IE Interrupt Enable bit in the IEC1 register.
- Set the TON Control bit (T1CON[15] =
1
) to enable the timer.
Synchronous External Counter Example Code
T1CON = 0x0; // Stop timer and clear control register
T1CON = 0x00000006; // Set prescaler at 1:1, external clock source
TMR1 = 0x0; // Clear timer register
PR1 = 0xFFFFFFFF; // Load period register
T1CONbits.TON = 1; // Start timer