8-Bit CCP Pulse Width Modulation

Pulse Width Modulation (PWM) is a common peripheral on almost every PIC® MCU Device. PWM is a way to use a digital output to vary the on, or high time, to create a variable output or square wave (see Figure below). If the PWM signal runs at a fixed frequency, then changing the high time of the signal will also change the low time of the signal. The amount of time the signal is high is typically called the pulse width. That pulse width relative to the period of the signal is called the duty cycle. The period of the signal, is defined as the time from one rising edge to the next rising edge of the square wave signal and is inversely proportional to the PWM frequency.

The period can easily be calculated by using the formula:

\begin{equation} Period = 1/Frequency \end{equation}

For example, a 1 kHz frequency will give us a 1 millisecond period.

Using PWM gets very interesting because there are many applications for it. Simplest of all is driving some kind of low-pass filter. By driving a simple resistor-capacitor (RC) low-pass filter circuit (see Figure below) directly from the microcontroller’s PWM port, the variable pulse width will be averaged out by the capacitor’s charge and discharge rate through the resistor. With enough filtering the digital PWM signal can be converted in to an analog voltage and used as a low cost digital to analog (D/A) converter.


For more information on Pulse Width Modulation (PWM) options visit the Pulse Width Module article.

20th Annual
Microchip MASTERs Conference 2016
Register now - Deadline: July 29

JW Marriott Desert Ridge Resort-Phoenix, AZ

© 2016 Microchip Technology, Inc.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.