ATTINY based dimmer

Hello everyone!
I need to create some kind of LED controller/dimmer in a relatively small PCB (45mm x 20mm). On that space should be living attiny13 and a constant current adjustable DC-DC converter. The converter gives 9V, based on common input about 5V (+/-1V). The scheme is attached.
It seems to be working, but not exactly as I expected. So the problems are:

- 1st and foremost: Does the scheme logic looks like a working circuit or I need to dig into the most sophisticated solutions? :slight_smile:
- 2nd. LEDs on the right aren’t actually turning off completely. There is a leakage and I cannot figure out how to close transistor completely. The solution could be is somehow to rise the base voltage higher than MCU has on it’s pin when it’s high. But how to do that?

I am not good building a schematics yet. Could anyone be so kind giving me some hints?
Thanks ~

---------------------------------------------------- UPD:

Guess I should mention ATTINY logic:

  1. MCU reads rotary encoder values and adjust analog output at pin PB0 (0~5V).
  2. Same rotary encoder has a switch to enable / disable converter by using high/low output respectively at pin PB4

Wrong forum?

way5:

  1. MCU reads rotary encoder values and adjust analog output at pin PB0 (0~5V).

I take it you want to use PWM? There's no such thing as a DAC in an ATtiny.

Some serious issues with your schematic.

Those 10µF caps C2 and C3 on the base of the transistors have to go. Instead you have to use a current limiting resistor - 330-470Ω for each.

No current limiting resistor on in series with the LEDs. You'll burn your transistors this way.

Two different part numbers for the transistors, that's odd.

What is the purpose of R2 and D1? Get rid of them. 5V direct to the Vcc pin.

You miss a 100nF decoupling capacitor for the ATtiny.

C1 also doesn't seem to have any use.

No ISP header (or how do you plan to program the thing?)

The reset pin is kept floating. Should have a pull-up, maybe a switch to GND if you want to be able to reset it.

Redraw your schematic so Vcc is on top, GND is bottom. That alone makes it a lot more readable.

way5:
Wrong forum?

No, arduino.cc is not as busy as other electronic fora you may be familiar with. It's a good idea to give it 24 hours before bumping.

5V +/- 1V? You need better regulated 5V than that to run Arduino.

Me, I'd get a regulated 5V 1A PS and connect all 6 leds with resistors (know at least the color if not the Vf) to 5V on the + legs and to a common N-type FET on the - legs. The 5V also goes to the ATtiny VCC pin.

I have done similar with 12V 12-led disks.

@wvmarle, thank you for the information. Briefly on some points:

I take it you want to use PWM? There’s no such thing as a DAC in an ATtiny.

Yes, I am using PWM, achieving gradually changes in voltage on pin PB0.

Those 10µF caps C2 and C3 on the base of the transistors have to go. Instead you have to use a current limiting resistor - 330-470Ω for each.

Got it. By using capacitors I was planning to smooth the signal to prevent flickering of diodes.

No current limiting resistor on in series with the LEDs. You’ll burn your transistors this way.

Initially there were resistors between VCC (+9V) and LEDs, but because of the reliability of DC-DC converter is high I decided to cut them off. If it’s still necessary, I’ll add them back to scheme.

Two different part numbers for the transistors, that’s odd.

Indeed, there are two different transistors (P / N-type)

What is the purpose of R2 and D1? Get rid of them. 5V direct to the Vcc pin.

Because I can not rely to external power source and cannot change that as well, I decided to add voltage divider using R2-D1 joint. If that is not necessary, I will exclude them from circuit.

You miss a 100nF decoupling capacitor for the ATtiny.

Agreed, thanks

C1 also doesn’t seem to have any use.

Agreed

No ISP header (or how do you plan to program the thing?)
The reset pin is kept floating. Should have a pull-up, maybe a switch to GND if you want to be able to reset it.

The ISP header I decided to leave it for later, because there is a problem uploading firmware while the MCU is wired. My guess is that there should be some jumpers or a wiring trick to be able to isolate the ATTINY from the circuit while uploading. So, since we are touching the topic, any suggestions are welcome. :slight_smile:


ChrisTenone:
No, arduino.cc is not as busy as other electronic fora you may be familiar with. It’s a good idea to give it 24 hours before bumping.

Agreed.

@GoForSmoke, that is the lack of reliability of an external power source that I’ve mentioned above. So I wanted to use R2-D1 voltage regulator/divider. If that is a bad practice, I will remove them.


MCU is doing its job well, since I am able to dimm out the leds on one side meanwhile the leds on another size are turning high, and vise versa. I’m gonna take some time to redraw the schematics, re-wire all over again and calculate some values for resistors for debugging purposes.
Will be back in a short while.

Thanks to everyone~

--------------------------------------------- UPD:
@wvmarle schematic is attached, I hope that is close to a fine results now :). Please do criticize it, that helps a lot

way5:
Yes, I am using PWM, achieving gradually changes in voltage on pin PB0.

Do look up what PWM does. It's a block wave, not a constant voltage.

Got it. By using capacitors I was planning to smooth the signal to prevent flickering of diodes.

The PWM makes the LEDs flicker at 500 Hz. You can't see that.

Initially there were resistors between VCC (+9V) and LEDs, but because of the reliability of DC-DC converter is high I decided to cut them off. If it's still necessary, I'll add them back to scheme.

Then use the 9V to power the LEDs. Add a few more LEDs so you get to about 7V total forward voltage, add a resistor for the rest. Otherwise you're going to break stuff.

Indeed, there are two different transistors (P / N-type)

Doesn't make sense. At all. Same purpose, different type? Why? Both should be NPN of course.

Because I can not rely to external power source and cannot change that as well, I decided to add voltage divider using R2-D1 joint. If that is not necessary, I will exclude them from circuit.

A voltage divider is not a regulator. Get a proper regulator instead, or better, a properly regulated power supply. An old 5V phone charger is great for this purpose.

The ISP header I decided to leave it for later, because there is a problem uploading firmware while the MCU is wired. My guess is that there should be some jumpers or a wiring trick to be able to isolate the ATTINY from the circuit while uploading. So, since we are touching the topic, any suggestions are welcome. :slight_smile:

Understand how ISP works, know what you connect where, and you'll be fine. Without you can't program the ATtiny. Or you unplug it, stick it in a programmer, and put it back?

wvmarle:
Understand how ISP works, know what you connect where, and you'll be fine. Without you can't program the ATtiny. Or you unplug it, stick it in a programmer, and put it back?

Well, I shall do some experiments with uploading, because while I am not unplugging rotary encoder from breadboard, avrdude says there is no connection to the chip. I'll do re-wiring, there might be a weak connection or something.

Btw, schematic is attached above, I'd appreciate your opinion.
Thanks~

way5:
Indeed, there are two different transistors (P / N-type)

I guess what you are doing is dimming one bank of LEDs while complementary brightening the other. Always one bank or the other is "on" and you are shifting the duty cycle between them. Is that it?

gardner:
I guess what you are doing is dimming one bank of LEDs while complementary brightening the other. Always one bank or the other is "on" and you are shifting the duty cycle between them. Is that it?

Correct.

(https://forum.arduino.cc/index.php?msg=4154485)Quote from: wvmarle Mon Apr 29 2019 01:02:19 GMT-0500 (CDT)
The reset pin is kept floating. Should have a pull-up, maybe a switch to GND if you want to be able to reset it.

Back to the RESET pin. Earlier I wanted to use it as a digital pin for a purpose but knowing there would be only way to program MCU using high voltage, after disabling the reset pin, I decided to deal with the schematic first and polish some details. :slight_smile:
I think is reasonable.

way5:
LEDs on the right aren't actually turning off completely.

I think you'll need to move the PNP transistor to the +V (high) side of the LED string to get it to turn off completely.

I suggest a good small regulated 5V PS because you don't have to mount an unneeded converter on-board.

I have 12V 12-led G4 discs that get hotter than I like. I used 2 of them and 2 pins to make them each ON half the time and run cool though the result is twice the disks for the same amount of light... that survive a lot longer unless those are COB leds and nothing tells me that, also Robin2 had noted short lives (not remotely 50,000 hours) for such disks.

1 pin could make 2 sets of leds blink in complement if you connect it to 1 FET (they've gotten cheap enough to be worth it) and to a logic inverter that connects to the FET for the other set of leds. But you have a pin to spare and can bit-bang to not need that extra part in your design.

What color leds are you using? (didn't catch it) White leds have forward voltage around 3V. If you run 3 of those with 9V you will not be able to limit the current with any resistor that lets them turn on. They likely might not burn up but that's because they likely won't reach full brightness either.

If you know the forward voltage of your leds once they warm up you can match resistors to get the 25 or more mA they can take w/o damage, you can get the most out of PWM.

The MIT High-Low Tech site has a good page on programming Tiny45/85.

As vwmarle posted, don't try and level PWM voltage with caps because human eyes can't see 2ms flicker. We can't quite see 40ms or less flashes except as vision persistence that blends. Human eyes are fooled at 24FPS.

Another reason to not make PWM other than square wave is that FETs lose efficiency and get HOT when run between full open and full closed. If you think to dim the lights with FETs like a volume control, just don't.
You -can- use BJT's instead. They're just not so efficient as FETs used properly and the difference goes up with current used.

GoForSmoke:
Another reason to not make PWM other than square wave is that FETs lose efficiency and get HOT when run between full open and full closed. If you think to dim the lights with FETs like a volume control, just don't.
You -can- use BJT's instead. They're just not so efficient as FETs used properly and the difference goes up with current used.

Great point! Thanks for the info. I'd like to ask referring to

wvmarle:
Do look up what PWM does. It's a block wave, not a constant voltage.

The PWM makes the LEDs flicker at 500 Hz. You can't see that.

I am actually concerned that this is a high frequencies for BJTs or FETs if we are talking about small, poorly ventilated spaces, where a small (low-power) or smd components should be used, mostly without any heat sinks. Thus, there is a high probability of thermal damage of the circuitry and surroundings (plastics for instance).
My guess was that I have to reduce the voltage fluctuations to avoid overheating. Am I right?

gardner:
I think you'll need to move the PNP transistor to the +V (high) side of the LED string to get it to turn off completely.

Ok. Just curious, is there a rule and it based on some logic or it's just your guess to move this transistor? Because I was thinking it doesn't close because of a low voltage on its base in comparison to emitter voltage.
Thanks~

PNP has to switch the high side with load at the bottom as you need a bigger voltage difference with the negative voltage on the base.

way5:
is there a rule and it based on some logic

There are many ways to skin a cat, but the common approach to high and low side switches with BJTs is outlined in this tutorial
https://learn.sparkfun.com/tutorials/transistors/applications-i-switches

@gardner, thanks.
@wolframore, correct, my bad

To switch your high side PNP, you will have to add an NPN to drive it. Otherwise you can never switch it off.

Don't forget to add appropriate current limiting resistors to the bases of all the transistors. To get into saturation (and minimise losses) you want no more than 20x gain, calculate resistor values accordingly.

way5:
Great point! Thanks for the info. I'd like to ask referring to I am actually concerned that this is a high frequencies for BJTs or FETs if we are talking about small, poorly ventilated spaces, where a small (low-power) or smd components should be used, mostly without any heat sinks. Thus, there is a high probability of thermal damage of the circuitry and surroundings (plastics for instance).
My guess was that I have to reduce the voltage fluctuations to avoid overheating. Am I right?

You won't be switching the lights anywhere near so fast. The leds will be the hottest parts in the project unless you power it with 12V through a 7805 regulator and then the 7805 will be the main heater.

You're running 6 leds at maybe 20-25mA or less each? If they were a bank of incandescent bulbs, that would make Heat.

Frequency of switching is up to you if you bit-bang. Less than 500Hz still looks like glowing (not flickering) down to some value I forget so I won't quote but try some tests with led13 where the ON/OFF interval is over 19ms, the effect to look for is like the light is vibrating in brightness.
There's a Playground sketch that you wire up a led and resistor to let you shine the led 990ms and then turn the led off and use it as a light detector (old Mitsubishi white paper on led apps) for ~maybe~ 10ms in normal indoor lighting -- you never see a flicker. But the darker it is, the longer the detection takes and the sketch as it was gets flickery in low light. The sketch doesn't time-out or change anything, it could do better. Products that use this (phones and remotes) certainly do.

FET's full ON are very efficient, that's why they're used for >= 1A and in more and more cases much less current (I have signal FETs that max at 250mA) where BJT's need heatsinks or just waste power. I have logic level IRLZ44N's, $10 got me 60, they max 41A at 60V with loads of cooling but don't get warm at a couple amps of 12V to power a led string.

There's values in the datasheet, Rdson (resistance when on) can be used with expected current to calculate heat output but I have to look it up and cookbook the answer every time. I don't do it often enough to memorize at my age, too busy trying to find my keys....

I've seen potted circuits built on pieces of metal that kept them room cool and nobody can just see how it works.

If you're really going to generate heat then look into Peltier wafers, heatsinks, fans, and temperature sensors.

A little study into the Seebeck Effect can show you how transfer heat (from hot to cool) without using power or moving parts. IIRC in the 80's or 90's there was a thing you could buy that would defrost meat quickly without using power, that was a Seebeck app. There's other apps, check em out, note that voltage is not a factor of field change in a coil according to the Faraday/Lenz Law. Also note that the science of this is from before 1850 and people are still wringing more out of it!