5
\$\begingroup\$

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).

\$\endgroup\$
9
\$\begingroup\$

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.

\$\endgroup\$
5
\$\begingroup\$

It makes no real difference.

The ATTiny chips can sink and source the same amount of current. So it really is down to your application.

Some chips can sink more than they can source, and some can source more than they can sink. Some have higher total source limits than total sink limits, and some have higher sink than source limits. But not the ATTiny chips.

It's all listed in the data sheet under Electrical Characteristics.

Maximum DC current per pin (either direction) is 40mA, but they don't guarantee more than 20mA. Maximum current on any Vcc or GND pin is 200mA.

\$\endgroup\$
1
  • 4
    \$\begingroup\$ And to avoid misunderstanding: these are the maximum allowed currents. The chip does not (reliably) limit the currents. It is up to the external circuit to ensure that these currents are not exceeded. \$\endgroup\$ Sep 15 '14 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.