When our circuit can be powered by either an external USB power supply or a lithium battery, we need to make the following logic settings:
1. When the external power supply is used, the power supply of the lithium battery is cut off;
2. When the external power supply is disconnected, it is powered by a lithium battery.
Here is the circuit the author used when designing the circuit:
When VUSB is powered by USB, the MOS tube is not turned on, and VCC is equal to VUSB minus the voltage reduction of diode D1; when VUSB is disconnected, the MOS tube is turned on and powered by VBAT to achieve automatic switching.
Here, take VUSB as 5V USB power supply and VBAT as 4.2V lithium battery power supply as an example to analyze:
1. When VUSB is 5V, the voltage of PMOS G terminal is 5V, PMOS is not conducting, and the voltage goes directly to VCC through D1.
2. After VUSB is disconnected, the G terminal voltage of PMOS is pulled down to GND by R1, PMOS is turned on, and VCC is powered by VBAT.
At this point, some friends do not understand why the MOS tube can be turned on in this circuit. Here is a brief description. The ingeniousness of this circuit is that the existence of the parasitic diode of the MOS tube is applied. Before the MOS tube is turned on, the S terminal The voltage becomes VBAT-0.7V, so the S terminal voltage must be higher than the G terminal voltage, so the PMOS is turned on. After it is turned on, the parasitic diode is short-circuited and no longer works.
3. In actual work, we definitely hope that the battery can be charged when the USB terminal is powered on. It is enough to simply add a charging circuit here. In this way, the entire circuit can not only cut off the power supply of the lithium battery, but also charge the lithium battery. This circuit is used in mass production circuits. After everyone digests it, the test can be used directly.