23.4.2.2 Synchronous External Counter Initialization Steps

The following steps must be performed to configure the timer for Synchronous Counter mode:

  1. Clear the TON Control bit (T1CON[15] = 0) to disable the timer.
  2. If available on the device, set the External Clock source using the TCS bit.
  3. Set the TCS Control bit (T1CON[1] = 1) to enable the clock selection.
  4. Set the TSYNC Control bit (T1CON[2] = 1) to enable clock synchronization.
  5. Select the desired timer input clock prescale.
  6. Load/clear the Timer1 register, TMR1.
  7. If using period match:
    1. Load the Timer1 Period register, PR1, with the desired 32-bit match value.
  8. If interrupts are used:
    1. Clear the T1IF Interrupt Flag bit in the IFSx register.
    2. Configure the Interrupt Priority Levels in the IPC1 register.
    3. Set the T1IE Interrupt Enable bit in the IEC1 register.
  9. 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