We detect you are using an unsupported browser. For the best experience, please visit the site using Chrome, Firefox, Safari, or Edge. X
Maximize Your Experience: Reap the Personalized Advantages by Completing Your Profile to Its Fullest! Update Here
Stay in the loop with the latest from Microchip! Update your profile while you are at it. Update Here
Complete your profile to access more resources.Update Here!
Item Qty
Your cart is empty.

Why Use a Timer Peripheral?


The most common use of a timer peripheral is to trigger a specific action after a certain amount of time or clock cycles. Timer peripherals can be used to enhance your microcontroller (MCU) design in several ways:

  • Implementing timer functionality as a hardware peripheral ensures accuracy and reduces load on the CPU: although timing and counting is possible with software, this often causes inaccuracies due to latency and consumes valuable CPU instruction cycles.
  • A timer peripheral can also be used to generate waveforms, such as Pulse-Width Modulation (PWM) signals: this enables control over various output functions and is recommended for applications like controlling servo position or the brightness of an LED.

We provide a multitude of PIC® and AVR® MCUs, and each MCU is loaded with a variety of timer peripherals. Every timer has specific capabilities and functionalities that makes it unique and well suited for different applications. Click on the sections below to learn more about the specific features of each timer.

How Do Timers in PIC MCUs Operate?


Universal Timer (UTMR)


The Universal Timer (UTMR) peripheral combines most of the operations of the legacy timers (TMR0/1/2, HLT, SMT, CCP) into a single timer. This means useful features such as periodic operation mode, clock gating, pulse width measurement and switch debouncing are combined into one feature-rich module.

Chained Operation Mode

Multiple UTMR modules can be chained together to form larger-sized timers, providing system design flexibility.

Timer 0


Timer 0 is the simplest timer available for PIC devices.  It can operate as either a 16-bit or 8-bit timer or counter. This peripheral can operate in low-power sleep modes provided that the internal or external clock source remains active. It also has a programmable prescaler, postscaler and period and can operate in a variety of modes.

Timer Mode

In timer mode, a timer variable will increment on every instruction cycle as long as there is a valid clock input signal.  This mode can operate both synchronously and asynchronously with an external clock signal.  Timer mode can also perform in lower-power sleep modes only if operating asynchronously from the system clock.

Counter Mode

In counter mode, the clock input the counter increments by one on each rising edge. This mode can operate both synchronously and asynchronously as well.  However, just like the timer mode, this mode can only operate if working asynchronously from the system clock.

Timers with Gate Control


Timer 1,3,5… (odd-numbered timers) all behave in the same manner. This enables a device to control multiple timer peripherals with different operating behaviors if desired. These timers can operate as 16-bit timers or counters, and they have programmable prescalers. They can also operate in low-power sleep modes provided that the internal or external clock source remains active. The odd-numbered timers are unique in their ability to enable and disable gate modes, which allows you to set your timer or counter to only increment under certain conditions based on the required Gate Signal Source.

Gate Enable Mode

When Gate Enable mode is active, the timer will begin incrementing on the rising edge of the gate input source.  It will increment on every rising edge of the timer’s clock source. On the falling edge of the timer’s gate input source, the timer will stop incrementing.

Gate Toggle Mode

When Toggle Mode is enabled, the duration between each toggling of the gate input signal can be measured. The timer will begin incrementing on the rising edge of the Gate Signal Source. It will continue to increment until the next rising edge of the gate signal source occurs.  You can use this to read the entire toggle period of your Gate Signal Source.

Gate Single Pulse Mode

When Single Pulse Mode is enabled, the timer counter will begin incrementing on the rising edge of the incoming Gate Signal Source.  The timer will continue to increment until the falling edge of the Gate Signal Source occurs. This enables you to read the duration of the high pulse of the incoming Gate Signal Source.

Gate Toggle and Single Pulse Mode Combination

These two operating modes can be used simultaneously. This allows both the high pulse duration and the period to be obtained at the same time, which can be converted into duty cycle if so desired.

Timer 2/4/6 with Hardware Limit Timer


Timer 2,4,6… (even-numbered timers) are duplicates of one another. The even-number timer peripherals are 8-bit timers with the ability to be reset by an external hardware source or an internal timer period match. These timers cannot operate in lower-power sleep modes. The even-numbered timers compare a predefined period value to an incrementing timer counter. When the two values match an output postscaler counter is incremented and a subsequent action can be triggered. This timer also features multiple operating modes.

Free Running Mode

In Free Running Mode, the timer counter is reset each time a period match occurs. As long as the timer is enabled, it will continue to increment until a period match occurs and it resets. An external hardware signal can reset the timer before a period match occurs if desired.

One Shot Mode

In One Shot Mode, the timer value increments until a period match occurs, after which the timer will stop and remain halted until it is restarted.  An external hardware signal can be used to reset the timer.

Monostable Mode

In Monostable Mode, the timer value increments until a period match occurs, after which the timer is stopped but is not disabled. An external hardware signal can be used to reset the timer.

Signal Measurement Timer


The signal measurement timer can be found on newer PIC devices and can be used for measuring different signal parameters such as pulse width, frequency, duty cycle and the time difference between edges on two signals. It can work as a 16-bit or 24-bit timer, and it has a combination of attributes and operating modes that are present on other PIC MCU timers.

Timer Mode

In Timer Mode On, the signal measurement timer works similarly to Timer Mode on Timer0. As long as there is a valid clock input signal, a timer variable will increment on every instruction cycle.

Gated Timer Mode

In Gated Timer Mode, the timer will only increment while the incoming Gate Signal is high. When it is low, the timer will stop incrementing. As a result, the signal measurement timer will only increment under specific conditions.

Period and Duty Cycle Mode

In Period and Duty Cycle Mode, either the duty cycle or period of the incoming signal to the Signal Measurement Timer can be acquired. They cannot both be measured simultaneously.

High and Low Measurement Mode

In High and Low Measurement Mode, the high and low pulse time of the incoming signal can be acquired.

Gated Windowed Measurement Mode

In Gated Windowed Measurement Mode, the duty cycle of the Signal Measurement Timer signal input over a user-defined window or period can be acquired.

Time of Flight Mode

Time of Flight Mode measures the time between the rising edge of the Signal Measurement Timer signal input and the rising edge of the Signal Measurement Timer window input.

Capture Mode

In Capture Mode, the value of the timer is captured based on the rising or falling edge of the Signal Measurement Window input and triggers an interrupt.

Gated Counter Mode

Gated Counter Mode counts pulses on the SMT input signal which is gated by the SMT window input.  The timer only increments after the rising edge of the SMT window input. It stops counting on the falling edge.

Windowed Counter Mode

Windowed Counter Mode counts the amount pulses of an input signal and the duration of the signal’s high pulse within a defined window. To measure the duration of the high pulse, the SMT begins counting on the rising edge of an input signal and stops counting on the falling edge. To count the number of pulses of an input signal, a counter value is incremented on each rising edge of the windowed signal. 

How Do Timers in AVR MCUs Operate?


Timers on AVR MCUs are designed a little differently than the timers on PIC MCUs. The biggest difference is that the timers on AVR MCUs are integrated with waveform output modules like the Pulse-Width Modulation (PWM) and Complimentary Waveform Generator (CWG), while PIC MCUs have separate peripherals for these functions.

Basic Timers (Timer/Counter 0, 1, 2…)


Timer/Counter 0, 1, 2, etc., on AVR devices are basic timers. Not only do they perform as a basic timer or counter, they also have some intelligent features.  

PWM Output

The basic timers can directly output a PWM signal with variable duty cycles and period. Fast PWM mode is used for generating high-frequency PWM, while Phase and Frequency Correct PWM is used for generating high-resolution PWM.

Output Compare

The timer compares a user-defined value with the counter value in the timer. When the timer is running, the counter value will keep increasing until it meets the user-defined value. The timer counter is then automatically cleared, or an interrupt can be generated to notify the user. This feature can be used when you need to trigger or output an event at a specific time.

Dead Time Insertion and Swap

The Dead-Time Insertion (DTI) unit generates OFF time where the non-inverted Low Side (LS) and inverted High Side (HS) of the Waveform Output (WO) are both low. The DTI unit ensures that the LS and HS never switch simultaneously. 

Timer/Counter Type A


Timer/Counter Type A, or TCA, is available in most new AVR MCUs. It is a 16-bit timer that can perform basic timing/counting, output compare and different types of PWM waveform generation.

Output Compare

TCA has three compare channels and, similar to the basic timers, it performs the output compare function. You can load three different values into the three compare registers to trigger three events or interrupts as the timer counter increments. This allows you to trigger multiple events at different times.

Edge-Aligned/Center-Aligned PWM Output

There are two kinds of common PWMs: edge-aligned or center-aligned. The edge-aligned PWM is widely used because of its simple configuration and higher resolution. The center-aligned PWM is extremely helpful in reducing the harmonics in the output of applications like motor control or power supply. TCA has can generate a high-resolution PWM with either a Single-Slope Mode or a Dual-Slope Mode. The Single-Slope Mode generates a left-aligned PWM, which has the high state at the beginning of a PWM period. The Dual-Slope Mode generates a center-aligned (symmetric) PWM, which has the high state at the middle of a PWM period.

Split Mode

TCA has a Split Mode, which splits the timer/counter into two timers with half the resolution. These two timers can perform basic functions such as counting and timing, single-slope PWM output and generating interrupts.

Timer/Counter Type B


Timer/Counter Type B, or TCB, is available in most new AVR MCUs. It is a high-resolution timer that can perform basic timing/counting, input/event capture, waveform measurement and PWM waveform generation.

Input Capture

TCB can capture internal/external events, such as a rising edge of an external signal, and give them a timestamp indicating the time of occurrence. There is also an option to enable a noise canceler to improve noise immunity to the captured signal.

Frequency and Pulse-Width Measurement

The Input Capture module of TCB also contains frequency and pulse-width measurement modes. Three modes allow you to measure frequency, pulse width, or both at the same time. These modes allow you to measure a periodic signal coming from another device or source. For example, you can use these modes to determine the period and duty cycle of a PWM signal so it can be used as an input feedback for the control system.

Single-Shot Mode

This mode can be used to generate a pulse with a duration every time a rising or a falling edge occurs on the input event. The timer will start counting when it detects the first rising/falling edge and counts to a user-defined counter value. This feature is useful for generating a fixed duration of event/output based on either a periodic or a non-periodic input.

Timer/Counter Type D


Timer/Counter Type D, or TCD, is available in some new AVR MCUs. It is a 12-bit timer with some specific features for complex waveform generation. It also contains flexible input capture and compare modes. This timer is extremely useful for timing- or safety-critical applications that require fault detection and for driving the output for a power supply or a motor.

Multiple-Condition Input Capture for Flexible Waveform Output

TCD has two input channels with ten modes of capturing input. Based on the mode you select, different actions/waveforms can be generated when there is an input, such as shutting down the output waveform or giving a flag to the microcontroller to perform additional operations in software. Additional signal processing features, such as input signal blanking and filtering, can be applied to the modes.

Edge-Aligned/Center-Aligned PWM Output

Like TCA, TCD can also generate center-aligned PWM by using a Dual-Slope Mode. It is very useful for applications like power converters or motors. It can also generate edge-aligned PWMs with conditional timings based on the user-selected input capture mode.

Half-Bridge and Full-Bridge Output

TCD can also generate signals for full-bridge and half-bridge output. The complimentary signals and dead time are generated automatically. Full-bridge and half-bridge are commonly used in driving power supply and motors. This eliminates the need to configure the output using software, which reduces the overhead for the CPU. It also eliminates the need to add external hardware logic components, which reduces costs.

Timer/Counter Type E


TCE is a 16-bit timer with four compare channels that make it suitable for advanced waveform generation for power and motor drive applications. It also contains high-resolution function that increases the waveform generator resolution up to 8× (3 bits). TCE is tightly connected to the Waveform Extension (WEX) module that allows highly flexible dead-band insertion. 

Edge-Aligned/Center-Aligned PWM Output

Like TCA and TCD, TCE can also generate center-aligned PWM by using a Dual-Slope mode. It is very useful for applications like power converters or motors. 

Increase Waveform Generator Resolution

The Timer/Counter E includes a high-resolution option that can increase the duty cycle resolution by up to eight times the input clock.

Output Compare

TCE has four compare channels, and, similar to the basic timers, it performs the output compare function. You can load four different values into the four compare registers to trigger four events, or interrupts, as the timer counter increments. This allows you to trigger multiple events at different times.

Timer/Counter Type F


TCF is a 24-bit timer/counter with capabilities that include frequency and waveform generation. TCF consists of a base counter and control logic that can be set in different modes, each providing a unique functionality. The base counter is clocked by a selectable clock source with optional prescaling.

24-bit Operation

TCF is a 24-bit timer/counter that allows high-resolution and accurate frequency generation. The TCF core runs asynchronously with the peripheral clock and allows operation at a higher speed with the integrated PLL. 

Operation Modes

The TCF waveform generation modes are frequency generation, Numerically Controlled Oscillator (NCO) pulse frequency, NCO fixed duty cycle and 8-bit PWM modes. In the 8-bit PWM mode, the lowest 16 bits are used for two separate compare registers.

Multiple Clock Sources

TCF supports many clock sources, both internal and external. By using the integrated PLL, a clock signal of up to 80 MHz can be used to allow high speed and resolution in the generated waveform.

Waveform Extention Module


The WEX module provides extra functions to timer/counters in Waveform Generation (WG) modes. It generates complementary waveforms and controls dead-time and fault handling. It can also be used for pattern generation.

Fault Protection

The fault protection unit is connected to the Event System, which enables an event to trigger a Fault condition to set the WEX output to a defined state. The Event System ensures predictable and instant fault reactions to put the system in a safe state. 

Pattern Generator

The Pattern Generator mode can be used to produce a synchronized bit pattern across the pins that WEX connects to. These features are perfect for handling the commutation sequence in Brushless DC motors (BLDC) and stepper motor applications.

Input Capture

Some basic timers can capture internal/external events, such as a rising edge of an external signal, and give them a time stamp indicating the time of occurrence. The timestamps can then be used to calculate the features of the signal such as frequency or duty cycle. There is also an option to enable a noise canceler to improve noise immunity to the captured signal.

New/Popular 8-bit Microcontrollers with Timers


Documentation


Application Notes

Title
AVR130: Using the timers on tinyAVR and megaAVR devices Download
TB3283 - Using the Universal Timer (UTMR) Module as Legacy PIC16/PIC18 Timers Download
Using the Universal Timer (UTMR) Module Download
Getting Started with Timers/Counters on PIC18 Download
TB3361 - How to Select a Timer on AVR® Microcontrollers Download
TB3363 - How to Select a Timer on PIC® Microcontrollers Download
TB3341 - Getting Started with TimerCounter Type F (TCF) Download

Hardware Limit Timer Peripheral (HLT)

The Hardware Limit Timer (HLT) provides a timed hardware limit to be used in conjunction with asynchronous analog feedback applications, or to detect missed periodic events.