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.

I’m sorry, but I still don’t see it. When I power off the battery will be removed from the circuit.
I have added the switch for clarity

follow my thinking. Because I left out an important point. Your on/off switch must switch the base of the transistor/s. If you stick the switch between the positive side of your battery and the diode the capacitor will slowly discharge through the base. I tested it with a 3300uf capacitor just using a 5ma led load and the circuit was powered for at least a minute compared to barely a second if the cap supplied the led as well. You are still using the battery to power any load connected until the cap has discharged throught the base-emitter circuit.

This definately will work. If you still don't follow me I am happy to try to explain further.

But you said the capacitor supplied enough current to finish a write to the micro sd. But when you mounted it in the unit there was a higher power consumption due to the gps etc. The transistors will use less current from the capacitor to stay on compared to the consumption of the whole circuit. You are still feeding the circuit from the battery until the capacitor discharges through the transistor. This current is not feeding the whole circuit however only the base current to hold the transistor on.Seeing as you are switching the ground rail you could ditch the second transistor and switch the ground rail with the first transistor. Even less current required from the capacitor.

Am I misunderstanding you in that the 9 volt battery is required in the original design? It's just that you didn't mention it until you found out the capacitor had not enough current to supply the complete circuit in the prototype.

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.

 

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 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.

Mech

 

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.

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!