Microchip logo
  • All
  • Products
  • Documents
  • Applications Notes
×

8-Bit MCUs

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.   

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?

PWM Peripherals in PIC MCUs
+

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.

Capture/Compare PWM Module in PIC MCUs
+

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.



How Are PWMs in AVR MCUs Used?

PWMs in AVR MCUs
+

The PWMs in AVR MCUs are integrated in the Timer/Counter peripherals as a function or mode.Two kinds of PWMs are commonly used:

  • 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

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.

Pulse-Width Modulation Block Diagram