Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
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....
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.