Author Topic: No Floating GPIO Inputs on MCU?  (Read 2554 times)

0 Members and 2 Guests are viewing this topic.

Offline pacmannTopic starter

  • Contributor
  • Posts: 39
  • Country: jp
No Floating GPIO Inputs on MCU?
« on: March 12, 2023, 11:37:14 am »
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? Cheers

If it was a floating pin issue, I think it would've been present in all boards and I wouldn't have the one with 2uA.

No, floating pins float to whatever voltages, even gigaohms of flux residue can resolve the levels close enough to Vcc or GND for this not to matter. But if the pins end up near the middle of the rails, and digital input stage is not disabled, large current (like hundreds of µA) will flow. You absolutely must make sure you don't have floating input pins.

It would be typical to see some boards working and some not due to floating pins, depending on what voltages the contaminations pull the pins to. If uncontaminated enough, then the pins will just pick up any random static charges (hence hovering the cat over the board changes things).
 

Online RoGeorge

  • Super Contributor
  • ***
  • Posts: 7332
  • Country: ro
Re: No Floating GPIO Inputs on MCU?
« Reply #1 on: March 12, 2023, 12:11:06 pm »
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.
« Last Edit: March 12, 2023, 12:13:17 pm by RoGeorge »
 
The following users thanked this post: pacmann

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6571
  • Country: es
Re: No Floating GPIO Inputs on MCU?
« Reply #2 on: March 12, 2023, 12:17:48 pm »
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.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: pacmann

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 9769
  • Country: fi
Re: No Floating GPIO Inputs on MCU?
« Reply #3 on: March 12, 2023, 12:40:20 pm »
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.
« Last Edit: March 12, 2023, 12:50:16 pm by Siwastaja »
 
The following users thanked this post: pacmann

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2398
  • Country: us
Re: No Floating GPIO Inputs on MCU?
« Reply #4 on: March 12, 2023, 08:12:37 pm »
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.
 
The following users thanked this post: thm_w, pacmann

Online PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 2347
  • Country: au
Re: No Floating GPIO Inputs on MCU?
« Reply #5 on: March 12, 2023, 11:55:12 pm »
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? Cheers
That's a system design question.
Certainly, you want to avoid a digital pin floating input, as the digital pin buffer has 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.
 
The following users thanked this post: SiliconWizard, pacmann

Offline Chat GPT (2)

  • Newbie
  • !
  • Posts: 5
  • Country: cn
Re: No Floating GPIO Inputs on MCU?
« Reply #6 on: March 14, 2023, 11:12:01 am »
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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf