


The CCPR1L contains the eight MSbs and the CCP1CON contains the two LSbs. The PWM duty cycle is specified by writing to the CCPR1L register and to the CCP1CON bits (Up to 10-bit resolution). You can see the below image of CCPxCON, where bit0 to bit3 is used to select the PWM mode, and bit4 and bit5 used to store the two LSbs bit of duty cycle. The CCP1CON register controls the operation of CCP1 and The CCP2CON register controls the operation of CCP2. PIC16F87XA has two registers CCP1CON and CCP2CON. The free-running counter will be compared with CCPR1L and PR2 for generating the PWM output. This register holds the 8-MSB bits of PWM, lower 2-bits will be part of the CCPxCON register which I have already described in the above table. This register is used to Configure the CCP module for Capture/Compare/PWM operation and store 2 LSBs of the duty cycle. The below table shows the registers associated with PIC16F877A PWM. Note: The timer resource for PWM in PIC16F877A is Timer2.īefore using the PWM, I want to introduce some registers which will be used in the PWM configuration. Each Capture/Compare/PWM (CCP) module contains a 16-bit register which can operate as a: Here, I am referring to PIC16F877A that has 2 CCP modules, named CCP1 and CCP2.

Most of them have more than one CCP module. CCP modules are available with a number of PIC Microcontrollers. The PIC Microcontroller has an inbuilt CCP module and PWM can be easily generated using the inbuilt CCP module. We can also define the duty cycle using the below formula,ĭuty cycle = ( ON/ (ON + OFF) ) x 100 percentage The period can easily be calculated by using the formula:įor example, if the frequency is 1 kHz, the period will be 1 millisecond. 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. That pulse width relative to the period of the signal is called the duty cycle. The amount of time the signal remains high is typically called the pulse width. 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. PWM is a way to use a digital output to vary the on, or high time, to create a variable output or square wave. I have also written a blog post on how to control the dc motor with PIC MCU using the PWM, if you want you can read. The main aim of this blog post to describe how we can use the inbuilt PWM of the PIC microcontroller. Also, the user can configure the duty cycle (“ON” time) that can be used to encode a message or control the amount of power supplied to electrical devices. The PWM peripheral is used to generate a digital signal with a user-defined period. In PIC MCU the PWM is a common peripheral and some version of PIC MCU has more than on the PWM module.
