hi guys. im using pic16f877 and struggling with a code to create PWM that can change its duty cycle depending on the number of interrupts that has occured e.g if the interrupt is triggered 2 time then set duty cycle to 40% and if triggered 4 time set it to 60 %
If you are using the full 10 bits then your CCPR1L is 0xFF = 100%.. 0x7F = 50% etc....
So forget about the two bits in the CCP1CON and use this... ( MAX DUTY * Percent required ) / 100.... Assume you want 75% so (255 * 75) / 100 = 191 if you load CCPR1L with 0xBF you'll get 75%
All you need to do now is get your interrupt counter to count in percent... ie.. 10%, 20% etc....