2

In the answer for this question (Does my circuit need decoupling caps?) there is a transistor between the attiny85 and the led. I understand that if the mcu isn't capable of providing enough current for a sensor, you have to do it the way the schematic shows, instead of controlling it directly trough the mcu. But I think that is not the case. So, why? Is there any advantage?

pmiguelpinto90
  • 387
  • 3
  • 9

4 Answers4

4

There are several reasons for using a transistor like that. One is if the load (in this case, the LED) requires more current than a microcontroller I/O pin is capable of providing. Another is if the load is powered by a voltage significantly different from the microcontroller's power supply. Perhaps the microcontroller is powered by a 3.3 volt supply while the load is powered by 12 volts. Another reason could be to isolate the microcontroller from various secondary effects, such as back EMF in the case of an inductive load such as a motor or relay. It can also be useful to isolate relatively high current (but still within the I/O pin capability) but possibly high frequency signals that could cause ground bounce or similar issues, such as when the microcontroller is driving an LED with a high frequency PWM signal.

alex.forencich
  • 40,694
  • 1
  • 68
  • 109
3

Taking the context into consideration, he was probably just using a transistor to have something to decouple.

enter image description here

Otherwise:

Attiny datasheet states Absolute max current per I/O pin: 40mA, and source/sink capabilities symmetrical.

So, if you're going anywhere over 20~30mA you wouldn't want to drive the load with the MCU (50mA in his example).

Another possibility is when your load needs a Voltage rail higher than supported by the MCU (not the case in his example).

enter image description here

Wesley Lee
  • 7,844
  • 6
  • 35
  • 53
3

If the current you want to put through the LED is high, the output voltage of the MCU is not well defined. If the difference between supply voltage (at the edges of tolerance) and the LED voltage is small you may have a problem.

A transistor, driven hard into saturation, will have a very well defined forward voltage at typical LED currents. So if you care about reproducability the transistor could be better. Otherwise you might get one unit that has an LED current that is double or half the next.

At 10mA the output drop in the ATTiny w/5V supply is less than 0.6 or 0.7V depending on sinking or sourcing (it's not quite symmetrical). Using a MOSFET you can make that number almost zero- eg. AO3400 has <32m ohm Rds(on) with 4.5V drive, so at 10mA the drop would be 320uV.

One way to see if this is likely to be a problem (other than the proper way of running all the sums on a spreadsheet or whatever) is to note whether the voltage drop calculated to be across the LED series resistor (yes, there should be one!) is getting very low, say much less than a volt or two. This is more of a problem with 3.3V supplies when you want an LED that isn't red or IR.

Another possibility a transistor affords you is to run the LED from a higher or lower voltage- perhaps an unregulated battery voltage before a boost converter or an DC unregulated input before a buck converter or linear regulator. This can reduce the power dissipation in your regulator, at the expense, perhaps, of some brightness variation with the input.

Finally, if you want a high-reliability design- or one that must work over the military temperature range or worse- it's best not to run too much current through IC outputs. At the maximum rated current there can be enormous current densities on the chip (equivalent to passing thousands of amperes through an AWG20 wire) which can result in eventual failures (eg. metal migration) especially at high temperature.

Spehro Pefhany
  • 376,485
  • 21
  • 320
  • 842
2

In the case of a single visible-light LED and not much else there's no advantage if the MCU can handle the current required. However, if you have many LEDs connected then it may be possible to overload the port or even chip itself, and transistors or even a dedicated driver may be warranted.

Ignacio Vazquez-Abrams
  • 48,282
  • 4
  • 73
  • 102