1869Views8Replies

Author Options:

How can I mix colors in a rgb-led with only 2 PWM channels? (using atTiny13)? Answered

hi all,

I would like to mix colors in rgb-led. If done that before with the atmega8 and that worked great (because it hs a lot of PWM channels). Now i want to do the same with an Attiny13 because I only have about 20mm x 20mm (less that a square inch) place to fit the elecronics.

I can mix up 2 colors because the Attiny13 has 2 PWM channels but has someone a solution to add the 3th color. Keep also in mind that I only have 1kbytes of flash and that i need a big chunk of that for the effects.

Thanks for thinking along with me.

8 Replies

user
JsmxboxBest Answer (author)2012-03-14

you can do Pulse Width Modulated in software like this here

http://blog.kevinmehall.net/2007/rgb-led-rainbow-fader

Select as Best AnswerUndo Best Answer

user
janw (author)Jsmxbox2012-03-15

Thanks for your answer! The question is already 2 years old so I already found out how to do it with the timers. but thanks anyway.

Select as Best AnswerUndo Best Answer

user
lent13_7 (author)janw2013-10-16

Hi
im having the same problem you had 3 years ago haha, please if you have de answer could you send it to me, my email is lent13_7@hotmail.com

Select as Best AnswerUndo Best Answer

user
frollard (author)2010-02-11

Hardware pwm is ideal, but you can fake it with a program loop - or use an interrupt to drive an ISR function that decides what the comparator value is...
x is an unsigned byte...
isr >  
x=x+1
it will loop automatically from 255 to zero.

in your main program loop that does the animations, simply bit bang the output pins comparing to the constantly looping x value.  if greater than x turn the led on..

Select as Best AnswerUndo Best Answer

user
MahavishnuMan (author)2010-01-25

I'll think out loud for a second, and maybe in my jabber an answer will pop out for you.

My initial impulse was to suggest using a method similar to how component video is produced.  In component video, you have Y, Pb, and Pr channels - but in actuality, they're not strictly green, blue, and red.  The Y channel is actually luma, or white intensity; Pb is a the difference between blue and luma and Pr is the difference between red and luma.  If both Pb and Pr cancel out, then only green is left.

This approach would only work if, at any given moment, some part of the LED were lit.

If your effects require the LED to dim completely off, then the only thing I can think to do is use some creative duty-cycle manipulation with an external logic gate (like XOR).  Perhaps it's not practical with the space limitations (although they still tend to be rather small), but it's a thought; for that matter, you could even cheat the first method this way.

I'll readily admit that I am not familiar with the Attiny (I know, I'm a horrible Instructable member for this) but if it is capable of tri-stating you can open up a whole myriad of possibilities using this information.

Select as Best AnswerUndo Best Answer

user

I suddenly realized XOR probably is not anywhere near the logic gate you'd want.

Select as Best AnswerUndo Best Answer

user
guyfrom7up (author)2010-01-24

I'm getting into using avr's more often, and this may work or it may just be a misunderstanding :P

Set one of the timers in ctc mode, and then use the main cpu (or whatever you want to call it) to break up that signal to drive 3 normal i/o pins

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)2010-01-24