paulv
Posts: 557
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Controlled Shutdown at Power Failure

Sat Jul 20, 2013 8:37 pm

[UPDATE] I have designed a new circuit for embedded applications and servers that need to be on 24x7, that is easier to build and more simple. It is for a large part based on the discovery process described below, but the link shows a complete HOW-TO using the latest developments for the Pi.
viewtopic.php?f=37&t=132201

My goal is to provide the means for a controlled shutdown of the Pi when there is a power failure.
There have been a few posts with similar topics, but not quite the same. At least none that I could find.

As we all fear, a sudden loss of power could possibly cause a corrupted SD card.
Because I did not have the proper means at the time, I must admit that while running my web controlled thermostat program for more than 6 months now, I've had to take the power away from the Pi to get it to do a restart several times. I've done that during testing and development as well, and I've never had a problem. (lucky me?)

But, as they say, I'd rather be safe than sorry, and my luck may be running out, so here we go.
[update] while working on this project, I did manage to corrupt the filesystem on my memory stick. I didn't use the SD card, only use that for booting, but still... I guess my luck ran out, and it proves you really need this kind of protection!

I put together a few elements of different designs and applications to come-up with a circuit I hope will work. One word of caution, I'm no longer a designer, and I have also not built the circuit yet. The purpose of this post is to solicit comments and improvements and come to a solid usable solution.

Below is the proposed circuit:
Shutdown Power Circuit.png
Shutdown Power Circuit.png (22.62 KiB) Viewed 34053 times
There are actually 4 building blocks, let me try to explain them one by one.

Block 1: The circuit around R2, R3 and R4 is put together to create a falling edge on a GPIO input when the 5V supply is no longer there. The software will get an interrupt, and we can wait for a second to see if it was just a glitch, or if we need to do a full shutdown. This period will take about 5-7 seconds, so we need to provide emergency power for that long.

Block 2: The charging circuit for the NiCd. (IC2, T1, D4, R1, D6 G1, C2 and C5). I found this circuit as a NiCd charger for multiple cells, but modified it somewhat. It works as follows. The LM317 is in constant-current mode, supplying a charging current to the AA Ni-Cad cell G1, through R1. D6 is there to block the discharge when there is no 5 V supply. When a cell is connected, the voltage drop over R1 causes T1 to be biased through D4. This results in about a 50uA current from the Adjust pin of the 317 to the AA cell, starting the constant-current mode. The charging current I is determined by R1. I have found that the charging current should be 1/32 of the capacity for top-off or 1/64 for maintenance (trickle-charge). Also 1/10 is safe to use. R1 is calculated as follows: (1,25V + Vsat {=0.1V}) / charging current I. For a 2200mAh cell, the maintenance charging current is 2200/64 = 34 mA, which makes R1 to be 39 Ohm, 1/4W. C2 and C5 take care of smooth charging and transients.

Block 3:The Step-Up DC-DC convertor around IC1. I selected the LT1073 because it works with a single 1.25 cell, and provides a 600mA continuous current, and a peak of well over 1A. It comes in a pre-configured 5 V output version, which is perfect.

Block4: is the power switch. Q1, a HEXFET will start to conduct when the gate goes low, caused by the absence of the 5 V. It then feeds the stepped-up 5V to the Pi. D2 blocks that towards the left. With a 2200 mAh cell, we should have plenty of time to perform a full shutdown, if not we can select a higher capacity (2700mAh) cell, or even go to two cells.

When the power comes back on, the Pi should do a normal wake-up from it's beauty sleep, perform a short boot and the Ni-Cd will start to recharge.

At least, that's the theory. I look forward to your comments and suggestions.

Note : I always try to use through hole parts, which determined the parts I've used. There are more elegant and better solutions, but I can't really use them.
Last edited by paulv on Sun Jan 17, 2016 7:02 am, edited 3 times in total.

User avatar
Tage
Posts: 287
Joined: Fri May 24, 2013 2:29 am
Location: St Thomas, Ontario Canada

Re: Controlled Shutdown at Power Failure

Sat Jul 20, 2013 9:28 pm

the main problem is that LT1073 does not have enough power handling capability to feed the Pi. if you look at the graph in the top right hand corner of the data sheet you see that it can only deliver 30mA to a 5V output when input voltage is 1.25V. you need a boost converter that can handle at least 5A input current if you use a single cell NiCd.

there is a typo in the schematic, drain and source of Q1 are swapped.

for a single cell charged from a stable 5V supply you could charge through a resistor and a diode. the 1/10th charge limit is a good choice, because you can leave the charger on forever, but the charge current does not have to be terrible accurate.

I will have a look to see if I can suggest another boost converter. the idea is good, you just need more power. because the Pi has some internal voltage drop in the fuse you may want to use a 5.2V supply to compensate for the small voltage drop in the Schottky.
--
( I did a quick search for a boost converter, but did not find a good replacement. if you use two NiCd cells in series it is much easier. For example LTC1872B would work. Correction: this controller does not handle such low input voltage )
Last edited by Tage on Sun Jul 21, 2013 4:29 pm, edited 1 time in total.

paulv
Posts: 557
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Controlled Shutdown at Power Failure

Sun Jul 21, 2013 3:46 am

Thanks Tage!

You've found an error in a published schematic on the internet. I just copied the IRF7526D1 connections that was used in another application. Oops!

With your comments, I revised the schematic. As I mentioned in the previous post, I like the LT1073-5, because it comes in an 8-pin DIP version and works with 1 cell. I borrowed this piece from another application, the Minty-Boost charger that can be found on learn.adafruit.com. They use the LT1302-5 with 2 cells but according to the information I found, the LT1073-5 supplies more current. Maybe I should revisit this chip again because we will need close to 1A for the Pi, WIFI dongle and whatever else is powered of the 5V.

Using two Ni-Cd cells is no big deal for me, so let's do that.

I've also changed the trickle-charge circuit per your suggestion, so it's a lot more simple. While looking at charging IC's, I noticed with the bq2002/F as an example, that they use C/2 for a fast charge, C/32 for a top-off charge and C/64 for a maintenance charge (trickle-charge).

In my situation, I only need the backup when there is a general mains power failure, which in our part of the woods only happens once maybe twice a year. (neighborhood power cables are all under ground) I think I'll go for the C/32 charge and try that out.

Here is version 2:
Shutdown Power Circuit V2.png
Shutdown Power Circuit V2.png (27.55 KiB) Viewed 34012 times

paulv
Posts: 557
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Controlled Shutdown at Power Failure

Sun Jul 21, 2013 4:52 am

Here is a schematic with the LT1302, as used in the Adafruit Minty-Booster project. This will deliver 500mA easily, but I don't know what the upper limits will be. According to the datasheet, up to 1A.

To reduce the current during a power failure, I will look into dropping the WIFI dongle supply. I hope I can switch that off to save some power. On the other hand, we're talking about 5-7 seconds, maybe this will work?
Shutdown Power Circuit V3.png
Shutdown Power Circuit V3.png (33.62 KiB) Viewed 34001 times

BudBennett
Posts: 89
Joined: Fri May 17, 2013 2:45 pm
Location: Westcliffe, Colorado, USA

Re: Controlled Shutdown at Power Failure

Sun Jul 21, 2013 3:14 pm

I, too, have a Raspberry Pi heating system that needs to stay operational after a power outage. I have given this problem a lot of thought. There are certain requirements for a circuit/system with this function:

0. Manage you reserve power source.
1. Detect the loss of power and signal the RPi.
2. Hold up the supply to the Pi for a short amount of time, 2-3 seconds, if the power has not returned after this interval then commit to a shutdown sequence. The Pi will need to debounce the loss of power signal. If input power returns during this interval then de-assert the loss of power signal and go back to step 0.
3. Hold up the supply to the Pi until it has shutdown completely - in my case this is about 35 seconds. If the input power returns during the shutdown period it must be ignored.
4. Remove power to the Pi after the shutdown has completed. If the input power has not returned there is no point to having the heating system running. I suspect this is the case with most systems powered via the mains. The Pi power must remain off for at least 10 seconds or so for the capacitors to collapse and allow the normal boot process when power returns. Alternatively, if there is a lot of reserve power available, just wait until input power returns and apply a "reset" or "reboot" signal to the RPi. (I find this to be impractical since the wait could be hours or days.)

Unless I'm missing something, I think that the circuit that you have designed so far has a few problems with regard to the steps outlined above. If the power returns while you are shutting down the Pi then it will return to its normal state and the Pi will be suspended - it won't reboot. The LT1302 has a SHDN pin - I suggest that you employ it to disconnect the Pi power after a suitable time period. Also, If your batteries are depleted they won't be able to respond to another outage within a reasonable amount of time. This is another good reason to disconnect the Pi sooner rather than later.

Here in Colorado it is lightning season. We're getting 2-3 power faults per week. Most of them seem to last between 0.5 - 10 seconds. During the winter months, when the heating system is needed, the power can go out for several hours, but not nearly as often.

I designed two circuits to address this controlled shutdown problem. Both of them use super capacitors as the reserve power source. (They also started out pretty simple, but have morphed into something a bit more complex.) One of them is working beautifully as a rather un-beautiful breadboard - but it has some issues I still need to fix, hence the other circuit. I found that the little white protoboards are a disaster when you are sloshing 1 Amp around the circuit - the connection resistance can be more than 1 Ohm. I ended up breadboarding using PCBs from OSH Park. Unfortunately the turnaround time is about 3 weeks per revision. If you wish I can post schematics of the current (and hopefully final) revisions here as well. I'm expecting the new PCBs in early August.

I'd like to see your circuit work as it is potentially simpler (and less expensive).

User avatar
Tage
Posts: 287
Joined: Fri May 24, 2013 2:29 am
Location: St Thomas, Ontario Canada

Re: Controlled Shutdown at Power Failure

Sun Jul 21, 2013 3:34 pm

paulv, I think the LT1302 will work. I simulated the circuit and found that it is necessary to add a voltage divider on the PMOS transistor to avoid that the output voltage drops too much when the 5V power goes away or re-appears. Unfortunately I also found that the 5V power needs to be 5.3V to compensate for the Schottky series diode. Otherwise, the circuit works even at higher current than 500mA.
I would adjust the voltage divider R5,R1 so that the PMOS gate is close to the threshold voltage but does not conduct current. One could look at the current draw from the battery and trim the divider so that no current is flowing when the 5V supply is present. There will of course be some variation in the 5V, so it is difficult to find the best values for the divider. it would not be good if the MOSFET turns on when the 5V just is a bit on the low side.

One difficulty is that many 5V supplies do not offer easy access to a voltage divider so that the 5V can be adjusted. Some chargers that I have looked at do have a voltage divider that you can access, and then it is an easy task to change the voltage to 5.3V. While doing this, a good idea is to check the output capacitor of the charger and change it to a higher quality part if necessary. Some of these cheapo ones have really cheap components inside.

BudBennett, you have some good points about sequencing. the circuit needs to be analyzed more in detail, and it may be necessary to add some simple logic to handle different scenarios.
Attachments
LT1302_paul.png
LT1302_paul.png (37.32 KiB) Viewed 33945 times

paulv
Posts: 557
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Controlled Shutdown at Power Failure

Sun Jul 21, 2013 3:46 pm

Hi Bud,
Thanks for the elaborate post.
Yes, you are absolutely right that the proposed circuit is not complete, but that was not my initial intend. I would like to get a handle on the battery operated emergency power first, because I believe that the other requirements can be bolted on to this core.

As an example, the Pi may not need a real powerdown sequence, I believe, if it is halted. This requires some residual power, but very little. I would need to experiment with this to make sure this is working, otherwise, yes, the shutdown may take a lot longer than then 5-7 seconds.

I have another post relative to this : http://www.raspberrypi.org/phpBB3/viewt ... 80#p379280

If the Pi is halted the way I do it in this post, all I need to do is to release the pin and it will do an abbreviated reboot.

With your inputs, we're moving in the right direction and I would like to have other people chime in as well.

I would be very interested to see your solutions, so we can benefit from your brainpower. Any chance on posting that soon?

One of my next steps will be to make some power measurements while halting or doing a shutdown procedure under various conditions. Without that information, we're shooting at a moving target. In the meantime, I would like to get to a working prototype so we can get a little closer a step at a time.

Please watch this post, and keep sending comments.

paulv
Posts: 557
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Controlled Shutdown at Power Failure

Sun Jul 21, 2013 4:04 pm

Hi Tage,

Thanks for spending the time to work on this circuit. You've made some real progress.

Because I power the Pi from the HVAC 24 VAC, with a circuit that I designed, I was already planning to use a different 5V regulator. Right now I use a fixed 5V switching regulator, but I purchased a little board around the LM2596S, and it allows me to set the voltage to what I want. One problem solved. Also, because my Pi is powered this way, there is no risk that the HVAC or the Pi can get out of sync. They both work, or they don't. Again simplifying something of the requirements list.

Back to the circuit. I found that the LT 1302 is not so easy to get. For $20 you can have it shipped from the UK, but that's rather expensive. Even purchasing it directly from LT is expensive if you want it delivered in Europe, which is where I am now. I may have to wait until I'm back in the US.

In the meantime, there is nothing in the way of making more measurements, as I mentioned in my reply to Bud. I can also design and test the circuit around the MOSFET. Just need to order some more parts and allocate some time...

I'll be back with more soon!

Thanks again.

User avatar
Tage
Posts: 287
Joined: Fri May 24, 2013 2:29 am
Location: St Thomas, Ontario Canada

Re: Controlled Shutdown at Power Failure

Sun Jul 21, 2013 4:39 pm

the gate control of the MOSFET is an issue. perhaps adding a comparator to monitor the 5.3V and controlling the gate of the MOSFET would give less of voltage dips. the problem is that if the 5.3V moves slowly, the MOSFET turns on and off slowly, so it is possible that the output voltage drops too low.

I was looking at LTC4088 which handles charging of a single cell Li-Ion battery and has internal MOSFET and logic. it delivers a voltage that is about 0.3V above the battery voltage while charging and just below the battery voltage when discharging. one could add a synchronous boost regulator to the output voltage from the LTC4088, perhaps that would work.

BudBennett
Posts: 89
Joined: Fri May 17, 2013 2:45 pm
Location: Westcliffe, Colorado, USA

Re: Controlled Shutdown at Power Failure

Sun Jul 21, 2013 8:04 pm

This is my "Plan B" circuit, which I designed after a lot of frustration using the LTC4425 supercap charger IC. The 4425 is replaced with the LTC1541 - a simple opamp/comparator/reference IC, which is pretty easy to understand. There are still some issues/problems with this solution:

1. The supercaps are charged through D1, the big Schottky diode, which causes the current to fall off as the voltage across the diode decreases. Recovery charge times are long - 30minutes to 2 hours - to bring the supercaps to full capacity after a discharge event.
2. The circuit won't handle sequential power loss events at short intervals.
3. If the supercaps are at a low voltage, power won't be applied until they are charged to 4.6V, which may take a while.
4. Q5 won't handle the power dissipation required to charge the super caps below about 2V, so I pre-charge the super caps before placing the circuit into operation. Once the supercaps are initially charged then there is no further problem.
5. The super caps must be reasonably well matched to avoid exceeding the 2.7V abs max rating. I calculate that this would only happen when the caps were mismatched by nearly the worst case +/- 20%. My caps never get more than 100mV of voltage difference.
PulseCharger.png
Plan B holdup/shutdown circuit
PulseCharger.png (19 KiB) Viewed 33898 times
What this circuit does:

If the input voltage dips below 5V the 5VOUT line is held up by the two supercaps and the PowerFail signal is asserted. If input voltage returns to 5.1V within 2 seconds then 5VOUT is again powered by the input voltage and the PowerFail signal is low. If the dropout continues for more than 2 seconds then the condition is latched and the supercaps continue to power the Pi as it shuts down. When the voltage at the top of the super cap stack falls below 4.6V the 5VOUT line is disconnected and the RPi is powered down for 10 seconds. It stays in this state until input power is available. After the input voltage is above the voltage on the super cap stack for 10 seconds the 5VOUT line is reconnected to the input and the Pi boots. If power returns during the shutdown period then the 5VOUT line is still disconnected but is reconnected 10 seconds later and (hopefully) the RPi begins to boot.

The circuit draws less than 50uA from the super caps while in shutdown. This will drain 10mV from the super cap stack per day.

How it works:

Two 350F supercaps, connected in series between CTOP, CMID, and CBOT, are charged by a current limited wall wart having an open circuit output voltage between 5.1V and 5.25V. If the voltage at CTOP is less than 4.6V then U1/COMPOUT is low, disabling the 4415 diode2 and forcing U2/STAT2_B high. This causes Q4's drain to pull the gate of Q5 low (saving it from a fiery death) and collapsing the input voltage down to CTOP plus the forward voltage of D1. The short-ckt current of the wall wart charges the supercap stack. U1/COMPOUT is low so the 4415 diode2 and diode2 are disabled while the stack charges and the Pi is unpowered.

When the voltage at CTOP exceeds 4.6V, U1/COMPOUT goes high, which enables both 4415 diodes and power is applied to the Pi through the 4415 diode1. U2/STAT1_B goes low and PWRFAIL is de-asserted. The super cap stack continues to charge at a slower rate until it reaches a voltage about 150mV below the wall wart voltage. It is now primed and ready. U1/AMPOUT will slowly force the voltage across the two supercaps to be the same.

If the wall wart voltage drops 15mv below the CTOP, 4415 diode2 conducts and holds up 5VOUT. Since diode1 is not conducting the STAT1_B pin goes high and asserts the POWERFAIL signal to the RPi. The STAT2_B pin goes low to indicate that diode2 is conducting - R9/C5 provide the 2 second delay to EN1, which will disable diode1. If the wall wart voltage returns before diode1 is disabled then the circuit returns to normal operation, but once diode1 is disabled the power down condition is latched since diode2 is the only source of power and STAT2_B remains low. Q4 turn off Q5 to insure that the supercaps can't be recharged.

The super cap stack can provide power for long enough to allow the Pi to shutdown. It will keep draining the stack until the voltage reaches 4.6V, then U1/COMPOUT goes low and the 4415 diode2 is turned off, disconnecting power to the Pi. I can't predict how long this phase might take. In my situation it doesn't matter as long as it is at least 45-60 seconds but not longer than about 10-15 minutes.

U2/EN2B goes high causing STAT2_B to go high-Z which re-enables diode1 after about 10 seconds. If the wall wart voltage is restored then diode1 conducts and pulls up the 5VOUT line, setting PowerFail low, and we're back where we started.

Status:

I have breadboarded this and it is working well on a spare Pi system that I have for development purposes. I submitted a PCB design to OSH Park on 7/15 and am awaiting finished boards. If my "Plan A" circuit works as expected then I don't expect to populate these PCBs. If indeed the Pi can be halted in 5-7 seconds then the size of the super caps can be reduced by almost tenfold, reducing cost and recovery time.

PaulV - I would like to see more info on how you plan to implement the halt. I read your previous posting and saw a shutdown and a reboot command. Can you explain it more specifically - I'm kinda stooped when it comes to limpware.

I'll post the "Plan A" schematic in a bit.

BudBennett
Posts: 89
Joined: Fri May 17, 2013 2:45 pm
Location: Westcliffe, Colorado, USA

Re: Controlled Shutdown at Power Failure

Mon Jul 22, 2013 12:45 am

This is my "Plan A" circuit. A simpler version of this was posted here: http://www.raspberrypi.org/phpBB3/viewt ... 41&t=42956 but it did not work correctly.

These types of circuits are not for the newbie. I originally tried to breadboard it (simulation would have been preferred, but LT doesn't provide macro models for either IC) with a protoboard and immediately destroyed 3 LTC4425s due to latch up, I think. The large connector resistance of protoboards creates problems when relatively large currents, >1A, are involved. Both of these ICs have their GND pins only available as an exposed pad on the back side of the package. So I decided to learn how to design PCBs. This first PCB did not work - I was convinced that it was LT's fault. I complained to some of by old buddies at LT (I used to work there) and they put me in touch with the Design Manager in Boston, who straightened me out a bit. I feel more stupid, but this ckt has a better chance of working now.

No circuit is perfect. Here are issues that remain (that I know of):
1. Power is provided to the Pi even though the super caps are not able to provide backup power. A much more sophisticated approach would be needed to sense that the supercaps were near or at their float voltage in order to perform this function.
2. The circuit still won't handle sequential power loss at short intervals. It is much better than Plan B since it can recover in about 30 seconds with 1.3A of charge current. Fortunately this is not a significant problem from the power company.
HoldUp2-2s.png
Plan "A" hold up circuit.
HoldUp2-2s.png (15.17 KiB) Viewed 33860 times
What this circuit does (similar to Plan B):

Two 350F supercaps are connected between CTOP, VMID, and CBOT, and are charged to 4.95V. If 5VIN dips below CTOP the 5VOUT is held up by the two supercaps and the PWRGOOD signal is de-asserted, signaling the Pi of a power loss. If 5VIN returns to 5.1V within 2 seconds then 5VOUT is again powered by 5VIN and the PWRGOOD signal returns high. If the dropout continues for more than 2 seconds then the condition is latched and the supercaps continue to power the Pi as it shuts down. When the voltage at the top of the super cap stack falls below 4.75V the 5VOUT line is disconnected and the Pi is powered down for 10 seconds. It stays in this state until power is available to 5VIN. After 5VIN is above the voltage on the supercap stack for 10 seconds the 5VOUT line is reconnected to 5VIN and the Pi boots. If power returns to 5VIN during the shutdown period then the 5VOUT line is still disconnected but is reconnected 10 seconds later and (hopefully) the Pi begins to boot.

The circuit draws about 23uA from the super caps while in shutdown - a bit lower than Plan B.

How it works:

The first time that you apply power, R5 charges C5 to about 1V before the U1/EN1 enables the 4415 diode1, PWRFAIL goes low so Q1 is off and PWRGOOD is asserted. So it takes about 10 seconds after power is applied before 5VOUT goes high and power is sent to the Pi. U1/EN is tied to 5VOUT so the 4425 begins to charge the supercap stack (Q3 is off so Q5 is on), keeping the two supercaps balanced. The 4425 can't dissipate the required power to provide 1.3A of charge current (it is a linear charger) so it limits the current output to what generates 102C internally (the sucker gets hot). U1/PFOB, power fail (active low), is low so the 4415 diode2 is disabled while the stack charges. In order to supply power to both the supercap charger and the Pi you will need a >2A source at 5VIN. The super caps could take 15-30 minutes to charge to their 5V "float" voltage. After the supercaps reach 4.6V the PFOB signal goes high, enabling the 4415 diode2. Diode2 is active but won't conduct unless the voltage at 5VOUT falls below CTOP. The 4425 stops charging the supercaps when the voltage at CTOP is 4.95V.

If 5VIN drops below the voltage at CTOP, diode2 conducts and holds up 5VOUT. Since diode1 is not conducting the STAT1_B pin goes high and de-asserts the POWERGOOD signal to the Pi. The STAT2_B pin goes low to indicate that diode2 is conducting - R8/C5 provide the 2 second delay to U2/EN1, which will disable diode1. If the voltage at 5VIN returns before diode1 is disabled then the circuit returns to normal operation, but once the 4415 diode1 is disabled the power down condition is latched since diode2 is the only source of power and STAT2_B remains low.

Since PWRFAIL is high, Q3 and Q4 are on and Q5 is off. Q5 disables the 4425 from trying to charge the supercaps if 5VIN returns. Q4 shifts the threshold for U1/PFOB to 4.75V.

The supercap stack can provide power for long enough to allow the Pi to shutdown - 45-60 seconds. It will keep draining the stack until CTOP reaches 4.75V then PFOB goes low to indicate a power fail condition. This forces EN2_B high which disables diode2 and disconnects power to the Pi.

If 5VIN is restored then U2/EN1 is pulled up by R5/C5 and after 10 seconds the 4415 diode1 conducts and pulls up the 5VOUT line, asserting POWERGOOD, and we're back where we started. The charge current is not inhibited by the 4425 thermal limit so it will put out the full 1.3A and recharge the stack in a relatively short amount of time since it only has to replace 250mV of lost charge.

Status:

The PCB design was submitted to OSH Park on 7/19. The 3 boards should be in my hot little hands by the second week of August. I have 4 LTC4425 samples and 5 LTC4415 samples left. I will probably build only a single board.

nelly26
Posts: 1
Joined: Tue Jul 23, 2013 9:19 am

Re: Controlled Shutdown at Power Failure

Tue Jul 23, 2013 9:29 am

Hi BudBennett,

I work for a technology company and in one of our products we are using a Raspberry Pi, experiencing SD card corruption on power failure. With this problem we are faced with replacing SD cards on our beta trial systems across the UK.

We've read your posts and are very intrigued by your developments. We would like to know what type of code you are using to implement this, i.e python script, linux distro or is it a functionality of the pi?

We are in the process of testing the BeagleBone Black (with flash memory) to see if any data corruption occurs on power failure.

Apologies for what might seem a newbie post!
Thanks!

paulv
Posts: 557
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Controlled Shutdown at Power Failure

Tue Jul 23, 2013 12:35 pm

If you are experiencing SD card failures, I recommend you move the filesystem to a "stick".
This actually turns the SD card into a read-only device, preventing writing problems to the card.
According to other posts, the filesystem of the "sticks" seem to be better suited than those of the SD cards.

Have a look at my procedure to do that: http://www.raspberrypi.org/phpBB3/viewt ... 87#p373587
Success,

paulv
Last edited by paulv on Wed Jul 24, 2013 4:05 am, edited 1 time in total.

FM81
Posts: 518
Joined: Wed Apr 17, 2013 4:33 pm

Re: Controlled Shutdown at Power Failure

Tue Jul 23, 2013 2:53 pm

BudBennett wrote:0. Manage you reserve power source.
A 7,2V-NiMH-block does this in my case.
BudBennett wrote:1. Detect the loss of power and signal the RPi.
GPIO08 ...
BudBennett wrote:2. Hold up the supply to the Pi for a short amount of time, 2-3 seconds, if the power has not returned after this interval then commit to a shutdown sequence. The Pi will need to debounce the loss of power signal. If input power returns during this interval then de-assert the loss of power signal and go back to step 0.
I use a binary, which delays only 500ms, but source-code can changed to a longer period:

Code: Select all

/*
* lpoweroff.c:
* Poweroff if GPIO08 goes to HIGH-level
*/

#include <wiringPi.h>
#include <stdio.h>

int main (void)
{
  int pin_level = 10; // GPIO08 - in original layout and in REV 2
  int del = 500; //change delay here

  if (wiringPiSetup() == -1) return 1;

  pinMode(pin_level, INPUT);

  for (;;){
    if (digitalRead (pin_level) == 1) {
		delay (del);
		if (digitalRead (pin_level) == 1) system("poweroff");
	}
    delay(del);
  }

  return 0 ;
}
BudBennett wrote:3. Hold up the supply to the Pi until it has shutdown completely - in my case this is about 35 seconds. If the input power returns during the shutdown period it must be ignored.
Realized this via a second line (GPIO00). And "old-style" with an R-C-combination and an OP.
BudBennett wrote:4. Remove power to the Pi after the shutdown has completed. If the input power has not returned there is no point to having the heating system running. I suspect this is the case with most systems powered via the mains.
The relay makes "click" around ten seconds after pi is down.
BudBennett wrote:The Pi power must remain off for at least 10 seconds or so for the capacitors to collapse and allow the normal boot process when power returns. Alternatively, if there is a lot of reserve power available, just wait until input power returns and apply a "reset" or "reboot" signal to the RPi. (I find this to be impractical since the wait could be hours or days.)
This is the only part, I've NOT included ... How ever, if main power is back, my pi starts, but the "safety range of 10 s" isn't definied.
http://www.raspberrypi.org/phpBB3/viewt ... 9&p=333336

MfG, FM_81

PS: OK, moving ROOT to USB makes sure, that your SD-card will not go corrupt! :) But every filesystem (mounted rw) can have such problems if you simply cut power! May be, an USB-stick is not so sensitive, but in general you are only moving the problem to another point ...
A: What does the command 'cat /dev/urandom', can you tell me please?
B: Yeah, that's very simple: It feeds your cat with radioactive material!

BudBennett
Posts: 89
Joined: Fri May 17, 2013 2:45 pm
Location: Westcliffe, Colorado, USA

Re: Controlled Shutdown at Power Failure

Wed Jul 24, 2013 2:36 am

I want to address the last post by Tage. I have somewhat radical idea: Why not just let the Schottky diodes handle the load switching? There are already two of them and their cathodes are tied together. Don't use a switch. Here's a schematic of what I'm talking about.
LT1302.png
Modification of Tage's last circuit without switch.
LT1302.png (18.16 KiB) Viewed 33671 times
The LT1302 is pretty low current drain. If you yank up on its output it should turn off and wait for the output to come back down. This appears to work (simulation of macro model) here's the input and output voltages. The nice thing about this is that a slow drop rate on the input is a good thing - it gives the LT1302 more time to respond. I tested it with faster (20us) edges on the input voltage and it behaves similarly. Minimum output voltage is around 4.75V. I don't know why it is so low (yet) the LT1302-5 should hold the output at 5.0V.
BackupTrace.png
Simulation of Vin vs. Vout
BackupTrace.png (60.44 KiB) Viewed 33671 times
In this configuration the only way to disconnect the load is with a series switch. There will be a drop associated with the output FET switch. Note the the FET switch has to be back-to-back to keep the bulk diode reversed.
Last edited by BudBennett on Wed Jul 24, 2013 2:45 am, edited 1 time in total.

BudBennett
Posts: 89
Joined: Fri May 17, 2013 2:45 pm
Location: Westcliffe, Colorado, USA

Re: Controlled Shutdown at Power Failure

Wed Jul 24, 2013 2:44 am

Nelly26,

I am using a Python script to debounce the GPIO input and shutdown the Pi.

Go to this link: http://raspi.tv/2013/how-to-use-interru ... pio-part-2

It should answer all of your questions. The only other thing that I did was to create a bash script in /home/pi/.config/autostart that initiates the program at boot. I put it there because I can back it up without being root.

User avatar
Tage
Posts: 287
Joined: Fri May 24, 2013 2:29 am
Location: St Thomas, Ontario Canada

Re: Controlled Shutdown at Power Failure

Wed Jul 24, 2013 3:58 am

"I want to address the last post by Tage. I have somewhat radical idea: Why not just let the Schottky diodes handle the load switching? There are already two of them and their cathodes are tied together. Don't use a switch. Here's a schematic of what I'm talking about."

your idea is not bad, it is worth looking into it. here are my comments:

- the schottky diodes have about 0.3V voltage drop while under load. so the "5V" has to be at least 5.3V plus some margin to allow for the variations in the 5V set point for the controller. your 5.4V is a good choice.
-the controller will see that its output voltage is a bit higher than the set point, so it reduces the current by pulling down its VC node. all is well.
- when the 5V (5.4V) drops, the output voltage will fall and the controller will notice that the voltage dropped below the setpoint, so it tries to increase the output current to meet the demand by increasing VC node voltage. this will take some time, because the VC node was at its lowest point, and the compensation capacitor has to be charged in order to allow VC to move upwards to the point where output current is flowing. the VC node is quite weak and can only supply a small charge current.
this is what causes the output voltage to drop too much. there is a recovery delay until the regulator can provide the load current. meanwhile, the output capacitor is being discharged.

a workaround may be to force VC node voltage to a voltage that is barely low enough to keep current from flowing when the 5V input is present. you can try to reduce the compensation capacitor C3 as much as possible. you can also try to increase the size of the output capacitor C1 , to give the controller more time to respond.

one way to charge the compensation capacitor close to the voltage it will have when the battery is delivering power is to simply add a resistor from 5V to the top of the compensation capacitor. (first, move the compensation capacitor C3 so that it is connected to GND and the compensation resistor R1 is connected to VC). the pullup resistor is selected so that it creates a voltage across the compensation capacitor that keeps it charged to the normal operating point at say 500mA load.

the VC node can then be held low through the voltage drop in the compensation resistor so there is no output current, but the capacitor has some voltage across it. when the 5V goes away, the current in that pullup resistor goes away, and the VC node jumps to close to the operating point (the compensation capacitor voltage), so current is immediately delivered without the normal delay. magic.

this is just an unproven idea, I have not tested it. I encourage you to try it in real life, or in simulation. the simulation models are quite accurate, even if they are simplified compared to the real components (so that the simulations will run faster).

:)
Tage

paulv
Posts: 557
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Controlled Shutdown at Power Failure

Wed Jul 24, 2013 5:39 am

I think we're making good progress. I waisted quite some time on the switching between the 5V supply and the souped-up battery supply, even used an Opamp as a comparator, but the easy solution did not stare me in my face. Good job Bud!

I was intrigued by the other tips from Tage, so I adjusted the circuit I was working on, around the variable output version of the LT1302. It maybe the simulation model, but I don't get the same symptoms on the output sag.
Shutdown Power Circuit V4.png
Shutdown Power Circuit V4.png (43.39 KiB) Viewed 33634 times
Shutdown Power Circuit V4 sim.png
Shutdown Power Circuit V4 sim.png (43.15 KiB) Viewed 33634 times
Playing with the suggestion to connect the junction of R4/C3 to the 5V supply did not bring me any improvements. With this setup, it is important to have an adjustable 5V supply, because the level of the 5V is important in relation to the LT1302 power supply. If the 5V is set too low, the battery supplies the difference. With this caveat, I begin to like it the way it is right now, if only the real thing would do the same...

I do not like the idea of cutting power to the Pi all together, because I think there is an easier way to accomplish what is needed, by just asserting the halt pin of the SOC, through P6. More below.

In the meantime, I made some timing and current measurements on my Pi setup. I used a revision 2 Pi Model B.
I use an Intenso 8Gb stick, and I offloaded the OS to the stick.
I also use an EdiMax WIFI dongle to run my Pi headless.

To measure the correct voltages and currents, I used an adjustable supply built around the LM2596S, which is fed by a 12VDC 2A supply. With this I could easily set the 5 V to whatever I wanted.

I used a Fluke DMM and a Fluke 123 digital scope, and the stopwatch of my wristwatch.

I ran the Pi headless and tried a few iterations of the shutdown command, and settled on

Code: Select all

sudo halt
and

Code: Select all

sudo poweroff
The current consumption of my Pi settled around 440mA, after swinging between 500mA and 414mA during the boot process.
When I issued the sudo halt command, it took somewhere between 25 and 33 seconds for the current consumption to drop to around 111 mA, although I have also seen 88 mA.

To wake-up the Pi from it's beauty sleep, you can assert the P6 jumper by momentarily connecting the two pins. (SOC Halt pin to ground). The Pi then performs an abbreviated boot process.

What that means for our power failure project is that we need to maintain the full current consumption of about 500mA for about 35 seconds, after which we can assert the halt, and then maintain the 115 mA for as long as possible until power returns. If power does not return, the Pi powers down completely and will do a normal reboot when power returns. To protect the batteries, power can be cut before they die by asserting the SHDN pin of the LT1302, which is currently not used in the models.

An external R/C circuit can keep the halt pin low during a main power return, and release it after a certain "debounce" period has been satisfied. This I believe should avoid the switching of the power to the Pi.

To enter the shutdown process, the 5V supply can be monitored through a GPIO pin. Examples are in the posts below.

I have a separate post about using the halt pin : http://www.raspberrypi.org/phpBB3/viewt ... 74#p355974
And another one that uses a GPIO pin to assert the Halt pin differently: http://www.raspberrypi.org/phpBB3/viewt ... 37&t=48455
and finally one to move the OS to a stick : http://www.raspberrypi.org/phpBB3/viewt ... 59#p351659

With this we should have most of the building blocks I hope.
Back to you guys...

BudBennett
Posts: 89
Joined: Fri May 17, 2013 2:45 pm
Location: Westcliffe, Colorado, USA

Re: Controlled Shutdown at Power Failure

Wed Jul 24, 2013 4:52 pm

paulv,

Two things:

1. You can't save the batteries by asserting the SHUTDOWN pin of the LT1302 - there is a DC path from the batteries through the inductor and Schottky diode. You must put a series switch in there somewhere if you need to disconnect the batteries. I suggest it be located at the output. If you're concerned about the added voltage drop from the switch you can put the sensing voltage divider for the 1302 at the other end - the 1302 will servo out the drop.
2. Use a "real" coil for the inductor in your simulation. I found that most of the error that I saw at the output was due to the relatively poor load regulation of the 1302 when I used a full blown inductor model from one of the recommended vendors in the datasheet. It could also be a difference between the 1302 and the 1302-5, but I doubt it.

The 1302 clamps VC to allow for a quick startup - I did not think that there would be much improvement gained by presetting it.

BTW: This circuit could work well with a single supercap instead of the battery...but I digress.

Bud.

paulv
Posts: 557
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Controlled Shutdown at Power Failure

Sat Jul 27, 2013 12:01 pm

I worked on some more circuit components while waiting for parts.
(part suppliers must have a field day serving us Pi enthusiasts)

Below is the LTSpice circuit I've been working on. There are in fact several circuits on this diagram, all related to the safe and controlled power-up and power-down of the Pi when there is a power-loss.
PowerStartDelay-PowerOff.png
PowerStartDelay-PowerOff.png (38.15 KiB) Viewed 33471 times
Part1:
If we're concerned about a sudden power-loss, then we also need to take a sudden power-on into account as well. When there is a general power failure, the power does not always comes back nice and steady, but can seem to stutter. When the Pi is in the power off state, it can wait a few seconds after power comes back on, to have a safe(r) boot. The circuit around U1 creates a 10 second delay by holding the Halt pin of the SOC through jumper P6. The 555 is triggered by a negative edge through R3 and D1, and C1 starts to charge through R2. The 555 fires after the delay (R2 x C1) and pulls the gate of M1 high, releasing the Halt pin. The Pi can now safely boot.

Part2:
I want to have the ability to force the thermostat in the Halt mode by hand, if the Pi is not responding, and I have published a circuit around M6 and M8 in a previous post. Just look up a bit in this post to see the reference to the detailed description. In essence, when I push a button, M6 releases the suffocation of C3, which starts to load through R9. Eventually, M8 will start to conduct and pulls the Halt line low, and keeps it there, halting the Pi. The combination of M1 and M8 on the Halt pin allows for a simple sharing of the P6 Halt pin with the two circuits.

Part3:
If we are concerned to have a safe and proper power-down of the Pi when there is a power-loss, we need to recognize a loss of power. This is accomplished through D3, R10 and R11. A negative edge is produced when there is a power-loss. D3 is connected to the 5.4V, which is indirectly coming from the 24VAC, coming from the HVAC, coming from the mains. (we have 5.4V to compensate for voltage drop losses, not all parts are shown here) R5 ensures a stable output of the 555. The negative edge triggers the 555, and R4 and C2 are selected to create a delay of about 55 seconds. I have found that it takes the Pi somewhere between 25-29 seconds to come to a power-down or Halt state after a power-down or Halt signal is asserted in software. The timing is depending on many things, so let's play it safe.
The resulting signal is available at the Drain of M2.

Part4:
In the previous posts, you have seen the development of a circuit emerging that can provide emergency power when the mains is down. There are three choices to make however. You can run the batteries down and hope power returns before they are empty. The problem with that is that with a simple trickle load for the batteries at C/30 or C/60 or even more, it may take days for them to fully recharge. We may not be ready for the next power-loss situation. Option two is to create a more elaborate charging circuit for the batteries, but I'm concerned about the extra real-estate it will take, and we may still not be ready. So option three is to switch off the power to the Pi after it has reached the Halt or Power-Down state. This only needs about 30 seconds of about 500mA, and in the remaining 20 odd seconds when the Pi is Halted, it only draws 110mA. With this we can go though several power-loss cycles without depleting the batteries.

So, now we need to find a way to shut-off the power to the Pi.
This is done through the MOSFET switch around M3 and M4, a portion BudBennett designed (see post above), which is driven by M7. All seems well, BUT (big butt). When the 555 gets triggered, the output goes high, to go low again after the timing period. This causes a problem with the switching of M7. After some trial and error, I have selected to use M5, which is driven by a GPIO pin. As soon as the Pi detects a falling edge on the GPIO pin connected to the 555 Trigger, the software should acknowledge this by driving the GPIO pin connected to the gate of M5 low. This pin should be set high soon after booting the Pi, or you can use one of the GPIO pins that are set high by the Pi at start-up. (they are the special pins for I2C (SDA, SCL) and for the UART (TXD, RXD).
The combination around the 555 timer and the power switch allows the shutdown of the Pi about 55 seconds after a power-loss has been detected.
Below is the simulation of the Power-Off circuit.
PowerOff.png
PowerOff.png (27.33 KiB) Viewed 33471 times
Green trace is the 5.4V power loss, with a stutter. The negative edge triggers the 555 at 25 seconds.
Blue trace is the 555 timer output at the gate of M2.
Red trace is the 5V power going to the Pi stopping at 80 seconds. So we have 80-25=55 seconds to let the OS power-down the Pi.

Unfortunately, it takes quite a number of components and takes up a sizable portion of real-estate, so if you know a better, more simple, or more elegant way, please chime in.

There are some tricks I can think off that will make life easier, but you will need to go in and change the kernel. I specifically don't want to do that, and rely on a stock version of the OS.

And now for the small print: The circuits around U1 and U2 and the power switch have not been build yet, only simulated. The components I used were available in LTspice IV, and may not be the parts I will eventually end up using, and this may require some value changes for R's and C's. When I have built and tested the circuits I will report back.
Stay tuned...

paulv
Posts: 557
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Controlled Shutdown at Power Failure

Sun Aug 04, 2013 12:58 pm

All the parts arrived, so I could start to build the circuit around the LT1302.
I selected the LT1302-5, the fixed output version, because it came in an 8 pin DIL package.
Eager to get some results quickly, I prototyped the circuit using my trusted breadboard.
I kept all leads as short as possible, and made sure I had one common ground.

With a 200 Ohm load, the current was a safe 25mA, and everything worked perfectly. Also the switching between the regular 5V supply (set at 5.32 to account for the diode voltage drop) and the LT1302 souped-up battery power worked great.

Next test, increase the current to 500mA. And here everything fell apart. The voltage dropped to a meager 3 volts, and the LT became very hot. At first I did not worry too much, since we intend to run the LT only for about 40-60 seconds. What concerned me was the voltage drop. I swapped some parts, changed the coil, some of the capacitors but to no avail. Reading the datasheet again and again, I was sure the device should deliver at least 500mA at 5V.

I used my trusted Fluke 123 digital scope, and saw some high-frequency ripple, coming from the PWM oscillator, but that didn't startle me. It was already late, so after a good night sleep and some more thinking freely, I re-read the data sheet once again. When I saw the proposed PCB layout, it just hit me. I realized that the LT could have been oscillating due to my sloppy breadboarding. The 123 scope would not pick that up if it was high enough, and that would explain just about everything.

So, I decided to re-build the circuit on a piece of prototype board, sticking to the proposed layout as much as possible. Of course it worked this time.

Here are some results with the input to the LT using two 1.2V NiMH 2700mAh cells
- 200 Ohm load (25mA) , output 5.04 V.
- 10 Ohm load (500mA), output 4,76 V. (hmm, could be better)

Then I used a variable supply instead of the NiMH cells, to see what the effects would be on a dropping cell voltage, when they are discharging.

When I changed the input to the LT between 1.8 and 3V, the output did not change at all. This is great! BTW, you can also use regular 1.5V batteries if you omit the charging components R3 and D3.
The LT only became warm to the touch, but not hot at all at the 500mA load. Also great, especially since we're only going to run it for less than a minute anyway.

Then I tested the switch-over from both supplies, letting the two Shottky diodes determine the winner. I set the supply voltage to 5.32V, just 0.02 above the Schottky voltage drop, to get a clean 5 V for the Pi. When I pulled the plug (yeah, nice feeling to be able to do that now) for the 5 V supply, the voltage dropped to 4.75V, but that was with a 500mA load. So far so good.

(I tried the same test with a 3K3 resistor between the Lt (pin 5) and ground, but that did not change anything.)

Now I need to start testing this with a real Pi at the end, and go through the shutdown procedure. That will be a project for next week.

Here is the resulting circuit I am now working from:
ShutdownPower V4 Schematic.png
ShutdownPower V4 Schematic.png (35.08 KiB) Viewed 33250 times

paulv
Posts: 557
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Controlled Shutdown at Power Failure

Mon Aug 05, 2013 10:53 am

I tested the circuit today with a Pi connected, and got it to work.
But first I ran into two problems.
First, as I expected, there is too much of a drop/glitch of the voltage during the switch between the supplies, so I countered that by adding a 1,500 uF capacitor parallel to C2. It seems that the Pi is very sensitive in that department. This cap is not a low ESR type. An earlier simulation showed quite an improvement when I selected a low ESR type, so I think I need to get one to be safe.

Second, I had two sets of old NiMH batteries, and both are not working right. When I yank the power, the voltage sags and then comes up to the 5V again. I was trying to get away with these old batteries, but apparently that does not work.
When I used normal AA Duracell Alkaline batteries, everything worked fine.
So, a new set of NiHM's is on order, and I hope this sagging issue is then resolved.

What we also expected was the required careful adjustment of the main 5 V supply because we OR the supplies through diodes. Initially, it seemed that 5.32V (200mV above the voltage drop of the Schottky diode) should have been enough, but I ended up needing to adjust the 5V supply measuring on the Pi side, and made that 200mV higher then the LT output voltage.
This avoids the LT kicking in when the 5 V drops too much. This can happen due to the different loading caused by the Pi.
The LT senses the voltage at the PI level, so it actively compensates for the different loads.

If you have, or expect a lot of main voltage drops, you may want to consider using a comparator (with a hysteresis) to measure the drop of the 5V supply, and use a MOSFET switch instead of the two OR'ed diodes. I started out that way but I think this should work just fine and I'll continue this way for the time being.

Because the battery voltage input to the LT1302 can vary quite a bit (from 1.8 to 2.5V) as I measured yesterday, this opens the door to Super caps. BudBennet already alluded to them in an earlier post. Normally, they are not that useful because only a portion of their charge can be used (they discharge linearly and so does the voltage). This is the main difference with batteries, which retain their voltage, then drop off sharply. This will be another test later on, to see if that works with this circuit. I already did some reading on them, but will need to learn a lot more about them. When you stack them, the charging is not so trivial compared to the NiMH's. More on that later, maybe.

Next on the list is to add the bells and whistles in hardware and software that I already designed and simulated (see above) to let the Pi shut itself down when the main power disappears.

BudBennett
Posts: 89
Joined: Fri May 17, 2013 2:45 pm
Location: Westcliffe, Colorado, USA

Re: Controlled Shutdown at Power Failure

Tue Aug 06, 2013 8:57 pm

I have been busy as well. My Plan A and Plan B PCB arrived last week and I have been evaluating the two circuit approaches (see postings above).

The bad news is that Plan A doesn't work. It has a serious flaw – the LTC4425 shuts down the PFOB comparator when it VIN pin goes below 1.5V. I thought that I would be clever and put a small diode from 5VOUT to 5VIN to hold up the supply until the Pi has shutdown, but the wall wart I'm using generates a vicious transient when you unplug it and then plug it in again within 2 seconds. It ended up yanking down on 5VOUT through the diode and the Pi immediately said bye-bye. It would have been nice if the 4425 data sheet had mentioned something about a comparator on VIN.

So on to Plan B.

It works pretty well. I already documented it previously so I won't get into details. Here's a scope trace showing it deglitching a short loss of power. Note that the POWERFAIL signal goes high and returns low – the deglitching is done in software.
deglitch.png
Deglitching a short power loss interval.
deglitch.png (11.55 KiB) Viewed 33097 times
Here's the full shutdown sequence where the input voltage is re-applied soon after the circuit is committed to the shutdown sequence. The circuit has to hold up the Pi for about 50 seconds – there's 5 seconds before it decides that it has to shutdown. You can definitely see when it switches from high current to shutdown current because the output voltage jumps up a bit due to less voltage drop across the 4415 diode, and the dV/dt slope on the supercaps decreases. It takes a bit longer than 10 seconds before power is re-applied to the Pi since the supercaps have to be recharged for a few seconds first.
fullcycle2.png
Full shutdown cycle
fullcycle2.png (13.54 KiB) Viewed 33097 times
The supercaps reach a voltage that will hold up the Pi power supply within about 30-45seconds after power is re-applied, so that's better than I expected. Unfortunately, if the supercaps are allowed to charge to their final voltage then the power won't be disconnected to the Pi for almost 5 minutes. This is perfectly acceptable for my application (my home heating system) where 5 minutes is a short amount of time.

I'm pretty happy with the performance. Here's a photo of the completed PCB sitting on top of the two D-cell sized supercaps.
P1020528-s.jpg
Plan B PCB with Pi in background
P1020528-s.jpg (40.82 KiB) Viewed 33097 times
I just need to figure out a method of securely holding the circuit and the caps and then I'm on to another project.

Bud.

paulv
Posts: 557
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Controlled Shutdown at Power Failure

Wed Aug 07, 2013 8:16 am

Hey Bud, well done! Congratulations.

With your design, there is now a controlled shutdown system documented that is using Super-caps and is verified to work.
For the sake of the followers of this post, did you do a calculation on the minimum capacity required for the Super-caps?

BTW, I'm sure you like your new scope!

I wish I had the possibility to use the SM components you use, it would make life easier.
Also, because of my thermostat enclosure, I don't have room for Supercaps this size.

So, with these constraints, I'll continue to try to stick to the through-hole parts and the NiHM solution and report the progress here.
Stay tuned...

Paul

BudBennett
Posts: 89
Joined: Fri May 17, 2013 2:45 pm
Location: Westcliffe, Colorado, USA

Re: Controlled Shutdown at Power Failure

Wed Aug 07, 2013 1:28 pm

Thanks Paul,

Here's my original calculation for sizing the supercaps:

I/C = dV/dt

I = 700mA (max Pi supply current - headless)
dV = 200mV (from 4.95V to 4.75V)
dt = 45 seconds

Plug all the numbers in to get C = 157F, but double it to get the capacitance of each supercap since they will be in series. I originally thought that this was an impossible number, but when I went to the Digikey catalog I found that they are available in even larger sizes, if you have the money. I found a 350F supercap with a 3.2 mOhm resistance for $11.

The size of the component doesn't bother me since my contraption is mounted in a 12"x12"x4" NEMA box on my garage wall. Even so, Tage mentioned in another post that some manufacturers are pushing for smaller so we'll just have to wait a bit.

I'm hoping that I can just install this thing and forget about it for 10 years. No battery maintenance issues. No significant power dissipation (25mW). No switching noise...

Bud.

Return to “Automation, sensing and robotics”