Author Topic: I/O Pin Source vs. Sink  (Read 7011 times)

0 Members and 1 Guest are viewing this topic.

Offline jroznerTopic starter

  • Contributor
  • Posts: 21
  • Country: us
I/O Pin Source vs. Sink
« on: December 15, 2016, 04:53:27 am »
I'm wondering if there is ever a specific reason to want to use an I/O pin on a microcontroller as a source or a sink for say an LED. I've read that sometimes microcontrollers can be significantly better or worse at sourcing or sinking from I/O and decided to experiment with two of the arduinos I had. I created a simple circuit and sketch to try it in both configurations and attached a multimeter (in milliamp) to measure the current flowing through. I found that in terms of the ATmega328P and ATmega2560 both seemed to have fairly similar amounts of current but I would get about 5-10 mA more when using the I/O pin as a source rather than sink.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: I/O Pin Source vs. Sink
« Reply #1 on: December 15, 2016, 05:16:42 am »
TTL is 100% better at sinking. That's why a lot of people still connect things like LEDs to VCC and enable then with a logic low.

CMOS logic is fully symmetrical when currents are within the specified maximum ratings.

Also, section "30.2 DC Characteristics" of the ATmega328P datasheet list all the limits.
« Last Edit: December 15, 2016, 05:24:24 am by ataradov »
Alex
 

Offline digsys

  • Supporter
  • ****
  • Posts: 2209
  • Country: au
    • DIGSYS
Re: I/O Pin Source vs. Sink
« Reply #2 on: December 15, 2016, 06:53:14 am »
My orders of preference -
1/ Source to external pass tansistor - If the shlt hits the fan, it is MUCH easier to change a transistor. LEDs can run on any voltage.
2/ Sink - the poor MPU doesn't have to supply the current = loading = heating. Especially important when you're running many outputs.
3/ Source - just be careful of loads and ANY back voltages that can pop your MPU.
Hello <tap> <tap> .. is this thing on?
 

Online T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 21686
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: I/O Pin Source vs. Sink
« Reply #3 on: December 15, 2016, 07:21:12 am »
CMOS isn't symmetrical -- but it can be.

Most families have a somewhat lower resistance pull-down (NMOS) than pull-up (PMOS).  This is because it's approximately the right ratio for speed and skew (rise/fall time, and capacitance required to be driven by the proceeding transistors inside the IC), while also not taking up much space (the PMOS transistor takes up about twice the area of the NMOS, so the IC layout isn't a burden).

This is typical of the 74HC family, which has about 40 ohms pull-down and about 70 ohms pull-up.  The average is ~55 ohms, which is conveniently at or below the impedance of most transmission lines.  Add a small series-termination resistor and you have excellent signal quality, say in a super long PCB trace, or a ribbon cable.

Microcontrollers and other general- and special-purpose devices may be made either way.  YMMV.

Note that very small IO drivers, such as on most FPGAs (say Cyclone 3 and up, and whatever Xilinx parts those are equivalent to), aren't rated to handle much if any DC -- under 2mA perhaps.  These should only drive CMOS input pins (that only draw current while the voltage is changing -- pin capacitance).  They also have very little ESD tolerance!

Tim
« Last Edit: December 15, 2016, 07:23:14 am by T3sl4co1l »
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline matseng

  • Frequent Contributor
  • **
  • Posts: 563
  • Country: se
    • My Github
Re: I/O Pin Source vs. Sink
« Reply #4 on: December 15, 2016, 09:03:18 am »
2/ Sink - the poor MPU doesn't have to supply the current = loading = heating.
I'm not sure I understand the reasoning here.

As I see it there's really no difference of having the current entering the VCC pin, going thru the switching element and then exiting at the iopin - or having the current come in at the iopin, going thru the switching element and then exiting at the GND pin.

Atleast not from a loading/heating perspective, as long as the switching elements have the same drop/resistance at both the high and low sides....
 

Online tggzzz

  • Super Contributor
  • ***
  • Posts: 19501
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: I/O Pin Source vs. Sink
« Reply #5 on: December 15, 2016, 10:31:46 am »
I'm wondering if there is ever a specific reason to want to use an I/O pin on a microcontroller as a source or a sink for say an LED. I've read that sometimes microcontrollers can be significantly better or worse at sourcing or sinking from I/O and decided to experiment with two of the arduinos I had. I created a simple circuit and sketch to try it in both configurations and attached a multimeter (in milliamp) to measure the current flowing through. I found that in terms of the ATmega328P and ATmega2560 both seemed to have fairly similar amounts of current but I would get about 5-10 mA more when using the I/O pin as a source rather than sink.

The fastest way to assess that is to look at the driving device's datasheet.

Ideally there will be two Vout-vs-Iout graphs, one for a logic one output, the other for a logic zero output. If you can't find that, then there is probably a set of  Vout-vs-Iout points listed in a table. If you can't find that, then choose another device.
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Offline digsys

  • Supporter
  • ****
  • Posts: 2209
  • Country: au
    • DIGSYS
Re: I/O Pin Source vs. Sink
« Reply #6 on: December 15, 2016, 12:30:51 pm »
Quote from: matseng
I'm not sure I understand the reasoning here.
As I see it there's really no difference of having the current entering the VCC pin, going thru the switching element and then exiting at the iopin - or having the current come in at the iopin, going thru the switching element and then exiting at the GND pin.
Atleast not from a loading/heating perspective, as long as the switching elements have the same drop/resistance at both the high and low sides.... 
oops, I over generalized here. I got used to MPUs with onboard regs and non-symmetrical io drivers. But as a rule, for higher currents, I found sinking the better option
for the MPUs I use. (silabs)
Hello <tap> <tap> .. is this thing on?
 

Offline shteii01

  • Frequent Contributor
  • **
  • Posts: 266
  • Country: us
Re: I/O Pin Source vs. Sink
« Reply #7 on: December 15, 2016, 02:42:51 pm »
2/ Sink - the poor MPU doesn't have to supply the current = loading = heating.
I'm not sure I understand the reasoning here.

As I see it there's really no difference of having the current entering the VCC pin, going thru the switching element and then exiting at the iopin - or having the current come in at the iopin, going thru the switching element and then exiting at the GND pin.

Atleast not from a loading/heating perspective, as long as the switching elements have the same drop/resistance at both the high and low sides....
You have ATmega328, it can source about 40 mA from a pin.  You connect a fan that can draw as much as 120 mA.  You arrive to a choice:  Do I source from io pin and come up short by 80 mA or do I sink into io pin and have the fan running at its full potential?  I think the answer is obvious. 

Heating elements are even worse.  By their nature they require A LOT OF CURRENT.  Why, for eF sake, would you try to source current from uC to the heating element!
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: I/O Pin Source vs. Sink
« Reply #8 on: December 15, 2016, 04:23:50 pm »
Do I source from io pin and come up short by 80 mA or do I sink into io pin and have the fan running at its full potential?  I think the answer is obvious. 
What makes you think that ATmega328 can sink 120 mA? It can't. 40 mA is absolute maximum rating for both directions. And it is absolute, you should not get anywhere close to it in real life.
Alex
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: I/O Pin Source vs. Sink
« Reply #9 on: December 15, 2016, 04:30:33 pm »
There is often a Package Limit on current flowing out the Gnd pin.  Even is every pin can sink 20 mA for an LED, there may still be a limit to the total current.
 

Offline retrolefty

  • Super Contributor
  • ***
  • Posts: 1648
  • Country: us
  • measurement changes behavior
Re: I/O Pin Source vs. Sink
« Reply #10 on: December 15, 2016, 06:20:32 pm »
There is often a Package Limit on current flowing out the Gnd pin.  Even is every pin can sink 20 mA for an LED, there may still be a limit to the total current.

 Those same package limit spec also applies to the Vcc pin(s) so what is your point?
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4102
  • Country: us
Re: I/O Pin Source vs. Sink
« Reply #11 on: December 15, 2016, 07:02:35 pm »
Quote
I'm wondering if there is ever a specific reason to want to use an I/O pin on a microcontroller as a source or a sink for say an LED.
Get used to making arbitrary decisions. If you spend so much thought on something like this, you will not get anything done. This is just the tip of a giant iceberg of arbitrary decisions :) If you must have a reason, go with what makes the pcb layout cleaner. If you're intentionally trying to cut things so close to max you need to worry about max current, you're just making more trouble for yourself down the road.
« Last Edit: December 15, 2016, 07:09:00 pm by KL27x »
 

Offline bson

  • Supporter
  • ****
  • Posts: 2270
  • Country: us
Re: I/O Pin Source vs. Sink
« Reply #12 on: December 15, 2016, 11:18:42 pm »
If you spend so much thought on something like this, you will not get anything done. This is just the tip of a giant iceberg of arbitrary decisions :) If you must have a reason, go with what makes the pcb layout cleaner. If you're intentionally trying to cut things so close to max you need to worry about max current, you're just making more trouble for yourself down the road.
This ^

Or base the decision on the default reset/power-on state so there's no glitching on the pins before you can get it configured.
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19521
  • Country: gb
  • 0999
Re: I/O Pin Source vs. Sink
« Reply #13 on: December 16, 2016, 09:19:33 am »
There is often a Package Limit on current flowing out the Gnd pin.  Even is every pin can sink 20 mA for an LED, there may still be a limit to the total current.
Yes that's true. Normally the maximum currents for both supply rails are the same. Which is why it's a good idea to both source and sink, if possible. If half the loads on the I/O pins are sourcing and the other half sinking, then you can drive twice as much current as you would with all of them sinking/sourcing.
 

Offline bson

  • Supporter
  • ****
  • Posts: 2270
  • Country: us
Re: I/O Pin Source vs. Sink
« Reply #14 on: December 16, 2016, 11:29:49 pm »
Just to clarify - if you want to increase the max current with CMOS use multiple pins in parallel.  With honest-to-goodness schottky you'd probably want ballast resistors, but MOS is fine without.  If you need to run the current in either direction place the load between two pins.  (= bridge drive.  MOS only.)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf