Introduction
Author: Teodor Lina Microchip Technology Inc. |
The AVR® EB Family of microcontrollers uses powerful timers designed 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. Up to eight PWM signals can be generated using the TCE and WEX peripherals.
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 provide complementary waveform output signals and generate a dead-time between the complementary signals to generate and handle fault events and to override the port outputs. The most important feature is that the WEX was devised to overcome common problems when using timers for applications such as motor control. With the dead-time added, the signals are not overlapping and shoot-through caused by the transistor’s switching is avoided. WEX can also make Fault conditions, driving all the signals into a user defined state, an important 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, consult 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 PWM signals with dead time. Each PWM signal has a different duty cycle, between 0% and 100%. Duty cycle increments happen in ISR routines during each compare register interrupt. A fault is triggered every 250 μs, driving all the outputs to low
‘0’
logic. Then, the fault is cleared, and the ordinary operation is restored. 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: