Microcontroller UPS

I have the following problem.
I’m rebuilding my SEA RENDERING https://www.robotshop.com/letsmakerobots/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.

UPS.gif

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. 

Use a reed relay like this

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.

 

If you had a couple spare i/o pins …

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.

Why not use a Not gate

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

 

How about using a pnp

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…  :)

I think timing is key

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 :slight_smile:

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!

I must admit that I have

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

The problem isn’t really

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.

 

Npn and pnp?

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

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?

No extra supply needed

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.

I’m sorry, but I still

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

ups1.gif

Perhaps I am wrong

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.

If you just want to shut

If you just want to shut down properly, why do not try procedural way instead of engineering? I’m not sure about your limitations, but I’d suggest to use two extra pins: first for “shutdown” button which when pressed makes the program to unmount SD or whatever else you may need in future. After shutdown sequence complete, it would use other pin to light up “safe to power off” signal LED. Then you turn off main power switch.

How about shutting down

How about shutting down through software? Use a push button on an input to tell the system to finish up it`s business. When ready an output triggers a N.C. relay to open thereby removing power to the system. This gives you complete control of how it shuts down and you can easily add functionality into the shut down sequence when ever you want without worrying about timing.

A 2nd relay to latch the power button and prevent the system from starting up again after shut down would also be needed though.

A few options.

1 ) how about a voltage regulator with a shutdown function (like this http://ww1.microchip.com/downloads/en/DeviceDoc/22200b.pdf)  – the shutdown current is .01-.1 uA so you can size a cap to time the delay between disconnecting power to shutdown.  (This is similiar to merser’s suggestions)

2) Make a solid state switch with a built in time delay. small pic, push button, mosfet similar to this: http://www.pololu.com/catalog/product/750

3) Alternately can you put a diode between the cap and the gps so that the cap is not powering the GPS?

4) Super cap?

 

I’m sorry but I can’t see

I’m sorry but I can’t see your picture…

Odd, how about this?

Odd, how about this?

Untitled-1.jpg

Nope…Does anyone else see

Nope…

Does anyone else see the picture?

A bit of of over thinking I think

The problem or need is:

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

Possible solution:

You could use the main switch to switch between the 12v and 9v. I’d put some caps in to filter the spikes and dips in the power rail though.  I’m not really sure what all you are powering with the 12v and what code you are using to do shutdown, so I’m making the best possible guess.