As there is no VBAT pin on the ESP32-S3, as there is on the STM32, I want to connect a CR2032 battery to power the RTC when the 3.3V supply is not connected, in order to keep the RTC running. I have attached a circuit to switch between the main 3.3V supply and the VBAT supply. I would like experts to analyze my circuit to see if it will work properly.
Additionally, I want to connect the 3.3V supply to a GPIO pin that triggers an interrupt when the 3.3V goes low. Upon this interrupt, the ESP32 will enter deep sleep mode (with just the RTC running). When the 3.3V supply is restored, a high-level interrupt will wake up the ESP32.
Thanks for your response. I am attaching VBAT so that when I lose power for hours i can still able to keep the RTC.
I have changed the circuit little bit.
Now ESP32 will get supply straight from source, not from diode.
A MOSFET will connected to 3.3V power supply and VBAT connected to it's source.
When the power goes down. The Pchannel mosfet will provide power thorugh VBAT
If 3V3 is lost the circuit is supposed to switch over to VBAT. How will the ESP find out? And I assume you plan to enter sleep quickly or the CR2032 will be drained, how much current do the ESP use in this state? How do you prevent the peripherals from stealing power from VBAT? And finally, how will the ESP wake up when power is restored?
I am getting 5V1 from power supply and 3.3v from regulator regulating this 5V1 supply. VBAT is coming from CR2032. When I lost power from 3.3V I will get an GPIO Low interrupt from 3.3V at IO15. Insdie the ISR of this Low Level interrupt I will immediately put ESP32 to deep sleep (<10uA) only running RTC Timer.
When I get power again which is 3.3V. The GPIO15 will put an RTC Interrupt to wakeup ESP32 again.
I have also attached 220uF Capacitor in parallel 3.3V and Ground. So that this capacitor provide some power during switching, and prevent ESP32 to reset due to low voltage.
You would need two P-channel mosfets, with an inverter between the first gate and the second, so that only one can be turned on at a time. Take a look at the functional block diagram in the datasheet of the ICL7673. In fact, that chip would work well for you, but is quite expensive. Maybe someone knows of a less expensive chip.
Edit: No. If the 5V source is accessible, then you CAN use an N-channel for the second mosfet. You would drive both gates from 5V. But the N-channel would have to have a low threshold voltage - 1V or less. So I think your circuit will work, but I think I would flip the orientation of the P-channel so the body diode points to 3.3V-MCU. Then both body diodes would be pointing in the same direction, which forms a basic two-diode model, with the source with the higher voltage supplying the load. Then whichever mosfet turns on bypasses its body diode, so there's no voltage drop. You just don't want current to flow back into Vbat, so the P-channel's body diode should oppose that.
I think the N-channel in your circuit is oriented correctly even though it looks backwards. The body diode blocks current from flowing from 3.3V-MCU back into a dead 3.3V supply when the battery is supplying MCU.
Thanks for your response. Much appreciated. I did some research of high side and low side switching and mosfet orientation. I made one change and now I think it will work. Still require your guys recomendations.
I have also performed some simulation on proteus. Although the mosfets are different in simulation, but It proves the logic.
Well, I think you now have both body diodes wrong. Both should be pointing into the 3V3-MCU line (their cathodes should be connected to that line). The mosfets will conduct equally well in either direction when turned on, so that's not a problem, but the body diodes need to prevent current from the active current source from flowing back into the inactive current source. You have the mosfets wired as switches, but they are not switches. They are just diode bypasses when turned on.
Your simulation is not quite accurate. If 5V is absent, the 3.3v supply will also be absent. That's the output of a dead 3.3V regulator. What will its state be then? Will it be at ground? What prevents battery current from flowing back through the body diode to ground?
It's about a charger, so a slightly different situation from this one, but take a look at the mosfet orientation in figures 5, 6, and 7. It's a P-channel mosfet, but the orientation has the body diode's cathode on the load side. It's not oriented as a switch, but in the opposite direction. So I didn't just make this stuff up. And your N-channel should be oriented the same way.