Problem with driving LED's from ATTINY88

Go To Last Post
19 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm starting my first project, and I can't even get an LED to light!

The code is trivial; PORTB is set to all outputs, and I toggle the pin high and low with a short delay.

Looking at the output, I see exactly what I should - the pin goes high and low as expected.

However, if I connect an LED (with resistor), and connect so the pin is sinking current, the level no longer goes from 0 to 5V. It goes from 5V to maybe 3.5V, and the LED does not light. Connecting the LED to have the pin source current has the pin going from 0 to ~1.5V. This happens with a variety of LED's, and resistor values.

Is there some setting I'm missing? Internal pullups getting in the way? Something else? I've looked at the examples but it's not clear at all what I'm overlooking.

I was under the impression that the ATTINY88 could drive LED's directly; I could use a FET but I don't think I should have to.

Thanks for any tips.

[ edit: Using AVR Studio 5, I'm pretty sure everything at default ]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Welcome to the Forum.

Perhaps you did not actually set the port's bit up for Output mode.

Can you post your code for people to review?

Use the CODE tags when posting code so that indentation is preserved in the formatting on the Forum.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the quick response! Maybe that's the problem; I'll grab the code at work tomorrow.

It seems odd that it would still work as an output if the pin was set to input; maybe there's a need for such behavior that would lead to odd results like this.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I'm starting my first project, and I can't even get an LED to light!

You are not the first & won't be the last!

Quote:
Looking at the output, I see exactly what I should - the pin goes high and low as expected.

Looking at the simulator output, or at powered up target. USing logic probe, multimeter, oscilloscope, logic analyzer ?

I recommend that you get yourself a logic probe. It will actually show you whether an output is a true LO or HI, irrespective of what the LED/resistor combination do.

Quote:
This happens with a variety of LED's, and resistor values.

Your are reading the multiplier resistor correct are you. It may not work with a 470K ohm resistor.

Stick with one resistor of 150 -> say 270 Ohms.
Use a new LED or at least test your LED with a digital multimeter in the Diode position. It should read about 1.7V one way and Err/ or infinity or something in the other.
Test the LED & resistor in series straight across Vcc & gnd.
Make sure it glows. Then leave the Vcc end connected to Vcc and the ground end connected to the output pin, it will (should turn on) when the pin is LOW (sinking)

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks. No simulation was used, I just measured outputs with a scope and good probe. LED's were tested independently, and I used resistors from around 100-330 ohm.

I suspect JC is correct, maybe the configuration isn't running correctly. If for some reason the pins were still set as inputs maybe some circuitry (pullups?) is interfering.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Using AVR Studio 5,
It will not necessarily fix your problem https://www.avrfreaks.net/index.p...

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jrs454 wrote:
It seems odd that it would still work as an output if the pin was set to input; maybe there's a need for such behavior that would lead to odd results like this.

If the pin is an input, setting its PORTxn bit high will turn on the internal pullup. Setting the same bit low will make the pin float.

Sid

Life... is a state of mind

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

5V - 1,7V = 3,3V / 100R = 33mA
I do not think that an AVR can source/sink that much current multiple times. Check the datasheet....

Change the resistors to 1K - 1,5K and use a low current LED. Although most higher current leds already give good light at lower currents.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

However, if I connect an LED (with resistor), and connect so the pin is sinking current, the level no longer goes from 0 to 5V. It goes from 5V to maybe 3.5V, and the LED does not light.

Note that Tiny88 family of AVR's has very wimpy pin drive, source and sink, compared to "normal" AVRs. See the graphs in the datasheet, and see if your results match the picture.

There are a few so-called "high drive" pins. Even those are wimpy.

https://www.avrfreaks.net/index.p...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks all. Turned out JC was right and the pins were misconfigured! It's all working now.

As for the pin drive, they do look pretty wimpy. Port D is spec'd at 20mA (just adequate for LED's), and the others are 10mA (barely enough), and only 100mA is allowed in aggregate. I'll have to do a lot of multiplexing, which limits brightness, or add transistors.

Perhaps this is a subject for a new thread, but any suggestions on alternate chips? It's primary purpose is to drive ~20 LED's, 3-4 pushbuttons, and most importantly I2C interfacing to an ADAU1701 (read and write). I'm under the impression that the ATMEGA has better I2C interfacing support, but it looks like others have gotten it to work with ATTINY (and cost is somewhat a factor).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

(and cost is somewhat a factor).


DigiKey pricing, qty. 100, TQFP:
ATmega48A: $1.08
ATtiny48: $1.0875

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, how about that. Why would anyone use an ATtiny?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
20mA (just adequate for LED's),
2mA is adequate for good LEDs, for anything more one would use proper constant current LED driver chips.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
Quote:

(and cost is somewhat a factor).


DigiKey pricing, qty. 100, TQFP:
ATmega48A: $1.08
ATtiny48: $1.0875

Yeah, I use 48s (and bigger brothers if needed) for all kinds of stuff. It may be the ideal jellybean micro.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:
Quote:
20mA (just adequate for LED's),
2mA is adequate for good LEDs, for anything more one would use proper constant current LED driver chips.

I could use a driver, but for those that I've selected (7 seg displays, etc.), 10-20mA is recommended, and I would think that a separate driver chip is probably overkill. 20mA is pretty typical; I'm pretty sure 2mA models are specialty parts.

Moving to an ATmega does give some more current, but it's still fairly limited. Brightness is adequate with 15mA, which I can run all needed LED's continuously and keep under the chip current limit. Brighter would be nice, but it would require a lot more parts, and with a limit of 20mA the difference isn't huge.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jrs454 wrote:
js wrote:
Quote:
20mA (just adequate for LED's),
2mA is adequate for good LEDs, for anything more one would use proper constant current LED driver chips.

I could use a driver, but for those that I've selected (7 seg displays, etc.), 10-20mA is recommended, and I would think that a separate driver chip is probably overkill. 20mA is pretty typical; I'm pretty sure 2mA models are specialty parts.

Moving to an ATmega does give some more current, but it's still fairly limited. Brightness is adequate with 15mA, which I can run all needed LED's continuously and keep under the chip current limit. Brighter would be nice, but it would require a lot more parts, and with a limit of 20mA the difference isn't huge.


I've used m48s to drive LEDs where I divided them into half common anode and half common cathode. That let me drive more total LED current than if all had been the same drive polarity, due to the port current limits being less than the sum of the individual pin limits.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kk6gm wrote:
jrs454 wrote:
js wrote:
Quote:
20mA (just adequate for LED's),
2mA is adequate for good LEDs, for anything more one would use proper constant current LED driver chips.

I could use a driver, but for those that I've selected (7 seg displays, etc.), 10-20mA is recommended, and I would think that a separate driver chip is probably overkill. 20mA is pretty typical; I'm pretty sure 2mA models are specialty parts.

Moving to an ATmega does give some more current, but it's still fairly limited. Brightness is adequate with 15mA, which I can run all needed LED's continuously and keep under the chip current limit. Brighter would be nice, but it would require a lot more parts, and with a limit of 20mA the difference isn't huge.


I've used m48s to drive LEDs where I divided them into half common anode and half common cathode. That let me drive more total LED current than if all had been the same drive polarity, due to the port current limits being less than the sum of the individual pin limits.

Clever! Thanks for the tip.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Or just use a couple of transistors on the output, that would have the added benefit of protecting the AVR output port, and greatly increasing the amount of current you could use.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mbeels wrote:
Or just use a couple of transistors on the output, that would have the added benefit of protecting the AVR output port, and greatly increasing the amount of current you could use.

I think I'd need a transistor for each pin (or at least several) for any meaningful difference; this would be a fair bit of extra hardware. According to the LED specs, 20mA is just right. I could do more multiplexing, but some of the LED's aren't that bright, so they will be driven (near-) continuously.

Currently I have 18 segments divided into three pin groups. (5+5+3, with another 5 multiplexed). This maintains the 100mA limit per group, and using the trick above it also maintains well under 200mA for the whole chip.

This stuff is fun.