0
\$\begingroup\$

What would happen to a gpio pin set as high output if the pin already see a voltage higher than the MCU's voltage? Lets say 3.3V vs 3.4V

I will probably solve this with a diode and using one extra gpio pin, but I got curious. How will the internal circuitry of the gpio react to a small over-voltage?

For the long story: I have two signals controlling the same point for a power enable pin. One gpio from a battery powered esp32 at 3V to 3.6V range. The other is from a voltage divider from USB 5V, and this will also have a voltage range, since every usb port is not the same. The resistance is almost 100k, so the current is probably too low for anything to happen anyway, or is it? The MCU also want to measure the usb voltage to boot in to other code if the device is powered from usb instead of the battery, so a diode for that pin does not work. I am short on space, so it would be neat if these two things could be connected on one gpio pin.

enter image description here

On-button turns the circuit on, and the MCU can decide on its own when to turn off. With USB connected, the circuit is always on

Link to Falstad circuit.

\$\endgroup\$
6
  • \$\begingroup\$ The datasheet was fuzzy on the subject. I expected to find a Vdd+0.3 V rating on the IO pins. \$\endgroup\$
    – winny
    Commented Apr 29 at 15:04
  • \$\begingroup\$ yeah, the datasheet is only for input characteristics aswell, and the internal gpio circuit for input and output are not the same \$\endgroup\$
    – ISbit
    Commented Apr 29 at 15:05
  • \$\begingroup\$ I don't expect a problem there, but are there transient states where the MCU has no supply and the voltage divider is active? \$\endgroup\$
    – Jens
    Commented Apr 29 at 15:18
  • \$\begingroup\$ hmm, the voltage divider can enable the power enable pin, that will give power to start the mcu. This would put voltage to the gpio before the mcu has started. I think that state should be perfectly fine, as the pin would be in high impedance state at that point right? \$\endgroup\$
    – ISbit
    Commented Apr 29 at 15:37
  • 2
    \$\begingroup\$ @ISbit Can you give the exact schematics? It is more efficient than a few words. Also will the MCU be powered or not, at what supply voltage? \$\endgroup\$
    – Justme
    Commented Apr 29 at 16:23

1 Answer 1

0
\$\begingroup\$

What would happen to a gpio pin set as high output if the pin already see a voltage higher than the MCU's voltage? Lets say 3.3V vs 3.4V

I'm assuming the GPIO is set to push-pull output (Open drain, a.k.a. Hi-Z, is another output config).

The output section of a push-pull output GPIO is a CMOS totem-pole buffer.

When the output is driven the pin will be connected to either rail (depending on whether the output is HI or LO) through a relatively low resistance which is the buffer transistor's equivalent resistance (The actual value depends on the chip but is usually less than 50 Ohms).

So, if the output is HIGH the external network and the output buffer will form an adder (a.k.a. summer). As you might expect, the net voltage will be dominated by the side having the lowest output resistance, in your case the MCU methinks. So the pin voltage will still be 3V (for 3V MCU supply voltage and 4.75~5.25V USB voltage).

But...

A non-zero current (in the order of microamps, you can calculate by yourself) will flow into the pin, through the high-side equivalent resistance (GPIO output driver MOSFET), out of the VDD pin and back to the source (battery, in your case). If the current coming out of the battery (i.e. load current) is already that low (or even lower) then the reverse current will win and the difference current will flow back to the battery. So, if the battery is a non-rechargeable one then this could be a problem, otherwise the USB port will recharge your battery with very low current.

If the GPIO output is set to zero whilst the external network is still connected then a current set by the external network's equivalent resistance will flow into the pin.


One other thing to consider here is the start up i.e. the GPIO's default (or reset) config. For some MCUs the GPIO pin is set to Hi-Z input at power-on reset and it'll stay such until it's configured for something else. So, if the external network will be present at power-up you may want to check the default config. If it's input then, as long as the voltage seen by the pin is within the ABS max ratings, it's fine.

\$\endgroup\$
5
  • \$\begingroup\$ When MCU output is high, they generally are not intended to being pulled up to higher voltage than MCU supply. \$\endgroup\$
    – Justme
    Commented Apr 30 at 12:56
  • \$\begingroup\$ @Justme true but the net voltage seen by the pin's input buffer will still be 3V assuming the GPIO output resistance is negligibly low compared to the external network's equivalent resistance. The biggest problem I can think of is that a non-zero current (in the order of microamps) will flow into the pin whilst it's outputting HIGH. Maybe I should add that details as well. \$\endgroup\$ Commented Apr 30 at 13:21
  • 1
    \$\begingroup\$ The voltage divider would then need to be set to the battery's max voltage, for the usb-ports max voltage. To not overcharge the battery. There should ofc be some protection circuit for the battery, but still not ideal to risk it. I ended up putting the control from the usb-port on a separate pulldown transistor instead of blocking diode, it saved more space on my board \$\endgroup\$
    – ISbit
    Commented May 2 at 6:43
  • \$\begingroup\$ @ISbit The voltage divider would then need to be set to the battery's max voltage no, the battery's minimum voltage or even lower, so that the GPIO output always wins. If you set the divider's voltage to the bat's maximum then as the battery drains the external voltage will become larger so a non-zero current will flow into the pin and back to the battery which is a thing you don't want to happen. \$\endgroup\$ Commented May 2 at 6:49
  • \$\begingroup\$ @RohatKılıç, right, the minimum voltage to not cause a reverse current for sure! I meant for the worst case, if the divider was used as in the topics question. It would charge the battery slowly, and the charging would stop at the dividers output voltage \$\endgroup\$
    – ISbit
    Commented May 2 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.