PIC32 Timer Overview
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 mode. 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)
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: