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 the 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:

(1)
$$Period = 1/Frequency$$

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 the 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 into 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 "10-Bit Pulse Width Modulation (PWM)" page.

© 2020 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
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.