There are two CCP modules present in PIC16F877A CCP1 and CCP2 at pins RC2 and RC1 respectively. To generate PWM with the help of a PIC16F877A microcontroller, built-in CCP modules are used. First let’s begin with MikroC for PIC compiler. As mentioned earlier, we will discuss an example with two compilers, namely, MPLAB XC8 and MikroC Pro.
Now let’s start understanding how to generate different frequency and duty cycle digital signals using PIC16F877A microcontroller.Īlthough, we use PIC16F877A in this post, but you can easily apply the same concepts and examples to other PIC microcontrollers also. Now you know the basics of pulse width modulation and you also know its related terminology. Before using PWM module of Pic microcontroller, we should define the frequency/timer period of the signal. For example, a frequency of 1000Hz would mean 1000 cycles completed per second. The frequency determines the amount of time taken by PWM to complete one cycle. Similarly, if a signal stays high for a longer period of time than it stays low, the signal will have a duty cycle greater than 50%. For example, if a digital signal is on for half of the time duration and off for the other half, the digital signal is said to have a duty cycle of 50%. An on-time is the duration of a signal for which the signal stays HIGH. There are two major components of a PWM signal that defines its behavior PWM duty cycle, time period and frequency. PWM (Pulse Width Modulation) is a powerful technique used to control analog circuits with the digital output from the microcontroller.
Variable Duty Cycle PWM using PIC Microcontroller.Generate Fix Duty Cycle PWM using PIC16F877A.