If I could figure out how to add a schematic, I would; but in the meantime, here goes:
I have a microcontroller that usually runs from an AC power supply, but needs to run normally as long as possible during power failures. The microcontroller must turn the battery power off (killing the circuit) when battery voltage drops too low. I added a 12V battery and charger. The client also wants a report on battery health, so I added some extras to separately control the battery charger IC and the AC voltage applied to the main switcher.
A brief outline of normal operation: When AC voltage comes up, power MOSFET Q4 (IRF9510) is turned on (by the AC) and applies voltage to the switcher. The switcher turns on and provides 5V to the rest of the circuit. The microcontroller turns on, and turns on power MOSFET Q1 (also IRF9510), which is between the battery and the input to the switcher. The micro also turns on the battery charger (LM317, with the Vadj pin switched between values that do, and do not charge the battery) There are diodes to block undesired current flows through MOSFET Q4, the LM317, and MOSFET Q1. Q1 is actually driven by Q2, a 2N4401 level shifter that in turn is controlled by the micro.
At intervals, while running on AC, the micro switches the battery charger off, and measures the battery voltage. If the battery passes, there is a battery installed, and the test continues by turning Q4 off. This should cause the power supply to switch to battery power for the test duration. Afterwards, AC and battery charge are restored, and everything returns to normal. I have measured voltages around Q1 and Q4 during each step described above, and I see the voltages I would expect to see.
My test setup has the microcontroller and power supply on separate boards. If I power the microcontroller board from my bench supply, and use resistors as the power supply load, the microcontroller and power supply run as intended.
However, if I remove the lab supply and run the micro from the power supply, the program fails every time it tries to switch to battery power. I have set break points, so I know it is here, and not at the point where it decides the battery has failed and is supposed to shut down. (The shut down is working properly if the battery fails.) The failure is reported as an illegal breakpoint if I have the debugger connected. Without the debugger, the program resets and restarts from the beginning.
I have monitored the 5V with my (non-storage) scope; it looks OK. Nevertheless, I added caps anyway just in case I was missing a glitch. I got up to 10uF with no change in operation.
I removed the control line to Q2, and tied it to the 5V. This fixed the problem completely, but of course makes it impossible to turn the battery off at the end of charge.
So, I am out of ideas. It sure looks like a glitch, but I can't find it, or make it go away. Any ideas?