ATtiny45 low output current - Page 1
Forum section: electronics / beginners

author: tuomotal
author_rank: Newbie
timestamp: October 22, 2015, 03:09:47 pm
content: Hi.I did a small test with ATtiny45 microcontroller to see if I can program it with Arduino Uno. I got my test program (1Hz blinking on two pins) in successfully and when measured with an oscilloscope the microcontroller seems to be working fine. When I connected leds from pins to ground they were blinking correctly but they were very dim. Current from (high) pin through standard 3mm yellow led to ground was only like 0.07mA with no external resistor used and even short circuit current was only like 0.142mA. What could be the reason for such a low output current? I used 5V operating voltage from lab power supply and ATtiny45 is 8 pin DIP version.

author: BillyD
author_rank: Regular Contributor
timestamp: October 22, 2015, 03:20:04 pm
content: If you do not set the pinMode() to OUTPUT, and connect an LED to a pin, when calling digitalWrite(HIGH), the LED may appear dim.Without explicitly setting pinMode(), digitalWrite() will have enabled the internal pull-up resistor, which acts like a large current-limiting resistor.

author: Simon
author_rank: Unknown
timestamp: October 22, 2015, 05:03:15 pm
content: You MUST use a current limiting resistor. Or you will just blow the chip.

author: miceuz
author_rank: Frequent Contributor
timestamp: October 22, 2015, 05:09:00 pm
content: Looks like you didn't set your pins as outputs. Also, don't connect leds to pins without a resistor. AVRs are forgiving in this regard at the first glance - output drivers are protected, you might get the impression you can skip the resistors, but you *will* get problems eventually (for example, just look at your power rail).

author: Simon
author_rank: Unknown
timestamp: October 22, 2015, 05:19:13 pm
content: Quote from: miceuz on October 22, 2015, 05:09:00 pmOh no they bloody well aren't. I spent a day looking like a tit in front of a customer at work because I tried to put LEDs straight onto the out pins of an AVR. It was only when I convinced my boss to let me swap the chip for another one that the system started working hence I remembered trying to connect LEDs to the outputs when I was a prototype of the circuit. I think it is rumoured you can get away with this on 3.3 V or less but it really is not a good idea. Do not do it.

author: matseng
author_rank: Frequent Contributor
timestamp: October 23, 2015, 04:09:03 am
content: A few years back I actually tried to destroy a port by connecting half the pins directly to GND and the other half to VCC and then setting them as outputs of the opposite polarity. The chip (I think it was a Mega8) got just lukewarm and the outputs still worked fine after being shorted for a week.

author: Mechatrommer
author_rank: Super Contributor
timestamp: October 23, 2015, 04:31:32 am
content: worked fine doesnt necessarily means worked wise..

author: matseng
author_rank: Frequent Contributor
timestamp: October 23, 2015, 05:13:15 am
content: Quote from: Mechatrommer on October 23, 2015, 04:31:32 amAbsolutely true, but at least it didn't break spectacularly or in any easily detectable way. All pins could still sink and source at levels that was the same a before. The AVRs is (was) sturdy little buggers...So many people believe that even a brief short will kill an output pin dead, but from my experience and this test that is not true.But of course, YMMW, and don't do this on a real commercial design. ;-)

author: Simon
author_rank: Unknown
timestamp: October 23, 2015, 05:31:08 am
content: funny i've never read anything about output protection on an AVR pin on a datasheet, if it was there they would be telling you all about it.....

author: Psi
author_rank: Super Contributor
timestamp: October 23, 2015, 06:45:16 am
content: With an LED directly on the output of an AVR the larger than normal current causes the output voltage to fall which reduces the current.Exactly what current this stabilizes at will depend on the LEDs forward voltage.But in 90% of cases it will run without any damage for a short time, maybe even for months. But with the output driver running hotter than usual you are asking for trouble.The AVR outputs are protected in that they have protection diodes, but this is not current limiting.I've not done the math but you might be able to wire an LED direct and keep the current level safe if you did some fast pulsing and used the circuits inductance/capacitance to limited the current.

author: Simon
author_rank: Unknown
timestamp: October 23, 2015, 06:57:46 am
content: I think on low voltages like 3.3V it may work but it's a flukenot an engineered solution. If it's for a one of trinket that you can have fail and not be a problem do it but if it's for anyone other than you or it needs to be reliable just don't. All you need is one mosfet like a 2N7000 (or 2N70002 if SMD) to trigger the LED to any required voltage with suitable limiting resistor.

author: tuomotal
author_rank: Newbie
timestamp: October 23, 2015, 09:17:40 am
content: QuoteOh, you are right. I made a faulty assumption that I wouldn't get any output if pins were set as inputs so I thought that couldn't be the problem. But... I had DDRB &= instead of DDRB |= where I tried to set pins as outputs and that was the only problem actually. I used resistors as usually until I noticed very low current and will be using. Thanks for your help.

author: Psi
author_rank: Super Contributor
timestamp: October 23, 2015, 09:25:04 am
content: The AVR i/o registers are laid out quite nicely, you can get a lot of different combinations by switching a single register between two states.open, pullup , low , high etc..egIf you have an LED on a pin you can switch between dim (pullup) and bright (output high) by toggling DDR.Or you can toggle between output high and open by doing the same thing but with pullup disable active (PUD).

author: Simon
author_rank: Unknown
timestamp: October 23, 2015, 12:48:26 pm
content: It is a common mistake to try and output something with out setting the pin as output. Usually if you see a small amount of output similar to what you expect but with no power it is because the pin was not enabled as an output.