40
\$\begingroup\$

I noticed, that on all my evaluation boards that I had up to this point in time. The LEDs were all connected in active low to the Microcontroller Port. I understand that from a safety view it's better to have active low RESET lines and such. But why LEDs?

\$\endgroup\$
6
  • 22
    \$\begingroup\$ In the old days, NMOS and NPN transistors were much stronger than PMOS or PNP. So we all got in the habit of arranging LED's so that the logic input sinks rather than sources current. It mostly doesn't matter any more, but old habits die hard. I have connected LED's the other way on occasion. It works fine as long as your respect the current limit of the IO. \$\endgroup\$
    – mkeith
    May 23 '17 at 16:15
  • 22
    \$\begingroup\$ It is often the case that a microcontroller's IO pins are able to sink more current than they can source. This can make for brighter LEDs without exceeding the total max current source for the whole chip. Your milage may vary of course, always check the datasheet. \$\endgroup\$
    – user98663
    May 23 '17 at 16:15
  • 4
    \$\begingroup\$ TTL grandfathered the notion of active low drive and CMOS I/O is always inactive high or floating input with/without active pullup. thus LED OFF after RESET \$\endgroup\$ May 23 '17 at 22:08
  • 3
    \$\begingroup\$ Historical note: TTL inputs floated high, and to drive an input low, you had to pull current from it. That is why TTL outputs had to be able to "sink" significant current in the low state, while they did not have to "source" much current in the high state. (In fact, TTL parts with open collector outputs could not source any current at all in high state.) \$\endgroup\$ May 24 '17 at 13:42
  • 2
    \$\begingroup\$ One other point. In "the good old days" LEDs were very inefficient and you really needed 20mA to make them look reasonable. These days 5mA is dazzling, so source or sink is not usually an issue. \$\endgroup\$ May 24 '17 at 14:00
49
\$\begingroup\$

It's still the case that MCU I/O pins often have weaker drive sourcing current than sinking current.

In a typical CMOS MCU output, when they drive LOW, they turn on an N-channel MOSFET; and when they drive HIGH they turn on a P-channel MOSFET. (They never turn both of them on at the same time!) Because of the differences in mobility that apply for N-channel vs P-channel (about a factor of 2 to 3 difference), it takes extra effort to make the P-channel device exhibit similar "quality" as a switch. Some go to that extra effort. Some do not. If not, the ability to sink (N-channel) or source (P-channel) current will be different.

Some of them are almost symmetrical, in that they can source almost as much as they can sink. (Which just means they are about as good of a switch to ground as they are a switch to the power supply rail.) But even when extra trouble is attempted, there are other issues that make it unlikely the two devices will be fully similar and it still is usually the case that the sourcing side is still at least somewhat weaker.

But in the final analysis, it's always a good idea to go look at the datasheet itself to see. Here's an example from the PIC12F519 (one of the cheapest parts from Microchip that still includes some internal, writable non-volatile storage for data.)

This chart shows the LOW output voltage (vertical axis) vs the LOW sinking current (horizontal axis), when the CPU is using \$V_{CC}=3\:\textrm{V}\$:

enter image description here

This chart shows the HIGH output voltage (vertical axis) vs the HIGH sourcing current (horizontal axis), also when the CPU is using \$V_{CC}=3\:\textrm{V}\$:

enter image description here

You can easily see that they don't even bother trying to show the same sinking vs sourcing current capabilities.

To read them, pick a current that is of similar magnitude on both charts (very difficult, isn't it?) Let's select \$5\:\textrm{mA}\$ on the first chart and \$4\:\textrm{mA}\$ on the second one. (About as close as we can get.) You can see that the PIC12F519 will typically drop about \$230\:\textrm{mV}\$ on the first one, suggesting an internal resistance of about \$R_{LOW}=\frac{230\:\textrm{mV}}{5\:\textrm{mA}}\approx 46\:\Omega\$. Similarly, you can see that the PICF519 will typically drop about \$600\:\textrm{mV}\$ on the second chart, suggesting an internal resistance of about \$R_{HIGH}=\frac{600\:\textrm{mV}}{4\:\textrm{mA}}\approx 150\:\Omega\$. Not very similar. (NOTE: I've extracted data from the curves for \$25^\circ\textrm{C}\$.)

So if you were designing this particular MCU into a circuit where you wanted to directly drive a \$2\:\textrm{V}\$ LED at about \$10\:\textrm{mA}\$, which way would you wire it? It's clear that you'd have to consider LOW as ON, since that is the only way that the datasheet says you might be successful, at all, without the need for an external transistor to boost the current compliance of the output.

[You may also take note that the above calculations at nearby sinking vs sourcing currents appear to show two resistance values that are approximately a factor of three from each other (about \$50\:\Omega\$ vs \$150\:\Omega\$.) This is probably not coincidental to the differences in mobility that I mentioned at the outset, that between P-channel and N-channel mosfets.]

Historical Note

The TTL series of ICs that became more widely available in the early 1970's were built upon NPN BJTs and were only able to sink significant currents. They could only source relatively small currents. Here's an example table from TTL:

enter image description here

Note that \$I_\text{OL}=16\:\text{mA}\$ and is sufficient to drive an LED, but that \$I_\text{OH}=-400\:\mu\text{A}\$ and isn't sufficient (in most cases.)

In those days, there wasn't much of an alternative. As a result, you'd often find TTL family ICs using inverted outputs preferred for earlier release than equivalent packages with non-inverting outputs.

A classic example I remember very well, because I was wire-wrapping my own 7400 computer back in 1974, is the 7489. This is a 64-bit 16x4 RAM with complementary, open-collector outputs, released a year beforehand in about 1973. It complemented the stored data on output. I used this fact to display the data directly, using LEDs, while also still capable of driving other logic depending on the RAM data output values. I'm pretty sure that I'm not the only one who enjoyed that fact and I suspect it informed the design choice made for this early RAM part.

At the time, we'd all been making extensive use of open-collector outputs with pull-up resistors. These provide a kind of "poor-man's" version of tri-stating and it was about the only convenient way to support a bus with multiple outputs riding on it.

The better and less power hungry tri-stating outputs eventually came onto the scene to support multiple "talkers" on a bus. They were very attractive when they arrived and I'd started playing with them. But I never did actually did create a large project using them. By the time they appeared, I was onto other things.

So it was much later that we saw the 74189. This is also 64-bit 16x4 RAM with complementary output, but instead of open-collector it provided tri-state capable output. Here, they chose to match the ID number with the prior 7489 and so the output was also the complemented version of the stored value. But no longer open-collector. I suppose this was billed as a "replacement" in cases where there was a transition from open-collector projects towards tri-state and where the remaining logic still expected to see complementary outputs and the project owner(s) wanted to focus only on the bus method and didn't want to add inverters to the design.

The 74219 capped this off with yet another version of a 64-bit 16x4 RAM, also with tri-state capable outputs, but now with the uncomplemented output. This was there for new designs, which didn't have to keep with the prior complementary output style from prior years.

\$\endgroup\$
10
  • 1
    \$\begingroup\$ @TonyM I've tested countless devices about ten years ago -- from the MSP430 to Microchip PIC devices. While in many cases the MCUs have gotten much closer in source vs sink capabilities, there was ONLY one case where I found the source capability to equal or exceed the sink capability. And that was in a device where ONLY ONE PIN was so specified and achieved. All of them, otherwise, exhibited lower drive. Not to the point of the example device I gave, but far enough that it is worth knowing. The MSP430, for example, provides about 60 ohm sink and about 100 ohm source. \$\endgroup\$
    – jonk
    May 23 '17 at 18:51
  • 1
    \$\begingroup\$ @TonyM So while the details vary, of course, and some devices will be closer (much closer at times) than others, the point remains. Do you have a specific device that provides detailed curves over sink and source currents that I might examine, in order to improve my answer here? Let's say that the selected device must operate with \$V_{CC}=3\:\textrm{V}\$, so that I can keep apples to apples. I'd enjoy improving the answer. \$\endgroup\$
    – jonk
    May 23 '17 at 18:52
  • 1
    \$\begingroup\$ Now you're asking, I've closed 'em all. Have a look at the Silicon Labs part and usually NXP datasheets are good, I'll have to recheck in a bit. But my examples show that logic chips today are balanced and its only digging deep you find imbalance. You can clearly hang an LED either way off these outputs and they'll work fine. The outputs don't have to be really precisely balanced to see that the old logic has gone, like 74LS outputs with 1.6 mA sink and 0.4 mA source, a 4-to-1 ratio. So one can't say the point remains, it's mostly just old habits pervading. Unless you love only Microchip :-) \$\endgroup\$
    – TonyM
    May 23 '17 at 19:14
  • 1
    \$\begingroup\$ @TonyM My point is more about looking at datasheets and doing the associated sanity checks, than it is about any one device. Also, though, it's not unreasonable to anticipate some difference. And that if you have a choice, you may find that it's a little bit more secure using active-LOW, even today. But always CHECK!! Clearly, for some applications (LEDs for example) it's far more likely today than 20 years ago. But the OP is asking about "Why?" they find what they find. My answer is an answer to that question. I'd still like to see some curves (not table rows) of some device at 3V. \$\endgroup\$
    – jonk
    May 23 '17 at 19:18
  • 1
    \$\begingroup\$ @TonyM Your NXP P89LPC933 seems to how only one curve for \$I_{OH}\$ as a function of \$V_{OH}\$ at \$V_{CC}=3.6\:\textrm{V}\$. Nothing for \$I_{OL}\$, at all. Maybe I missed it? It would be enjoyable if you could find a good case to make your point clear and unequivocal, without the nuance of having to say "for this application it is the same but for that application, maybe not." I'd like to add it to my answer, very much. \$\endgroup\$
    – jonk
    May 23 '17 at 19:23
21
\$\begingroup\$

It is fairly common (although not as common as it used to be) that microcontroller output pins can sink more current in the low state than they can source in the high state. As a result, designers got used to putting LEDs, or anything else that needs a high (for a microcontroller pin) current between power and the pin instead of between ground and the pin. When the micro has symmetric source/sink capability, this is not necessary, but does no harm either.

For example, here is a snippet from the PIC 16F1459 (a reasonably recent and certainly mainstream production part) datasheet:

Note how the currents for the Output Low Voltage case are higher at the same supply voltage than for the Output High Voltage case. And, the sink currents are specified for a 600 mV rise, while the source currents for a 700 mV drop. All in all, this micro has substantially stronger low side drivers on its regular I/O pins.

Many newer micros are symmetric, apparently particularly those that don't have much source/sink capability in the first place.

When the LED requires more current than a digital output can handle, or at least more than you want to let it handle, you need to use a external transistor. A low side switch is the natural and simple choice. The LED is then connected between power and this transistor.

\$\endgroup\$
12
  • 1
    \$\begingroup\$ Hi, a correction for your answer: [it was fairly common that microcontroller output pins could sink more current in the low state than they can source in the high state. Microcontrollers of the last 10 years or more have balanced outputs that source as much as they sink] I agree completely it was the case with 8048, 8051, 6811 and all the old'uns but not so with post-2005 or thereabouts-ish stuff like all the ARMs. Thanks. \$\endgroup\$
    – TonyM
    May 23 '17 at 16:41
  • 1
    \$\begingroup\$ @Tony: Asymmetric source/sink is still common, although less than it used to be. I just checked one of the PIC 16F1xxx (16F1359 specifically) parts, which are fairly new. With 5 V Vdd a high output can source 3.5 mA with 700 mV drop. A low output can sink 8 mA with 600 mV drop. This is far from gone, even in modern micros. \$\endgroup\$ May 23 '17 at 16:59
  • 1
    \$\begingroup\$ The PIC16F1xxxx are an upgrade from the old PIC16Fxxx line but still ancient technology. They are all symmetrical now as close as possible with wide tolerances 25% typ. and 1/Vdd sensitive. \$\endgroup\$ May 23 '17 at 18:23
  • 1
    \$\begingroup\$ Thanks for looking but Microchip part looks misleading. I looked up: NXP P89LPC933 (8051, 2004) with Iol=Ioh=20 mA; NXP LPC1111 (ARM, 2010) with Iol=Ioh=4 mA; TI OMAP5910 with Iol=Ioh=same (configurable) mA; TI TMS320C620 with Iol=Ioh=8 mA; Silicon Labs EFM32GG380 (2014) with Iol=Ioh=same (configurable) mA. Ignore the missing '-' on sinks. Could have kept going, just quick 5 mins in my datasheet library...personally, I haven't seen an unbalanced one in decades. Please can you re-edit your answer similar to my earlier comment, good to give the full picture and harmless to your answer to do so. \$\endgroup\$
    – TonyM
    May 23 '17 at 18:30
  • 1
    \$\begingroup\$ that's how old 16F1 must be .. I have written extensively in this forum about the RdsOn vs Vdd and CD4xxx, 74HCxxx 74 LV, ALC AVLC2 are ALL more symmetrical by design with vintage and lower ESR or Rs or RdsOn = Vol/Iol and (Vdd-Voh)/Ioh but no one else has given kudos for this revelation. \$\endgroup\$ May 23 '17 at 18:58
10
\$\begingroup\$

By using a pull-down design it is possible to switch a device (eg a LED) with a 5V supply, using a 1.8V but 5V tolerant microcontroller without any external components.

When the (open-drain configured) pin is not pulled down it is floating, as no current is drawn the voltage will float to the supply voltage of the led so to 5V. This is ok for some but not all low-voltage micros.

This way you can run the leds directly off a supply line and use a lower current voltage converter for the micro. This is the only way to use eg. blue leds on a 1.8v micro without adding more components.

For example the pins of the NXP LPC81xM series are 5v tolerant when the micro is powered, even at 1.8v

Dataseet of NXP LPC81xM

excerpt from datasheet

\$\endgroup\$
1
\$\begingroup\$

Because open drain mosfets generally sink more current than push pull and sometimes even tolerate a wider voltage range. Using an LED with open drain only works with an active low configuration. Depends on the micro though, some are only push pull.

\$\endgroup\$

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.