Electronic – Sink or source from AVR


I've been (re)learning microcontroller programming using AVR ATinys (13/45/85). One reference on digital outputs said that I should sink outputs, but nearly all of the circuit examples I've seen online source them.

Which is right/generally better? If the answer is "it depends" would you mind providing guidelines for when each is better (in the case of ATiny digital outputs).

Best Answer

Atmel AVR output drivers have reasonably symmetric current capabilities. Some MCUs do not.

An N-Channel MOSFET (N-MOSFET) has a lower resistance (and hence higher current capacity) than a P-Channel MOSFET (P-MOSFET) of the same size.

N-MOSFETs connect an output pin to ground, and hence sink current.
P-MOSFETs connect an output pin to Vcc, and hence source current.

I believe this may a cause for some 'better to sink' advice.

It costs more silicon area for the P-MOSFET to make the current handling comparable to an N-MOSFETs. Some manufacturers don't seem to do that. Instead they specify the drive capability in the data sheet, and it is asymmetric. This seems to be less of an issue with more modern devices, where symmetric drive capability appears to be a bullet point on the device's marketing features list.

Another feature of output drivers is open-drain/open-collector. The high-side P-MOSFET is disabled, and only the low-side N-MOSFET part of the output driver is active. This means the output can only ever be 'LOW' (conducting) when the N-MOSFET is on. The output is high-impedance when the N-MOSFET is off; it isn't actively pulling the pin to Vcc.

One use of open-drain is to enable an output pin to switch something which is connected to a voltage higher than the MCU's Vcc. This is handy. For example 3 or 4 LEDs in series could be driven directly from 9V by a 5V MCU. Also the current doesn't need to come via the Vcc voltage regulator, so it might be possible to use a lower-rated regulator part. (Open-drain/open-collector has other uses, for example using a shared wire for signalling data between more than two devices.)

Open-drain drivers only applies to the low-side N-MOSFET. IIRC some PIC's do this, maybe well above 9V. So I believe this also may be the cause of some 'better to sink' advice.

Summary: for the AVR's it does not matter (i.e. I can't remember seeing one which was not symmetric). However it would be better to sink current than source it with some other manufacturers devices when they have asymmetric pin drivers or open-drain-capable drivers.

It is worth noting that larger-power MOSFETs might still show the asymmetry, for example a package containing both an N-MOSFET and a P-MOSFET may have a significantly lower power for the P-MOSFET. Some H-Bridge drivers work that way too.