Continue to Site

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.

  • 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.

pwm code for dimming lights

Status
Not open for further replies.

sthii

New Member
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....
 
Hi, is your problem setting up the pwm module, or getting the pwm value to dump in ccpr1?
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top