Another important thing: when Vee is connected, the MCU is powering a LED (permanently) and disable it when Vbb is connected.
I think when i'm switching back to Vbb, the LED is still powered, and will be unpowered on my next cycle - i have100ms cycle... - so the time the led is powered it creates a significant current sink. This is a really decent reason !
It may be better to power the LED from the Vee supply -- the same as the relay -- so it is not drawing from the capacitor.
Without the diode, I'm not sure how you are detecting the external supply, but it is quite reasonable to continue doing so.
You could also connect the power to an interrupt pin or poll it faster so you can react faster to a power switching event.
The time for the capa energie is t=RC right so a 20k load should last around 100ms, right ? Or t = RC would only be for capacitor charging through a resistor and not when the load is parallel to the capacitor ? Is there any better formulae ? I don't understand everything on wikipedia related to this.
In 1 RC time, the capacitor will discharge by about 63%. That's *way* too much in this application.
We're only wanting a very small voltage drop, so we can consider the current drawn to be constant and the rate at which the voltage falls is then linear.
For a constant current i amps and a capacitance C farads. and a voltage drop v volts (think 0.1 or so for this), then the time taken (t, in seconds) is t=(Cv)/i
So for a 0.1V drop on a 1000uF capacitor with 20mA, t = (1000e-6 *.1) / 20e-3 = 0.005 (and that's 5ms)
Note that this is the time from when the relay drops out. At the moment, the capacitor discharges to the voltage where the relay drops out (it might be 2V) and then the slower discharge starts. The schottky diode eliminates the load of the capacitor driving the relay.
Warming my oscilloscope, thank you !
Good idea, it's always good to be able to see what's going on.