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:

(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 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.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 1, "x-ck12": 0, "texerror": 0, "math_score": 0.6798206567764282, "perplexity": 777.3436175680171}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2019-26/segments/1560627998291.9/warc/CC-MAIN-20190616182800-20190616204800-00281.warc.gz"}