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.

PIC with 3 pwm channel

Status
Not open for further replies.

johnson

New Member
I wanna buid a pic to control the led dimmer with RGB colors, is there any PIC have this feature(3 pwm channel), or is there any way to achieve this task?


thanks,

cheers :>
 
I know p16f877 has 2 PWM channels. And as the principal, these ccp will work at the same period.

If you intend to use 3 ccp with the same period, you can use only one ccp and use PWM interrupt to send 3 channel as well.


Get the minimum duty cycle of the three.

Set ccpr1l to this duty cycle.
bcf suitable pin
wait for next
bcf second nearest pin
wait
bcf third pin

as tmr clear
bsf 3 pins

continu the loop forever
 
Thanks, but what i need to do is changing the color of LED smmothly. For example, change red to green smoothly (RGB 100 to RGB 010), means red color has to diminish while Green color is raising. Any idea?



cheers:>
 
There are PICs with 3 PWM, but not in a user-friendly DIP package.

Use a faster PIC18 (40MHz) and just do it the hard way. As the speed gets above 100 hz, the flicker will only be apparent if it's moving across your field of view.

"Hard way" being that you:

unsigned int ctr;
RED_PIN=red_limit>0;
BLUE_PIN=blue_limit>0;
GREEN_PIN=green_limit>0;
for(ctr=0;ctr<1024;ctr++){
if(ctr>red_limit)
RED_PIN=0;
... green...
... blue ...
}

But when do you get to recalculate the color limits? There are several ways- interrupting this routine would occassionally cause color "glitches", but it probably wouldn't be noticed. This loop could also be a timer interrupt itself, but you'd either decrease the available resolution for each color or have to decrease the frequency you're doing the PWM at.
 
thanks man:> however i have settle it using software control(PIC basic ). if u want the code juz pm me:>



cheers
 
Just generate you PWM signal manually( by switching a pin off and on simulatiously by code). If you do find a PIC with 3 PWM outputs, you'll be wasting like 35 output pins for nothing.

Even a small 8-pin PIC would pull it off easy.

I find that in/decrements in 2% to 5% show up as smooth transitions.

EDIT: PICBasic has been known to be quite notorious at cooperating with the PWM registers, doing it manually would work quite easily with PICBasic.

2nd EDIT: Verified by me, so make your switch to ASM already.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top