Timer2 Operation

Timer2 is driven by the internal instruction clock (FOSC/4). The Timer2 (TMR2) register increments on each clock edge. A prescaler on the clock input allows direct input (1:1), divide-by-4, divide-by-16 and on some devices divide-by-64 prescale options. These options are selected by the prescaler control bits: T2CKPS of the Timer2 Control (T2CON) register. The value of TMR2 is compared to that of the Period (PR2) register on each clock cycle. When the two values match, the comparator generates a match signal as the timer output for other peripherals to use as a time base. A Timer2 interrupt can also be triggered by the match. The match signal becomes the input to an optional postscaler and also resets the value of TMR2 to 00h on the next cycle.

t2con.png

The TMR2 and PR2 registers are both directly readable and writable. The TMR2 register is cleared on any device reset, whereas the PR2 register initializes to FFh. Both the prescaler and postscaler counters are cleared on the following events:

  • a write to the TMR2 register
  • a write to the T2CON register
  • Power-on Reset (POR)
  • Brown-out Reset (BOR)
  • MCLR Reset
  • Watchdog Timer (WDT) Reset
  • Stack Overflow Reset
  • Stack Underflow Reset
  • RESET Instruction

Timer2 can be turned on and off via the TMR2ON bit of the T2CON register.

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.