3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

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

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.

7 answers
sort by: active | newest | oldest
Mar 14, 2012. 12:59 PMJsmxbox says:
you can do Pulse Width Modulated in software like this here

http://blog.kevinmehall.net/2007/rgb-led-rainbow-fader
Feb 11, 2010. 2:09 PMfrollard says:
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..
Jan 25, 2010. 6:20 PMMahavishnuMan says:
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.
Jan 25, 2010. 6:56 PMMahavishnuMan says:
I suddenly realized XOR probably is not anywhere near the logic gate you'd want.
Jan 24, 2010. 2:36 PMguyfrom7up says:
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
Jan 24, 2010. 1:50 PMsteveastrouk says:
High speed multiplex ? 

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!