Microcontroller shutting off because of brief loss of power, can a capacitor fix this?

There are possibly two things going on here, short glitches (ns to µs) and much longer supply dropouts (ms to s).

You always need a bypass capacitor accross power and ground of a microcontroller. This keeps the local supply steady despite quite large very short term variations in the current the microcontroller is drawing. These variations are too fast for the power supply to regulate away. Also, the traces back to the supply have enough impedance at the high frequencies of these fast current variations to cause local voltage fluctuations even if the main supply was totally steady.

The other problem of longer term power supply dropouts has to be handled with significant energy storage somewhere. After all, insufficient power is coming in for some period of time, and the local storage has to make up the difference temporarily. The best place to put this is before the regulator. Let's say your regulator requires 2 V headroom. That means it will continue to produce 5 V out as long as its input doesn't drop below 7 V. That's 5 V less than the nominal 12 V in. A large enough cap on the input can hold up the input voltage of the regulator for some time after the 12 V input suddenly goes away. Put a Schottky diode in series with the 12 V input, then the cap afterwards. That prevents the input going low from discharging the cap.

For example, let's say you put a 1 mF cap on the input of the regulator (in addition of course to the small high frequency caps required for basic regulator operation as specified in the datasheet). Since you didn't say what your current is, we'll arbitrarily pick 100 mA in this example. Let's also say the Schottky diode drops 500 mV at full current.

The cap is then charged to 11.5 V during normal operation, and can drop to 7 V before the 5 V supply starts to drop. (4.5 V)(1 mF)/(100 mA) = 45 ms, which is how long the cap can keep things running after the 12 V input suddenly goes away.


If it's really power supply dropping, you'll do better with a capacitor in front of the voltage regulator (isolated with a diode, if necessary). That will allow the voltage to drop more before falling out of spec for the micro.

For example (picking numbers out of the air) suppose your micro needs 5V, your regulator supplies 4.75V and your micro is guaranteed to work at 4.5V. And further suppose you're feeding the regulator with 9V from a wall wart and the micro and other stuff draw 50mA. And suppose the regulator drops out at 1.5V.

If you put a 1000uF capacitor after the regulator, the time it will hold up the micro is:

t = 1000uF * (4.75V - 4.5V)/50mA = 5ms

If you put it before the regulator, the time it will hold up the micro is:

t = 1000uF * (9V - 6V)/50mA = 60ms (about 12x longer)

I kind of suspect that this may be an EMI issue causing disruption of the micro program unless you have a strong indication that the voltage is actually dropping.


It is mandatory to have ceramic capacitors close (~1cm) to the MCU supply pins. This is practically true for all integrated circuits.

But if you have doubts why the MCU resets, they usually have registers showing why a reset occured. Some MCUs have a brown-out circuit onboard and the trip point can even be set on some of them.

Which MCU do you use?