What is best configuration to connect LED to micro controller ?  - Page 1
Forum section: electronics / projects

author: Sai teja
author_rank: Regular Contributor
timestamp: April 12, 2018, 09:18:38 am
content: Hello, I would like to interface LED with microcontroller.Basically, we can connect LED with the microcontroller in two configurations.Configuration 1: Connect anode of LED to external power supply(say 3.3 V) and cathode to microcontroller GPIO with a series resistor. In this case, microcontroller sinks the currentConfiguration 2: Connect anode of LED to microcontroller GPIO and cathode to ground with a series resistor. In this case, microcontroller sources the current.What is the best configuration? Please tell the reason as wellThank you.

author: capt bullshot
author_rank: Super Contributor
timestamp: April 12, 2018, 09:25:00 am
content: In former days, your configuration 1 would be the choice. This is because back then, most logic outputs (including these on a uC) could sink more current than they would source. Another reason to do so are integrated pull-up resistors, that some devices had (and some still have), so the LED would glow dark while the port pin isn't initialized yet. The 8051 family is a good example for that.With most of todays uC, it just doesn't matter and it's up to your personal favour, since these output have similar to equal capabilities to source and sink. Beware of exceptions to this rule, always check the datasheets for hidden surprises ...

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 12, 2018, 01:01:07 pm
content: That's right.I would just add something. One reason that can make configuration 1 preferable in some cases (and making sure the µC doesn't source any significant current from its IOs in general) is that it allows to measure its own current draw directly.

author: Ian.M
author_rank: Super Contributor
timestamp: April 12, 2018, 02:08:26 pm
content: There's no getting around the solid state physics. Typical electron mobility for Si at room temperature (300 K) is 1400 cm2/ (V·s) and the hole mobility is around 450 cm2/ (V·s). That means that if other parameters are as near identical as possible, a P-MOSFET will typically require three times the die area to get the same Rds_on performance as a N-MOSFET. Of course the IC manufacturers tweak the parameters of their P-MOSFETs as far as possible to better match their N-MOSFETs, but die area costs money, and the remaining extra area for the P-MOSFETs may be significant in smaller MCUs or ones with a lot of I/Os, so its not unusual to find a residual asymmetry that still favours using the output to sink current rather than source it. Often the asymmetry is buried deep in the datasheet - e.g. the logic '1' output voltage when loaded may be quoted at a lower sourcing current than the equivalent logic '0' parameter's sinking current.

author: ajb
author_rank: Super Contributor
timestamp: April 12, 2018, 02:28:16 pm
content: Even so, modern LEDs are so efficient that usually just a couple mA are required for perfectly adequate brightness for indication purposes, so either way will work. You can even do both at the same time--connecting two LEDs with their own current limiting resistors in series across the supply and connecting an IO pin in the middle gives you two LEDs on a single pin. I've done this on the debug lines for really pin-constrained projects.

author: Ian.M
author_rank: Super Contributor
timestamp: April 12, 2018, 02:40:09 pm
content: Yes, its less of a problem with modern high efficiency LCDs. It still comes up if you are multiplexing them and leads to common anode with an external high side transistor (preferably a P-MOSFET) per anode output being favoured, as the extra sinking capability is often just enough to avoid the need for external cathode driversThe two LED trick is good for bench use and even for production, as long as there is plenty of margin between the total Vf and the supply voltage. If the supply rail rises too close to the total Vf, they start glowing noticeably in the dark!