

That is 0-1024 will be converted to 0%-100% Duty cycle. Then we generate a PWM signal with frequency 5000Hz and vary its duty cycle based on the input Analog voltage. In our program we will read an Analog voltage of 0-5v from a potentiometer and map it to 0-1024 using our ADC module. The following registers are used to generate PWM signals using our PIC MCU: There are two CCP modules in our PIC MCU (CCP1 And CCP2), this means we can generate two PWM signals on two different pins (pin 17 and 16) simultaneously, in our tutorial we are using CCP1 to generate PWM signals on pin 17. The resolution of our PWM signal is 10-bit, that is for a value of 0 there will be a duty cycle of 0% and for a value of 1024 (2^10) there be a duty cycle of 100%. PWM signals can be generated in our PIC Microcontroller by using the CCP (Compare Capture PWM) module. In our tutorial we will set a frequency of 5KHz. One Period is complete ON and OFF of a PWM signal as shown in the above figure. The frequency of a PWM signal determines how fast a PWM completes one period. If the signal is always ON it is in 100% duty cycle and if it is always off it is 0% duty cycle.ĭuty Cycle =Turn ON time/ (Turn ON time + Turn OFF time) The percentage of time in which the PWM signal remains HIGH (on time) is called as duty cycle. There are two important parameters for a PWM as discussed below:

The time during which the signal stays high is called the “on time” and the time during which the signal stays low is called the “off time”. This signal is set high (5v) and low (0v) in a predefined time and speed. Pulse Width Modulation (PWM) is a digital signal which is most commonly used in control circuitry.
