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

Re: Controlled Shutdown at Power Failure

Fri Dec 20, 2013 6:25 pm

The supercaps hold up the supply for at least 5 minutes before they cutoff the supply voltage to the Pi. The first 30-45 seconds or so the Pi is running at 500mA and the balance of the time is spent idling at around 100mA. I don't think that you could get away with much less than 300F for the each capacitor in the stack - using the more conservative cutoff point of 4.75V.

If you were willing to let the 5VOUT voltage slide to around 4.6V (check out the specs of the LDO that the Pi uses to supply the 3.3V supply) then you could use smaller caps still. It's all about safety margins.

Bud.

konavan
Posts: 4
Joined: Thu Dec 19, 2013 10:24 pm

Re: Controlled Shutdown at Power Failure

Sat Dec 21, 2013 5:25 pm

Bud,
thanks for that info. after some pricing research it appears that most supercaps are minimum ~$11 regardless of size. so getting smaller than 350F results in no cost savings. oh well. also, tell me about your processing. I can easily see how sensing the power fail signal you could initiate a shutdown or halt. my concern is how to restart. if the mains power returns before the supercaps fail, the system will be stuck in halt mode. possibly do you initiate a reboot and have a startup task that checks the power fail signal before fully booting?
the whole point is not to be writing to the file system and abruptly lose power.
-Van

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

Re: Controlled Shutdown at Power Failure

Sat Dec 21, 2013 6:45 pm

There is no danger that the shutdown procedure will be interrupted. Once the power is gone for 2 seconds then the circuit latches the power fail state until the supercaps are discharged. If the power returns before the end of the super cap discharge cycle, the circuit waits until the supercaps trip the discharge threshold, then the 5VOUT is switched off for 10 seconds to let the Pi reset, and then 5VOUT is re-applied and the Pi boots normally. The flaw in the system is if the power goes out again soon after reboot, but I don't think there is a significant chance of SD card corruption at that point (but I might be wrong about that).

Bud.

guitarist46559
Posts: 3
Joined: Sat Feb 08, 2014 3:16 am

Re: Controlled Shutdown at Power Failure

Sat Feb 08, 2014 3:29 am

I stumbled onto this thread looking to do nearly the same thing as you guys. Only difference is, I'm looking to use a Pi as part of a car stereo package, so I am more drawn to BudBennett's SuperCap method, given the high frequency of power downs this Pi would be likely to see.

BudBennett, do you have any suggestions to adapt your circuit(s) for use in an automotive system? I am also highly considering using an external drive for music storage (and an Adafruit GPS module), so suggestions on adding sufficient power to have a few devices on the Pi would be greatly appreciated too.

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

Re: Controlled Shutdown at Power Failure

Sat Feb 08, 2014 2:15 pm

I wouldn't recommend this approach for an automotive system - you've got a large battery already as a backup power source. I think that there are other threads dealing with 12V automotive systems.

Bud.

guitarist46559
Posts: 3
Joined: Sat Feb 08, 2014 3:16 am

Re: Controlled Shutdown at Power Failure

Sat Feb 08, 2014 2:28 pm

BudBennett wrote:I wouldn't recommend this approach for an automotive system - you've got a large battery already as a backup power source. I think that there are other threads dealing with 12V automotive systems.

Bud.
but that's just it, in my car, the radio turns off as soon as the key is turned to the off position, effectively acting as a "power outage". I know I could tie it into an always on circuit, but I'd rather it act as my radio does, and to not have to mess with it each time.

I hadn't seen any other threads that quite cover what I want to do (this ones been the closest), but I'll keep looking.

acnheatpro
Posts: 3
Joined: Mon Mar 24, 2014 6:03 am

Re: Controlled Shutdown at Power Failure

Mon Mar 24, 2014 6:09 am

Bud,
Thanks for sharing your project. I plan to build your circuit and use it on my raspberry pi project to prevent from having another corrupted sd card.
I found all the needed parts online except I can't seam to find the R145-32.768.
Does anyone know where I can buy one online at?
Thanks for your help

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

Re: Controlled Shutdown at Power Failure

Mon Mar 24, 2014 10:02 pm

The 32.788 kHz crystal can be ordered from http://www.taydaelectronics.com. They have good prices on the DS1307+ as well.

We had an 18" snowfall about 3 weeks ago. The power must have cycled at least 15 times over a 15 hour period. The circuit rode through all of it - even the 2-3 events that occurred over a one minute interval. The only problem that I had was that the last glitch event was less than one second long and disrupted the wi-fi adapter than I had plugged into the USB extender on my Dell monitor. It hung, and I had to restart everything.

I hope you know how to solder these fine-pitch packages (the LTC4415 is a 0.5mm pitch). I can make my design project public on OSH Park and you can order them there if you would like. You must order three, but I think the total cost is around $8.

Bud.

acnheatpro
Posts: 3
Joined: Mon Mar 24, 2014 6:03 am

Re: Controlled Shutdown at Power Failure

Tue Mar 25, 2014 5:09 am

I'm glad to hear that it stood up to the test. Mine should not see so many events, I have clean power but it does get unplugged from time to time so that is why I want to use your circuit.
I'm not vary good at soldering but luckily I have a friend that is a pro so hopefully he can handle the fine pinch parts.
Yes please make your design public.
Thanks again for all your help. If there is anything I can do for you just let me know.
Also I will post updates once I get everything soldered up.

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

Re: Controlled Shutdown at Power Failure

Tue Mar 25, 2014 6:01 pm

I made my PCB a public project on OSH Park. Here's the link: http://oshpark.com/shared_projects. It is named "HoldUp2+RTC". Date on the PCB bottom is 9 Sept. 2013.

C4,C5: 0805. C1, C3, C6: 0603. C2 is a radial electrolytic with 2mm pin spacing, 5mm dia. Resistors are 0603, except for R4: 0805. I used a DIP pkg for the 1307 because it was much cheaper than SMD. I couldn't figure out how to get oval holes so I had to drill the J4 contacts myself.

Have fun.
Bud.

rtek1000
Posts: 27
Joined: Wed Mar 12, 2014 9:21 pm

Re: Controlled Shutdown at Power Failure

Thu Mar 27, 2014 6:43 am

I was thinking of doing something simpler, leveraging what is already commercially available.

Image

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: Controlled Shutdown at Power Failure

Thu Mar 27, 2014 4:31 pm

guitarist46559 wrote:
BudBennett wrote:I wouldn't recommend this approach for an automotive system - you've got a large battery already as a backup power source. I think that there are other threads dealing with 12V automotive systems.

Bud.
but that's just it, in my car, the radio turns off as soon as the key is turned to the off position, effectively acting as a "power outage". I know I could tie it into an always on circuit, but I'd rather it act as my radio does, and to not have to mess with it each time.

I hadn't seen any other threads that quite cover what I want to do (this ones been the closest), but I'll keep looking.
Hi Guitarist,

You could simplify these circuit designs for your car stereo design, bring both switched and unswitched 12V supplies to your board, supply your Pi from the unswitched supply (dropping the voltage to 5V of course) while monitoring the switched supply to command shutdown.
Effectively you are using the same design without the need for capacitors or internal batteries.
Doug.
Building Management Systems Engineer.

rtek1000
Posts: 27
Joined: Wed Mar 12, 2014 9:21 pm

Re: Controlled Shutdown at Power Failure - News

Thu Mar 27, 2014 6:19 pm

If you disable LAN chip, the use of super capacitors can be viable:
Disable LAN9512


The LAN9512 is the hardware device which controls Ethernet and USB ports. This chip consumes almost 200mA, and it will be very useful to disable it to save energy when I don't need USB or Ethernet. The LAN9512 datasheet explains some states of the device to save energy - these modes are SUSPEND2, SUSPEND1 and SUSPEND0. Therefore, it seems to be possible.

I have already found a partial solution:

echo 0x0 > /sys/devices/platform/bcm2708_usb/buspower will effectively disable the device and wake up it again with echo 0x1 to the same file. However, once the device has been stopped and started a certain number of times, it won't wake up again until the next reboot of the operating system.

Is there a method to disable LAN9512 and start it again reliably? (Maybe can I reload some driver that controls LAN9512?)

Motivation

When a raspberry pi model B is idle, it consumes 400 mA. When it's stressed, 470mA. When the LAN9512 is disabled, it consumes 200mA on idle and 260mA stressed.

Others

I have tested the fiability of disabling the chip through "buspower" by using a script that disables the LAN9512, tries to mount an usb device to check for activity and reboots. Until now, the raspberry pi has rebooted 9222 times without errors.
echo 1 > /sys/devices/platform/bcm2708_usb/bussuspend Disables the LAN9512 But won't wake it up again when doing echo 0 to the same file. After disabling it, the raspberry pi goes extremly slow reporting a load average up to 4.

Font:
http://raspberrypi.stackexchange.com/qu ... le-lan9512
Note: I obtained a login on 'Putty' with more than 4.05V at 5V line.

I will try use two 20F in serie, result in 10F.
I will try use the simple scheme:
Image

acnheatpro
Posts: 3
Joined: Mon Mar 24, 2014 6:03 am

Re: Controlled Shutdown at Power Failure

Mon Apr 07, 2014 4:45 pm

Budd,
I ordered the boards from Osh park they should ship 4/8/14. I have also revived all of the other parts needed so hopefully I will be able to build the board next week.
I plan to embed the raspberry pi with your circuit inside of an appliance. The pi will be powered from the appliance and must be safe from SD card corruption when the appliance is powered down.
I am going to use your circuit with another that converts the appliance's power to 5vd
I want it all to be on one daughter board that will plug into the Rpi GPIO
Is this something that you would be interested in helping me with?
I am more than willing to compensate you. send me an email for more details.
[email protected]
Thanks

rtek1000
Posts: 27
Joined: Wed Mar 12, 2014 9:21 pm

Re: Controlled Shutdown at Power Failure

Tue Apr 08, 2014 12:41 am

Hello guys,

Yesterday I turned off the Raspbian normally, I expected to stay only the red LED lit, after some time I turned off the power.

Today I had a bad experience!


The RPI was not fully loading the boot and appeared on the screen to manually run ' fsck '.

And I ran the 'fsck' on my Xubuntu.

It worked to recover the boot, the filesystem was clean.

But a folder disappeared, just that I use to run the script for the expected application to the RPI.


I researched quite a solution to prevent the file system is corrupted to turn off the power abruptly.

Also did not have time to put into practice the idea of backing up the source with batteries or super capacitors.


And I think I found a solution to my problem!

I managed to get the filesystem to read- only mode, and everything seems normal.

Follows the idea:
1 - In Xubuntu I opened the files from the SD card RPI and edited the file /etc/fstab, adding temporary partitions running in RAM:

Code: Select all

proc            /proc                proc    defaults                                           0       0
/dev/mmcblk0p1  /boot                vfat    defaults,noatime,ro                                0       2
/dev/mmcblk0p2  /                    ext4    defaults,noatime,ro                                0       1
tmpfs           /tmp                 tmpfs   defaults,noatime,nosuid,size=100m                  0       0
tmpfs           /var/tmp             tmpfs   defaults,noatime,nosuid,size=30m                   0       0
tmpfs           /var/spool/mqueue    tmpfs   defaults,noatime,nosuid,mode=0700,gid=12,size=30m  0       0
none            /var/run             tmpfs   size=5M,noatime                                    0       0
none            /var/log             tmpfs   size=5M,noatime                                    0       0
2 - I dismounted the SD and insert again in the RPI.

3 - I called several times and hung up the RPI and at different times to test.


Note:
1 - I do not need the GUI, so I removed everything related to it.
sudo apt-get remove --purge x11-common (-750MB)
sudo apt-get autoremove (-205MB)

2 - Before editing the fstab file, The RPI was only 44MB of RAM in use.
check with:
free -m

3 - SD was only 598MB in use (I also removed other small packages).
check with:
df -h

4 - the GPU is configured to use 16MB.
add to end of file /boot/config.txt:
gpu_mem=16

5 - Remember to always back up the data from sd card. On Windows PC, I use USB Image Tool:
http://www.alexpage.de/usb-image-tool/

Good luck!!!

surfparadise
Posts: 95
Joined: Fri May 10, 2013 9:01 am

Re: Controlled Shutdown at Power Failure

Tue Apr 29, 2014 9:39 am

Hi, this is my circuit for a safe shutdown due to power loss.

What do you think about it? Could it works?

Image

Regards

slado
Posts: 21
Joined: Thu Aug 16, 2012 6:23 am

Re: Controlled Shutdown at Power Failure

Mon Jun 09, 2014 11:06 pm

Interesting topic. There is already a product using supercapacitors instead of batteries to backup power for the Raspberry Pi for a short time. The main difference: The supercapacitors work with their full charge, not only with a small change of charge around the 5V. A step-up/step-down converter is doing the job of converting the falling or rising voltage at the supercapacitor:

www.juice4halt.com

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: Controlled Shutdown at Power Failure

Tue Jun 10, 2014 8:31 am

slado wrote:Interesting topic. There is already a product using supercapacitors instead of batteries to backup power for the Raspberry Pi for a short time. The main difference: The supercapacitors work with their full charge, not only with a small change of charge around the 5V. A step-up/step-down converter is doing the job of converting the falling or rising voltage at the supercapacitor:

http://www.juice4halt.com
as the webpage you have linked to says that they are still in development and was only launched this month I think the phrase "already a product" is an exaggeration

The product does seem to be inspired by this topic, although there are probably many other similar ones spread across the internet.
Doug.
Building Management Systems Engineer.

slado
Posts: 21
Joined: Thu Aug 16, 2012 6:23 am

Re: Controlled Shutdown at Power Failure

Tue Jun 10, 2014 10:25 pm

Yes, you are right. The product is not ready for production. It will be probably by the end of this year. As I am the designer of the board I must know it. Sorry for not saying this information. Just wanted to see what people think about it.

LeftyF
Posts: 7
Joined: Mon Sep 23, 2013 5:59 pm

Re: Controlled Shutdown at Power Failure

Wed Jun 11, 2014 1:20 am

Interested to see how this turns out. I did a very simple solution with mine using a Nicad battery backup and a script that checks periodically for a USB device. If the device no longer responds the battery backup has dipped to near dead voltage and the script sends a shutdown. Not as elegant as what you're doing but it gets the job done. I also saw another project with a sensor and a lipo battery back that looks promising, but not done cooking yet. It's fun to see all the solutions coming from the user community.

Good luck and keep posting your results

hughes89
Posts: 3
Joined: Thu Nov 01, 2012 10:45 pm

Re: Controlled Shutdown at Power Failure

Wed Sep 03, 2014 5:38 pm

BudBennet, I just saw your PCB in detail in the given images and I must say I’m thoroughly impressed with your work. Using a super capacitor is more suited than the use of batteries since they can charge and discharge every time and can work for a long time. It is a must have for people who are logging data in real-time like me. I faced these issues a lot because of power outages here. I’m going to work on it and provide my feedback here.

pcb assembly

Fisek
Posts: 7
Joined: Mon Dec 05, 2016 12:28 pm
Location: Belgium

Re: Controlled Shutdown at Power Failure

Tue May 23, 2017 3:26 pm

Hi BudBennett,

I am also planning to integrate a similar circuit for my RPI3. Is it possible for you to share the code that you have mentioned?

In addition to this, do you have any other suggestions/pre-cautions for integrating the circuit to RPI3 as it has a bit different lay-out?

Kind regards,

Fisek

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

Re: Controlled Shutdown at Power Failure

Wed May 24, 2017 8:16 pm

Hi Fisek,
Things have moved a long way since I posted my first supercap solution, which BTW is still working fine on with the RPi1 attached to the boiler controlling my heating system. But I am now woking with PaulV to come up with an improved UPS system that can provide the higher currents needed by the RPi3B. Progress is slow. This stuff is not easy -- even for an experienced design engineer -- due to second-order effects and misleading switch-mode converter data sheets. I should have the next generation UPS ready to post in a few weeks (Hint: how about a UPS using a single supercap?), but in the meantime here's the code (such as it is) that is currently running the old system:

Code: Select all

#!/usr/bin/env python

import RPi.GPIO as GPIO
import os, time

GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)

def powerfail_detect(channel):
    for n in range(1,4):
        time.sleep(1)
        if (not GPIO.input(23)):
            return
    print("powerfail detected...shutting down the Pi!")
    os.system("sudo shutdown -h now")

GPIO.add_event_detect(23, GPIO.RISING, callback=powerfail_detect)

try:
    print("Waiting for falling edge on port 23")
    while True:
        time.sleep(1)
except:
    GPIO.cleanup()  # clean up GPIO on CTRL+C exit

GPIO.cleanup()
Note that the Pi is not involved in the decision to shutdown -- the old hardware makes all of the decisions. Things are different on the next UPS generation.
Bud.

Return to “Automation, sensing and robotics”