Let's Make Robots!

Microcontroller UPS

I have the following problem.
I’m rebuilding my SEA RENDERING http://letsmakerobots.com/node/21098 project from two Arduinos to one FEZ Panda running .NET
In my original setup I had one switch for the main power and one for stopping the logging. The reason for this is that if one shuts down power when the system is writing to the SD card, you might end up with a corrupt log file or in the worst case a completely ruined SD card. In an attempt to remedy this I made the following circuit that worked great on the breadboard.

The thought behind the circuit is that when the 12V is removed the voltage regulator goes down giving me an interrupt on pin 5. The system flushes all data to SD and unmount it. The charge in the 4700uF capacitor gave me enough time to do that.
According to Murphy’s law “If a prototype functions perfectly, subsequent production units will malfunction.“ and that kicks in here.
The problem (I think) is that the prototyping was done on a micro SD with nothing else attached. In my boat I have a normal size SD and GPS, digital compass etc. attached. So it drains the capacitor to fast.

So this I what I want to do.
When the main switch is turned off the volt regulator gives me a signal. Then I would like to pull a 9V battery online and keep it supplying power until I pull a digital pin low and turn everything off.
So, the great minds of LMR, -is this possible? I think resorting to a relay will drain the capacitor to fast so there must be some other way. 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Use a reed relay like this one to connect the 9V battery into the circuit. After the 12V is stopped, the micro will get the interrupt, then it will turn on the relay that will connect the 9V in the circuit, thus powering everything. When you're done with the SD stuff, the micro can turn off the relay, thus disconnecting the 9V from the circuit and everything will shut down when the capacitor gets discharged.The advantage of a reed relay is that some of them use a small amount of coil current and are 5V, so you can just connect them directly to a microcontroller (with a clamping diode) instead of using transistors.


I must admit that I have never heard of a reed relay before, but this is very interesting.  Thank you!

you could use it in reverse of the way sumobots use their power on switch. Push the switch and after a delay a relay in parallel w/ a NO switch on the power rail would be turned off, thereby killing power to the circuit. When you want to turn it back on hold the NO switch to start again. At least it is a possibility based on what little I know of electronics.

You could use a NPN transistor with an appropriate resistor on the 12v power feed as a Not Gate.  When you lose power it would switch high, a pin could go high to trigger an interrupt and then uC could start the shutdown procedure.   Doing it this way you don't have to manually or through programming turn it off, because once the NPN (aka the not gate) is switched back on by the power feed it will switch off the 9v.  You may want to have another Not Gate to turn off the 12v when the 9v comes online so you don't fry anything, gotta keep the smoke in yanno.



How about using a pnp transisotr as a switch that has the base connected to the same line that the FezPin5 is connected to.

When the power goes out, the transistor is triggered and can supply components for a short time. 

Another thought is to have all of the components connected through npn's as on/off switches when power is supplied to pin5. When power is cut, those curcuits are cut as well, saving the power for the rest of the fez and sdcard. Mind you this is just a thought as I don't know how the rest of your board looks or if it's even something you'd want to play around with....or hey, maybe it doesn't make sense to do it this way....  :)

You're approach with the diode to a large capacitor is good for keeping everything connected at that node (where the diode's cathode and capacitor's anode meet) powered a little while longer.  This is because everything "upstream" from the diode will not discharge the capacitor because the diode is blocking current in that direction.  So obviously power just what's needed if possible, such as the microcontroller and SD card.

As for "power fail detection" you can probably get a much bigger head start to know that power is starting to go out by using a resistor divider and a comparator.  So I suggest a resistive divider (use high values so as not to waste much power) instead of a 5V regulator.  Pick your "threshold voltage" (Vth) at which you think power is bad and you want to shut down the system, say maybe 8.5V but it could be more or less.  If your comparator interrupts your microcontroller at say 2.5V (Vcomp) you can calculate your ratio of resistors R1:R2 (R2 is the resistor connected to ground) as (Vth - Vcomp) / Vcomp.  *simplify the eqn if you like :)

Only catch is you should really use a digital storage oscilloscope to capture the falling capacitor waveform (powering your SD card for those last 10's of milliseconds) so you know if you are really good to go or if a bigger cap is needed.

Perhaps this is the overkill, time consuming approach in full.  I like the 9V battery idea, or even a rechargeable backup battery!

The problem isn’t really power failure of the type that the battery gets depleted, then I would agree that monitoring the voltage would be a better solution. The circuit I need is related to the main power switch and how to power down the system in a controlled manner.
I really hope to not be dependent on timing as other things might get added to the system in the future. The optimal solution for me would be to have the system turn itself off when its ready and not by the lack of power.


What if you used a couple of transistors which would require a lot less current to stay switched on long enough for your purpose?

Sorry for my dodgy drawing. Would this work for you?

I must admit that I don’t quit follow you on this one. Where does the extra 9V power source come in? If we still are just draining the capacitor for power, what will the extra transistors do?

The capacitor is only supplying the base current to hold the transistors on for a time. This would be less current than feeding the whole circuit off the capacitor due to the gain of the transistors.