3 ms·
True that: I know very few microcontrolers with overcurrent protection, you usually permanently disable a pin when draining too much current. I would still use
by MayeulC 5y ago
True that: I know very few microcontrolers with overcurrent protection, you usually permanently disable a pin when draining too much current. I would still use a resistor with it, though having the microcontroller supply the current is usually fine.
Protip: microcontrollers can usually absorb more current with pull-downs (due to n-mosfets, plus internal power supply routing) than they can supply. So have VCC -> res -> LED -> µC and turn the LED on by writing a 0 to the GPIO. Make sure the µC doesn't overheat, and you can drive a lot of LEDs (or other circuits) like this. Double check the datasheets for the max ratings, of course.
- tzs 5y ago> So have VCC -> res -> LED -> µC and turn the LED on by writing a 0 to the GPIO. For turning the LED off the obvious way is to write a 1 to the GPIO. But check the documentation for your processor. On many another way to turn the LED off is to change that GPIO from an output to an input. With the LED off you should have very little current through the GPIO but there usually is a little, and I believe that on some processors the "change it to an input" method will have a little less current. It probably won't be a big difference but when you are trying to squeeze as much runtime as you can out of a battery it can be worth it.
- MayeulC 5y agoGood point, I hadn't thought of that for this use! An input has a high impedance, which is to say a very large (giga-ohm) resistance to vcc/gnd: very little current will flow trough. Usually it's connected to the gate of a transistor, which can easily be damaged by high voltages (3V instead of 1.2 can be enough). You can achieve the same effect, but more resilient to high voltages, by switching the output pin to an open drain/open collector mode, which disable the pull-up (pmos) transistor. That gives you high impedance when the pull-down transistor is enabled (ie, 1 is written to the output). This can also be used to control high-voltage logic/LEDs with a low-voltage microcontroller. https://en.wikipedia.org/wiki/Open_collector https://en.wikipedia.org/wiki/Open_collector https://blog.stratifylabs.co/device/2013-10-21-Understanding-Microcontroller-Pin-Input-Output-Modes/ https://blog.stratifylabs.co/device/2013-10-21-Understanding...
- londons_explore 5y agoWhen trying to squeeze runtime out of a battery, you want all pins to be 0v or Vcc with no current flowing. That means that if you're connected to an LED, setting the pin to an input is a very bad plan. The voltage will sit around 1 volt, which will cause internal circuitry within the microcontroller to use substantially more current - in some cases multiple microamps (compared to nanoamps for some microcontrollers sleeping).