- PIC MCUs
- AVR MCUs
- 8051 MCUs
- Angular Timer
- Configurable Logic Cell
- Cyclic Redundancy Check
- Complementary Waveform Generator
- Direct Memory Access
- Event System
- High Endurance Flash
- Math Accelerator
- Numerically Controlled Oscillator
- Peripheral Pin Select
- Pulse-Width Modulation
- Temperature Indicator
- Timer Peripheral
- Windowed Watch Dog Timer
- Intelligent Analog
- Input and Output Features
- Core Independent
- Functional Safety
- PIC Hardware
- PIC Software
- AVR Hardware
- AVR Software
8-bit Development Tools
What Is Pulse-Width Modulation?
A Pulse-Width Modulation (PWM) peripheral is used to generate a digital signal with a user-defined period and duty cycle (“ON” time) that can be used to encode a message or control the amount of power supplied to electrical devices. This type of signal can be used in a variety of applications such as motor control, LED lighting and power supplies.
Depending on when the PWM signal is active high during each period, there are two common types of PWMs:
- The widely used edge-aligned PWM offers simple configuration, fast response and higher resolution
- The center-aligned PWM is extremely helpful in reducing the harmonics in the output of motor control, power supply and other applications
- Some select devices can even generate variable-aligned PWM, which serves applications that require higher flexibility
Why Use PWM Peripherals?
Although they are designed slightly differently for each architecture, the PWM peripherals available in PIC® and AVR® microcontrollers (MCUs) provide your system with a hardware-driven PWM generator that does not occupy any CPU resources at runtime. They also have built-in hardware to accommodate PWM-related tasks such as dead-band delay and auto shutdown. To generate complex waveform outputs, the PWM peripheral can be used with other on-chip peripherals, such as the Complementary Waveform Generator (CWG), Configurable Custom Logic (CCL) or Configurable Logic Cell (CLC). PWM peripherals can be easily configured with MPLAB® Code Configurator (MCC) for PIC MCUs and Atmel START for AVR MCUs.
How Are PWM Peripherals in PIC MCUs Used?
PIC microcontrollers offer a variety of stand-alone PWM peripherals ranging from 10–16 bits that are designed to integrate and interface with different peripherals like timers. The standard PWM peripheral generates a PWM signal with a modifiable period and duty cycle duty. A variety of clock sources can be used to operate the PWM, and it can be used in low-power sleep modes when an external clock source is being used.
The Capture/Compare PWM (CCP) module is an extremely versatile peripheral that offers multiple modes of operation. In PWM mode, it can operate as a PWM peripheral, and in capture mode it can measure PWM characteristics such as the edges of waveforms. In compare mode, it can also compare its internal timer values to user-defined values to trigger other peripherals or generate an interrupt.
Select 8-bit PIC MCUs offer a 16-bit PWM that uses an independent Timer source and can generate various output signals. This PWM peripheral is extremely useful for dynamic high-resolution lighting control and push-pull amplifiers.
The PWM module has a compare feature and multiple outputs. The outputs are grouped in slices with each slice having two outputs where both share the same PWM period and operating mode. Different slices can utilize different operating modes. There are six operating modes: Left Aligned, Right Aligned, Center Aligned, Variable Aligned, Pulsed Compare, Toggled Compare. The left and right aligned modes can also be operated in Push-Pull mode.
How Are PWMs in AVR MCUs Used?
The PWMs in AVR MCUs are integrated in the Timer/Counter peripherals as a function or mode. Visit the Timer Peripheral page to learn about the functions of each Timer/Counter peripheral in AVR MCUs.
Almost all Timer/Counter peripherals in AVR MCUs provide the function of generating edge-aligned PWMs. This can be referred to as fast PWM or single-slope PWM mode within the Timer/Counter peripheral. Some Timer peripherals, like Timer/Counter Type A (TCA), have a split mode, which can be used to split a 16-bit PWM into two 8-bit PWMs in case your design needs more PWM outputs.
Some Timer/Counter peripherals, like Timer/Counter Type A or Timer/Counter0, 1, 2… on ATmega devices, can generate center-aligned PWMs. This can be referred to as phase correct PWM or dual-slope PWM mode within the Timer/Counter peripheral.