Introduction
Author: Teodor Lina Microchip Technology Inc. |
The AVR® EB family of microcontrollers uses powerful timers structured to cover several applications, from signal measurement to event synchronization and waveform generation. The Timer/Counter type E (TCE) is a 16-bit Timer/Counter peripheral that can generate up to four Pulse-Width Modulation (PWM) signals and has multiple waveform generation modes. The Waveform Extension (WEX) is a waveform extension peripheral that enhances the capabilities of the TCE. The TCE and WEX peripherals can generate up to eight PWM signals.
The capabilities of the 16-bit PWM TCE include accurate program execution timing, command execution, frequency and waveform generation. The TCE consists of a base counter and a set of compare channels. The base counter is used to count clock cycles and events or enable the events to count the clock cycles. The compare channels can be used with the base counter to perform a compare match control, frequency generation and pulse-width modulation.
The WEX enhances the capabilities of the 16-bit PWM TCE. This peripheral can produce complementary waveform output signals, generate a dead time between these signals, generate and manage Fault events, and override port outputs. The key feature is that the WEX overcomes common problems when using timers for applications such as motor control. With the dead time added, the signals are not overlapping, avoiding shoot-throughs caused by the transistor’s switching. WEX can also make Fault conditions, driving all the signals into a user-defined state, a significant feature in applications where safety is crucial. Every functionality from WEX occurs inside the hardware, making the waveforms generated predictable in every situation.
This technical brief familiarizes the reader with several operating modes for the TCE and WEX, emphasizing the timer’s particularities. For a better understanding of the functionality, refer to the data sheet.
The structure of the document covers three specific use cases:
- Generate Four PWM Signals
Using TCE Independently of WEX:
Initialize the TCE in Dual-Slope mode to generate four PWM signals with different duty cycles and scaling options.
- Generate a Pattern for
Eight Signals Using WEX:
Configure the WEX to generate a patterns succession of patterns for each output pin that toggles periodically.
- Generate Eight
Complementary Waveform Output Signals with Fault Detection Using TCE and
WEX:
Initialize the TCE in Single Slope mode and generate four PWM signals. Configure the WEX to split the four PWM signals into eight complementary signals with dead time. Each PWM signal has a different duty cycle, between 0% and 100%. During each compare register, interrupt duty cycle increments happen in the Interrupt Service Routines (ISRs). A Fault event is triggered every 250 μs, driving all the outputs to low ‘
0
’ logic. Then, the fault event is resolved, and the ordinary operation resumes. After that, the process repeats.
Bare metal code examples for AVR16EB32 with the same functionality as the ones described in this technical brief can be found here:
MCC Melody generated code examples for AVR16EB32 with the same functionality as the ones described in this technical brief can be found here: