PIC32 Timer Overview
timer.png

The PIC32 has two kinds of timers:

  • Timer1 supports the following functions:
    • 16-bit mode
    • Synchronous Internal Timer
    • Synchronous Internal Gated Timer
    • Synchronous External Timer
    • Asynchronous External Timer
  • Timer2, Timer3, etc… support the following functions:
    • 16-bit and 32-bit modes
    • Synchronous Internal Timer
    • Synchronous Internal Gated Timer
    • Synchronous External Timer

Timer1

All timers can run when the Central Processing Unit (CPU) is in idle mode, but only Timer1's asynchronous external clock mode enables it to run while the CPU is in sleep. This, combined with its ability to be driven by a secondary oscillator, allows the timer to function as a real-time clock (RTC).

Timer2, 3, 4, etc…

Each timer has its own 16-bit counter and period registers. A 32-bit timer can be created by combining two timers (e.g. Timer2 & Timer3). In this case, the 32-bit timer is controlled by the even number timer control registers (e.g. Timer2). When an interrupt event occurs, the odd number timer generates the event (e.g. Timer3).

Timer Operation (non-gate mode)

timer_period.png

When a timer is not in gate mode, it will generate an interrupt event when the value in the counter matches the value in the period register. When this match occurs, the counter is reset to zero, and the timer starts counting again. Note that if interrupts are disabled, the timer interrupt flag, TxIF, will still be set.

Timer Operation (gate mode)

You can use the timer's gate feature to accurately measure the time for an external event. When the timers are in gate mode, the counters (driven by an internal clock) only increment when the TxCK pin is high. When this pin goes low, the timer stops incrementing and the timer interrupt flag, TxIF, is set. Note that in this mode, an interrupt event is not generated when the timer value matches the period register.

Detailed Overview

For more detail on the Timer modules for a specific PIC32 device, please view the family reference manual chapter for that device, for example:

20th Annual
Microchip MASTERs Conference 2016
Register now - Deadline: July 29

JW Marriott Desert Ridge Resort-Phoenix, AZ

© 2016 Microchip Technology, Inc.
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.