Author Topic: What is best configuration to connect LED to micro controller ?  (Read 1076 times)

0 Members and 1 Guest are viewing this topic.

Offline Sai tejaTopic starter

  • Regular Contributor
  • *
  • Posts: 51
  • Country: in
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 current
Configuration 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 well

Thank you.
 

Offline capt bullshot

  • Super Contributor
  • ***
  • Posts: 3033
  • Country: de
    • Mostly useless stuff, but nice to have: wunderkis.de
Re: What is best configuration to connect LED to micro controller ?
« Reply #1 on: April 12, 2018, 09:25:00 am »
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 ...
Safety devices hinder evolution
 
The following users thanked this post: Sai teja

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15103
  • Country: fr
Re: What is best configuration to connect LED to micro controller ?
« Reply #2 on: April 12, 2018, 01:01:07 pm »
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.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13012
Re: What is best configuration to connect LED to micro controller ?
« Reply #3 on: April 12, 2018, 02:08:26 pm »
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.
« Last Edit: April 12, 2018, 02:10:45 pm by Ian.M »
 

Offline ajb

  • Super Contributor
  • ***
  • Posts: 2701
  • Country: us
Re: What is best configuration to connect LED to micro controller ?
« Reply #4 on: April 12, 2018, 02:28:16 pm »
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. 
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13012
Re: What is best configuration to connect LED to micro controller ?
« Reply #5 on: April 12, 2018, 02:40:09 pm »
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 drivers

The 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!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf