Charging lithium battery while at the same time trying to use circuit didn’t quite workout, with problems like the circuit not turning on and the battery never finish charging. The battery is 3.7V and capacity of 300mAH. However I found the microchip app note on same issue. Here is circuit:-[![enter image description here][1]][1] [1]: https://i.sstatic.net/w94vD.png When USB power is applied at `Vin` this circuit will turn off `Q1`, and as long as`(Vin – D1 VF)` is above `(Vbat – Q1 VSD)` then the load will instead use power from USB through `D1`. This allows the battery to charge normally without any outside disturbances. The `Q1` is P channel MOSFET, but I am not able to understand the connection. Why source is connected to load and Drain connected to Vbat? It should be reverse. Which MOSFET should I select for this circuit, if `Vin` is `+5v(+/-0.25)` and Vbat is `+4.2V - 3.2V` what should be `Rdon` and `Vgs(th)` for this MOSFET. How to calculate above parameters? Also D1 is to prevent current flowing from the battery into the charging power source. `D1` should be a schottky diode. reverse leakage current of D1, which could be up to a few hundred microamp (schottky diodes are very leaky). This leakage current will create a small voltage at the MOSFET gate which, if high enough, could cause the MOSFET to not turn back on properly when the main Vin power is removed. How to overcome this? How to minimise the leakage current of D1, in the range of 1-10uA(or may be less). Any reference part?