## ATtiny and ATmega Output Pins

6 posts / 0 new
Author
Message

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

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.

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.

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

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.