I/O Pin Source vs. Sink - Page 1
Forum section: electronics / beginners

author: jrozner
author_rank: Contributor
timestamp: December 15, 2016, 04:53:27 am
content: 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.

author: ataradov
author_rank: Super Contributor
timestamp: December 15, 2016, 05:16:42 am
content: 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.

author: digsys
author_rank: Unknown
timestamp: December 15, 2016, 06:53:14 am
content: 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.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: December 15, 2016, 07:21:12 am
content: 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

author: matseng
author_rank: Frequent Contributor
timestamp: December 15, 2016, 09:03:18 am
content: Quote from: digsys on December 15, 2016, 06:53:14 amI'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....

author: tggzzz
author_rank: Super Contributor
timestamp: December 15, 2016, 10:31:46 am
content: Quote from: jrozner on December 15, 2016, 04:53:27 amThe fastest way to assess that is to look at the driving device's datasheet.Ideally there will be two Vout-vs-Ioutgraphs, 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-Ioutpoints listed in a table. If you can't find that, then choose another device.

author: digsys
author_rank: Unknown
timestamp: December 15, 2016, 12:30:51 pm
content: Quote from: matsengoops, 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 optionfor the MPUs I use. (silabs)

author: shteii01
author_rank: Frequent Contributor
timestamp: December 15, 2016, 02:42:51 pm
content: Quote from: matseng on December 15, 2016, 09:03:18 amYou 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!

author: ataradov
author_rank: Super Contributor
timestamp: December 15, 2016, 04:23:50 pm
content: Quote from: shteii01 on December 15, 2016, 02:42:51 pmWhat 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.

author: rstofer
author_rank: Super Contributor
timestamp: December 15, 2016, 04:30:33 pm
content: 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.

author: retrolefty
author_rank: Super Contributor
timestamp: December 15, 2016, 06:20:32 pm
content: Quote from: rstofer on December 15, 2016, 04:30:33 pmThose same package limit spec also applies to the Vcc pin(s) so what is your point?

author: KL27x
author_rank: Super Contributor
timestamp: December 15, 2016, 07:02:35 pm
content: QuoteGet 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 decisionsIf 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.

author: bson
author_rank: Unknown
timestamp: December 15, 2016, 11:18:42 pm
content: Quote from: KL27x on December 15, 2016, 07:02:35 pmThis ^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.

author: Zero999
author_rank: Super Contributor
timestamp: December 16, 2016, 09:19:33 am
content: Quote from: rstofer on December 15, 2016, 04:30:33 pmYes 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.

author: bson
author_rank: Unknown
timestamp: December 16, 2016, 11:29:49 pm
content: Just to clarify - if you want to increase themax currentwith 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 loadbetweentwo pins. (= bridge drive. MOS only.)