Bi-Color LED ATtiny PWM

Hi,
I was project, and instead of having an LED going on and off to indicate certain status, i wanted to use a Bi-Color LED which i power from an LM317 providing me with 1.8v which gives me about the same brightness for the Green & Red if i toggle the Input between 0v & 5v. So far so good, but since i also wanted it to be 'Off' at times, i decided to just simply use

analogWrite(PWM_PIN, 92); // 1.8 * 255 / 5 = 92

And at first i could quite work out what was going on, the LED was lighting up ! and since it was actually supposed to be in the 'Off' state, i got rather confused.. Until i realized that it was lighting up both colors partially. Now i was a little hesitant but figured i should be able to just a capacitor.
My hesitation was that i didn't want to burn the Output pin of the ATtiny, since there would be no current limiter anywhere. I started with a small one (10nF) , tried a few possible connection points, and in the end it was a 100uF Cap between GND & the PWM pin. And that actually works, i can turn the LED 'Off' but i am still wondering (and a little worried i suppose) about the mathematical side of things, so maybe someone can enlighten me on the matter.
Bi-Color LED ATtiny.JPG

Bi-Color LED ATtiny.JPG

Cute symbol for the LED but an extremely foolish approach in all respects. You are grossly overloading the microcontroller and I would be surprised if the chip is not getting very hot! :astonished:

If you want to turn the LED off, you simply set the pin to INPUT. :roll_eyes:

Paul__B:
Cute symbol for the LED but an extremely foolish approach in all respects.

That's what i figured as well.

Paul__B:
You are grossly overloading the microcontroller and I would be surprised if the chip is not getting very hot! :astonished:

well it isn't getting hot at all so be surprised

Paul__B:
If you want to turn the LED off, you simply set the pin to INPUT. :roll_eyes:

Now there is a good plan !! Thanx, i knew i was missing something.

Really that is just so much better !! saves a component (the Cap), and it saves me about 50 bytes !
Of course in the 'Microcore' Attiny13 core, PWM writing is independent of the pinMode, but now i don't need to use that.

Just as a final note, the 10R resistor in line with the LED is probably a tad small, something in the order of 50R is more appropriate.

Deva_Rishi:
Just as a final note, the 10R resistor in line with the LED is probably a tad small, something in the order of 50R is more appropriate.

That is actually why I said "in all respects". It looks rather inappropriate. :roll_eyes:

However given that the high-side driver internal resistance is about 36 Ohms and the low-side driver about 50 Ohms but increases substantially with temperature, (datasheet Figures 19-19 and 19-22), you might just as well leave it at 10 Ohms or leave it out entirely! :astonished:

you might just as well leave it at 10 Ohms or leave it out entirely!

Well there is also that the voltage-drop of the LED is quite high, at 2.1v & 2.3v, it's just having used those LED's in another project (on a Pro-mini) i had decided on 50R. (that project always had them on either red or green)

Well with the LM317 set to 1.8 V, it will give - 1.8 V - to the red LED and 3.2 V to the green LED, limited by the resistor and the internal resistance of the ATmega chip.

Actually, it's not quite like that!
Bi-Color LED ATtiny.JPG
When you pull the output HIGH, the LM317 sees its output voltage pulled up so it actually switches off. I am not sure of the exact situation, but I do not think it will actually pull its output down and indeed, the resistors prevent it doing so. So the green current is actually controlled only by the 1k and 470 Ohm resistors.

So the brightness of the green LED is limited by (all) the resistors, and the brightness of the red LED is limited by being fed at barely above its threshold - about 1.7 V presumably. It really is a wonky circuit, easier/ more reliable just to use two output pins!

And I just noticed in your OP,

Deva_Rishi:
My hesitation was that i didn't want to burn the Output pin of the ATtiny, since there would be no current limiter anywhere.

Which really is funny, as that is exactly what the 100 µF capacitor would do. Oh well ... :grinning:

It really is a wonky circuit, easier/ more reliable just to use two output pins!

or maybe just 2 resistors, and leave the lm317 out ? 2 output pins is hardly an option, that they seem available in the diagram doesn't mee they are, PB0 is used as a PWM, and i am using the other 3 as Analog inputs measuring voltages, since i do need full resolution i figure it would be easier to leave the reset pin as it is, but yes good point.

Which really is funny, as that is exactly what the 100 µF capacitor would do.

i figured current would flow when the pin is HIGH charging the capacitor until it is full ? (exponentially decreasing) and in the opposite direction when the pin is LOW, Leveling out at the % of voltage of the duty cycle. That it is only happening for a short amount of time just didn't seem the same as not happening at all.

the LM317 sees its output voltage pulled up so it actually switches off

An LM317 is actually great like that, if you do that to a 7805 it breaks.