Oh, i can't wait to study your explanation. Let my MUC monitor itself the power is finally something i have not even considered (let's stay i focused on an electronic solution).
What do you call a slow fallback ?
Well, I spoke kinda of 2.
The first is the time it takes to turn the mosfet on after the plugpack is removed. (This is pretty easily modelled as it is in the normally used portion of the device's operating range.
This is not instantaneous and is the time it takes to transfer the gate charge across the gate resistor. Roughly, this can be calculated as Q/I, where I is the current that passes through the resistor at the battery voltage.
Picking a mosfet almost at random, 1/2 of an SI4505, it has a gate charge of 20nC and the current is (say) 3/100,000 = 30uA. So the time is just under 1ms.
A 100uF capacitor at 100uA will drop about 1mV in 1ms, so the voltage drop is not significant (however the drop will be higher if the MCU is in a period of higher current draw.
The second deals with a slowly dropping voltage on the plugpack. Perhaps it has been unplugged and the voltage falls to zero over a period of 10 seconds. This is a little more problematic because we're dealing with aspects of a mosfet's behaviour that tend to be variable and where we typically don't operate them.
As the voltage on the gate of the mosfet falls, the mosfet turns on... slowly. Mosfets in this mode act like a constant current source. So as Vgs(th) is reached, current starts to flow, and this increases as the gate voltage decreases.
[ASIDE: I'm talking about the gate voltage decreasing because the gate is eventually grounded, but what is actually happening is that the difference in voltage between the source and gate is increasing]
S0 as the voltage at the gate falls, Vgs increases. The
datasheet tells us that Vfs(th) for the P Channel mosfet is between -0.45 and 1.0 volts (I'm assuming they mean -1V). It also tells us that the threshold current for this P channel mosfet is 250uA -- which is way higher than our load! (This is telling me that this mosfet isn't actually a good one for this).
Let's assume that Vgs(th) is -0.8V. This means that the voltage at the gate only need drop to 0.8V below the battery voltage and already 250uA can flow. What we're really interested in is the voltage which allows 100uA to flow. And let's say that is -0.6V (I don't know). This means that as the power supply voltage drops to o.6V below the power supply, the battery can supply enough current for the MCU. But what iof it's 0.5V below it, and it stays there for some time?
Let's assume the battery has 2.7V across it, and our MCU needs 2.5V. The battery will not be able to supply 100uA until the power supply voltage drops below 2.2V. If it stays there (say at 2.4V) for too long, the charge stored in the capacitor will be exhausted, and the MCU will reset (and here is the point that software could try a last gasp of forcing the battery power on).
How long would that take? Who knows? It depends on so many variables that I wouldn't hazzard more than a very rough guess that the voltage would want to drop at about 1V/second or faster.
One way of making this faster is to reduce R1. This provides a load on the external power supply. A lower value here will discharge any output capacitors faster and cause the voltage to fall faster. You could drop it to 1k, for example to draw 3.3mA
Actually i have ordered pieces to mockup a relay (with a calculated capacitor to absorbate the 5ms voltage switch) + flyback diode. Notice any 100mA on external power pack is not a problem, but your solutions are what i consider a real hardware design, and my own totally lacks of skills/elegance.
You probably don't need a flyback diode in this case, but it can't hurt.
And reading about the problems of the slowly falling voltage, you might think that a relay would just be plain easier. You might be right.
HOWEVER...
The voltage that the relay pulls in is higher than the voltage at which it drops out. Added to this, the relay switches slowly if the voltage falls slowly. The first of these is more important than the second. If the relay holds in at a voltage lower than the MCU minimum voltage, the same thing can happen.
In the relay's defence, it will draw more current and (all other things being equal) will cause the plugpack voltage to fall faster.
I'll test on LTSPICE you own design to really understand the drawbacks and see if i can meet them. Need to understand what a MOSFET is, vs classic NPN/PNP.
Low current ? High speed switch ?
Many thanks Steve for theses toughts and help.
I'll not explain mosfets other than to say that they're voltage controlled devices and that they have a lower voltage drop across them at low currents.
Given that this circuit is getting more and more complex, it may actually be smaller and simpler to use a relay. The swap in the voltages from the plugpack to the battery having the highest voltage was really the killer.