No Floating GPIO Inputs on MCU? - Page 1
Forum section: electronics / general

author: pacmann
author_rank: Contributor
timestamp: March 12, 2023, 11:37:14 am
content: Is there a "best" mode to put GPIO pins to get lowest power draw? A post in a recent question said to put all GPIOs to output high or low but not to keep them as input and floating. Whats the explanation for this? CheersQuote from: Siwastaja on March 05, 2023, 04:40:12 pm

author: RoGeorge
author_rank: Super Contributor
timestamp: March 12, 2023, 12:11:06 pm
content: In digital circuits, more energy is consumed during a transition from high to low, or from low to high than when a gate sits still. If a gate is constant low or constant high, the consumed energy is very, very small.If you let an input floating, then the electric hum from the surroundings (for example the mains hum, or some parasitic induced voltage from a nearby radio station, etc) those weak parasitic signals might make a floating input to capture the electric noise and flip repeatedly between high and low. With each flip, energy is wasted for no reason.Therefore, you can either pull-up or pull-down the input gate, so to permanently fix it's input as either high or low, so it won't flip like crazy from the surrounding parasitic. Or, you can set that pin as an output, thus making that gate sensitive to your software only, and insensitive to surrounding parasitic fields.

author: DavidAlfa
author_rank: Super Contributor
timestamp: March 12, 2023, 12:17:48 pm
content: Some mcus like stm32 have a special "analog" mode (Not related to the ADC) where everything becomes disconnected internally from the pin and I/O circuitry disabled, this makes the lowest consumption.Otherwise, better to set the pin as input, connected to gnd or using the internal pulldown resistor.

author: Siwastaja
author_rank: Super Contributor
timestamp: March 12, 2023, 12:40:20 pm
content: Shoot-through current through the complementary MOSFETs when the input signal is in the middle of the rails, so that both MOSFETs are somewhat conducting; basically a weak short circuit which achieves nothing. MCUs are designed so that this is not damaging, but it still consumes power.Two possible fixes: disabling the digital input stage completely (not always possible), or using any means to get the pin voltage near either GND or VCC. Internal pull-up, internal pull-down, setting pin as output outputting "hard" 0 or 1, tying it externally to GND or VCC "hard", or using external pull-up/pull-down resistor all work pretty much the same. Some configurations have disadvantages, for example if you hard-wire the output to GND then you must be careful not to ever set the pin as output in the firmware. Internal pull-up/down is usually the simplest and safest option.Note that the opening post's "You absolutely must make sure you don't have floating input pins" is in context of very low power gadgets. For something not low-power, having floating pins is not a huge problem.

author: Peabody
author_rank: Super Contributor
timestamp: March 12, 2023, 08:12:37 pm
content: I would just add that as far as the Atmega328P used in Arduinos is concerned, I've never been able to detect any difference in current draw that varied with the state of unconnected pins, whether INPUT, INPUT_PULLUP, or OUTPUT. They do power-down sleep at well under 1uA in each case. YMMV.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: March 12, 2023, 11:55:12 pm
content: Quote from: pacmann on March 12, 2023, 11:37:14 amThat's a system design question.Certainly, you want to avoid adigital pin floating input, as thedigital pin bufferhas a roughly triangle Icc-Vin current curve, only << 1uA within 500mV of the rails.Output hi or low is valid, but you need to consider the external and internal loads. Fighting a pullup or pull down resistor of course adds current.Another choice is to flip the pin to Analog mode, on a MCU that should disable the digital pin buffer.

author: Chat GPT (2)
author_rank: Newbie
timestamp: March 14, 2023, 11:12:01 am
content: Yes, there is a best mode to put GPIO pins to get the lowest power draw. When a GPIO pin is set to an output high or low, it is actively driving the pin to a known state, which means that there is no leakage current flowing through the pin. On the other hand, when a GPIO pin is set to an input and left floating, there is a small amount of leakage current that can flow through the pin, which can result in unnecessary power consumption.Leakage current is the current that flows through a transistor when it is in a non-conducting state. This current is typically very small, but it can add up over time, especially if you have many GPIO pins that are left floating.In general, it's a good idea to configure unused GPIO pins as outputs and drive them to a known state (either high or low). This can help reduce power consumption and improve the reliability of your system. However, you should be careful not to drive the GPIO pins to a state that could damage your system or any attached peripherals.Additionally, some microcontrollers and development boards have features that can help you reduce power consumption even further. For example, you might be able to configure the GPIO pins to operate in a low-power mode when they are not actively driving a signal. You should consult the documentation for your specific hardware to see what options are available and how to configure them.