ATtiny and ATmega Output Pins

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

I'm a little confused to the source output of ATtiny's and ATmega's. Is it a passive pullup? Somewhere I'm thinking I read where you can drive a LED directly without a current limiting resistor. Is that true, if so why?

Phil

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

The internal pullups are only useful for reading switches etc. You turn them on by setting your pin to input with DDRx.n = 0; PORTx.n = 1; // for pullup and then you read the switch with result = PINx.n

You always connect your switch between the pin and GND.

For output you normally connect the LED anode to Vcc with a resistor. And connect the LED cathode to your output pin. Of course you set DDRx.n = 1; // for output.

When reading a switch, 0 means closed.
When sinking a LED, 0 means light.

Correct C syntax is PORTx |= (1<<n); // PORTx.n = 1;
And PORTx &= ~(1<<n); // PORTx.n = 0;

You ALWAYS need an external current limiting resistor for an LED (unless integral with LED package).

An AVR or a PIC can source current to an LED but it will still need a resistor and the rated current is generally less for source than sink. An 8051 can only sink current.

HTH David.

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

http://www.avrfreaks.net/index.p...
http://www.avrfreaks.net/index.p...
(where ezcomp says he does it all the time--before you take that as gospel, look back on the content of his posts. ;) )

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

Looking further at least for the Mega48, max output current per output pin is 40ma, so looks like a limiting resistor is needed. I thought maybe each pin had a current limiter. Thanks

Phil

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

Quote:

max output current per output pin is 40ma,

Not exactly. That is in the Absolute Maximum Ratings * section, right? Note the asterisk:
Quote:
Quote:
*NOTICE: Stresses beyond those listed under “Absolute Maximum Ratings” may cause permanent damage to the device. This is a stress rating only and functional operation of the device at these or other conditions beyond those indicated in the operational sections of this specification is not implied. Exposure to absolute maximum rating conditions for extended periods may affect device reliability.

See this thread where 80mA was drawn:
http://www.avrfreaks.net/index.p...

and the datasheet sections such as 28.8 Pin Driver Strength
Figure 28-22. I/O Pin Source Current vs. Output Voltage (VCC = 5V)

Lee

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

When calculating maximum current flow through AVR I/O pins, always look up the data sheet Electrical Characteristics section, under the DC Characteristics table. There are notes after this table that explain how much current all the I/O pins together may source or sink. Different groups of combined I/O port pins have different maximum current levels and there is a combined total maximum for the entire AVR chip.

When you add up the current flow through all the AVR I/O pins in a given port, some ports will not even support 20 ma for all eight I/O pins simultaneously.

For high current draw on multiple AVR I/O pins, find a suitable driver/interface chip that can drive or sink your high current loads. If it is only a few AVR I/O pins, then just use discrete transistor driver circuits.

As always, if this is a one of a kind hobby project, do whatever you want to the AVR chip. All you risk is a damaged or dead AVR chip. If this is for a product that you will build multiple copies of and have to support after you sell it, always design within the data sheet specifications.

Just for fun, maybe you could adapt one of the popular Personal Computer CPU liquid coolers to your AVR chip and see how far you can push the AVR chip beyond its maximum current specification before it self destructs :).