I've seen this circuit used in several ESP32 designs (e.g. the Sparkfun ESP32 Thing) and in an answer on this site that allows a device to be powered by either 5V from a USB connection or a battery. V_OUT
shown in the schematic usually goes to an LDO to convert 5V to 3.3V.
I'm clear on what happens when just the USB is connected: power goes from VBUS
through D1
and out V_OUT
. The p-channel MOSFET M1
is open.
When USB is not connected and a battery is, the 10K pulldown resistor pulls the MOSFET gate to 0V, and current flows from V_BATT
through the MOSFET's body diode which causes the voltage at V_OUT to be higher than the gate, so the MOSFET channel closes and conducts (I hope this is the correct interpretation of events, please correct me if I'm wrong).
What I don't understand is what happens when both the USB and V_BATT are connected simultaneously. I expect the gate voltage to be high enough that the MOSFET channel doesn't conduct, but I also expect some current to flow through the body diode from drain to source. Is this what happens? Is this in some way bad or harmful to the circuit?
If I wanted to create a circuit to switch between one or the other supply exclusively, but prefer the supply tied to the gate (i.e. VBUS
), is a p-channel enhancement mode MOSFET the correct part to use?
simulate this circuit – Schematic created using CircuitLab