Introduction
Author: Catalin Visan, Microchip Technology Inc. |
The AVR® microcontrollers are equipped with powerful timers designed to cover a wide area of applications, from signals measurement to events synchronization and waveforms generation.
The Timer/Counter type A (TCA) is a 16-bit timer that is present in the tinyAVR® 0-series, tinyAVR® 1-series, megaAVR® 0-series, and AVR® DA devices. The main idea behind the TCA is that a very flexible timer is needed to perform convoluted actions as well as the very basic functions of a simple timer. The flexibility comes from the multitude of features provided, such as the possibility of splitting the 16-bit timer into two completely independent 8-bit timers or the built-in Wave Generation modes. Another important characteristic is that the TCA was devised to overcome common problems when using timers, such as the unpredictable behavior of the PWM signal when the duty cycle is changed while the timer is running. The TCA has double-buffered registers that synchronize the updates of different registers, making the waveforms generated predictable in every single situation.
The purpose of this technical brief is to familiarize the reader with some of the operating modes of the TCA, emphasizing this timer’s particularities and to provide initialization code snippets. For a deeper understanding of the functionality, please consult the data sheet. The structure of the document covers three specific use cases:
- Using
Periodic Interrupt Mode:
Initialize the timer to trigger an interrupt every 250 ms, toggling an example GPIO in the Interrupt Service Routine
- Generating a
Dual-Slope PWM Signal:
Initialize the timer to generate a dual-slope 16-bit PWM signal with 1 kHz frequency and 50% duty cycle on a GPIO pin
- Generating
Two PWM Signals in Split Mode:
Initialize the timer in Split mode to generate two single-slope 8-bit PWM signals on two GPIO pins, with independent duty cycle and frequency