Feral-Nerd
Posts: 30
Joined: Sat Mar 28, 2015 2:31 pm

PowerBoost 500c Safe Shutdown

Sun Apr 19, 2015 3:04 am

I just ordered the PowerBoost 500C. According to Adafruit the PowerBoost 500C tells you when the battery is low by dropping LBO to 0V which means you can detect low battery. Then it hit me that when you install a power switch and flip the switch to shut the PowerBoost 500C off by shorting EN to ground the PowerBoost 500C probably just brutally cuts the power. Is this correct? I have been playing around with a circuit simulation program and I came up with the attached circuit which should hold the voltage over R1 the 1M ohm resistor at around 3v for about 10 seconds when you open up the switch S1 which then jumps to 3 volts. So by detecting the voltage over the switch S1 jumping to 3 volts when it is opened with a GPIO pin on the raspberry PI one should have about 10 seconds to boot the Rasp. Pi down before voltage over R1 drops to 0. You can vary the time by adjusting R2 and the Transistor is a MOSFET-n with a threshold of 1V. All this having been said I suck badly at analog circuit design, I'm a code monkey by trade.
Attachments
S1-Open.jpg
S1-Open.jpg (45.93 KiB) Viewed 11269 times
S1-Closed.jpg
S1-Closed.jpg (48.98 KiB) Viewed 11269 times

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: PowerBoost 500c Safe Shutdown

Sun Apr 19, 2015 4:51 am

I doubt it seriously. The RPi draws too much current.

You need a switch or sensor to signal the RPi to (shutdown -h now) and then kill the mains (the powerboost) when the RPi is safely down. I would not mess around with any goofy flaky power cap to try to hold the RPi when the mains are down hoping that the RPi can shutdown cleanly in the alloted timeframe... you're just asking for a clobbered SD card bubba.
marcus
:ugeek:

Feral-Nerd
Posts: 30
Joined: Sat Mar 28, 2015 2:31 pm

Re: PowerBoost 500c Safe Shutdown

Sun Apr 19, 2015 4:59 am

All I really want to do is detect when the ON/OFF switch is opened with a GIPIO pin but still keep the EN pin on the PowerBooster high for about 20 seconds while the Raspberry powers down.

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: PowerBoost 500c Safe Shutdown

Sun Apr 19, 2015 5:19 am

I see... clever... you might try a timer (555) that would produce a one-shot (high for 20-40 seconds) then LOW /

Automating power-down is typically not done. Automating recycle, yes, or restart after power glitch... UPS and so forth, but for all practical purposes you can leave the RPi on forever. If its being battery driven, then yes you need some way to detect the batts LOW condition and power-down the PI safely... but it looks to me like you are interested in powering off the PI with a switch on the powerboost, yes? Bad plan. Power down the PI and then cycle down the powerboost.
marcus
:ugeek:

Feral-Nerd
Posts: 30
Joined: Sat Mar 28, 2015 2:31 pm

Re: PowerBoost 500c Safe Shutdown

Sun Apr 19, 2015 6:10 am

My ON/OFF switch sits on the outside of a case. It is a toggle switch that conducts when it is pressed to the ON position and the contact is only broken when the switch is switched to OFF.

According to the Adafruit documentation if I short EN to GND the PB500C will stay shut down but the monent EN and GND are disconnected the PB500C will power up and the Rasp. PI will boot up. So it strikes me that what I need is a circuit that:
  • Disconnects EN and GND immediately when the switch toggled to the ON position and keeps them disconnected thus keeping the PB500C active.
  • Connects EN and GND after a delay of 10 or so seconds when the switch is toggled to OFF thus giving the Rasp. PI time to shut down.
  • Both states would have to be detectible by a GPIO pin on the Rasp. PI.


A user in another thread suggested using a MOSFET transistor. I have also thought of using a NC555 timer But I can't figure out how to wire up such a circuit. Problem is that I'm no circuit designer... :oops:

Feral-Nerd
Posts: 30
Joined: Sat Mar 28, 2015 2:31 pm

Re: PowerBoost 500c Safe Shutdown

Sun Apr 19, 2015 7:15 pm

Cooked this up, according to my circuit simulator it keeps the relay engaged for 12 seconds after the switch S1 is disengaged.
Attachments
LM555-Based-delayed-OFF-timer.jpg
LM555-Based-delayed-OFF-timer.jpg (56.83 KiB) Viewed 11186 times

Feral-Nerd
Posts: 30
Joined: Sat Mar 28, 2015 2:31 pm

Re: PowerBoost 500c Safe Shutdown

Sun Apr 19, 2015 10:28 pm

New version. S1 and S2 are DPST (Mechanically linked). that way GPIO 18 gets a logical change immediately but NC only 12 seconds later.
Attachments
LM555-Based-delayed-OFF-timer.jpg
LM555-Based-delayed-OFF-timer.jpg (53.28 KiB) Viewed 11171 times

vvanhee
Posts: 3
Joined: Sat Jun 07, 2014 11:39 am

Re: PowerBoost 500c Safe Shutdown

Sat Jun 20, 2015 3:37 am

I'm also trying to do this with a 1000c. I'm hoping to be able to program an ATtiny85 to turn on the PowerBoost when it sends a high signal on one of its pins. I'd rather not use a relay as I don't have one.

I've been trying to use a NPN transistor inverter circuit to keep the EN to Ground shorted on the PowerBoost while the ATtiny is off, but I'm having no luck. I posted more details on Stack Exchage: http://electronics.stackexchange.com/q/176398/79190

Would really appreciate any help.

mikey11
Posts: 354
Joined: Tue Jun 25, 2013 6:18 am
Location: canada
Contact: Website

Re: PowerBoost 500c Safe Shutdown

Sat Jun 27, 2015 8:11 pm

Consider this solved from a hardware perspective: (You will need to write your own code that watched GPIO pins to handle a shutdown)

See the breadboard diagram below:

Image

Parts:
pnp transistor: BC516
resistor: 100Kohm (I may use a 1Mohm in my final)
electrolytic capacitor: 220 uF (I may use 47 uF or less in my final)

SPDT switch.

so, I needed this function for the powerboost 1000C, but it will work on either the 500C or the 1000C. I did my testing on the 500C, but it will make little to no difference.

Basically the capacitor is charged when the spdt throw switch connect the BAT pin to the + terminal of the capacitor. When the capacitor is charged, it discharges through the 100K ohm resistor. the pnp transistor monitors this circuit, and is inhibited as long as there is power discharging through the resistor. if the pnp were not inhibited, the EN and GND pins would be tied together and shut down the powerboost. (note, on the 1000C, the BAT pin is labeled Vsh, and is not always the battery voltage, but the higher of two possible voltages. It shouldn't change the behaviour of this circuit, but the pins aren't the same, and this should help avoid confusion)

As long as the switch is closed, power continues to be applied.

When the switch is open, the capacitor stops charging, and begins to discharge. It discharges over time based on the value of the capacitor, and the resistor. If you modify these values, you can change the time. I need about 25 seconds, and this circuit on the first go gives me 38 seconds. once the capacitor discharges, the pnp stops being inhibited, and the EN and GND pins of the powerboost connect, killing power to everything.


So. If you want to integrate this into an rPI project, you will need to monitor the state of the power switch which charges the capacitor over one of your GPIO. You may need a voltage drop as the BAT pin can be as high as a fully charged lipo, exceeding the 3.3V considered "safe" on the raspberry pi. When the monitor pin goes low, a shutdown command is initiated.

Another consideration is that the voltage of the battery will change over time, hence changing the amount of power stored in the capacitor. This means that a lower battery will have a shorter shutdown time, so I'm planning on making my shutdown time much longer than needed.

On a device that has hours of battery life, an extra minute at full charge is nothing if it guarantees me the 25 seconds I require at low charge.

Another consideration is power consumption. When the switch is turned on, your resistor is chewing up battery. This is what is pushing me towards a 1M ohm resistor, and a smaller capacitor than a lower resistance, and higher capacitance. I want my timer circuit to demand maximum of about 5 mA continuously... the less the better.

Some useful places to check out while pursuing this are:

http://ladyada.net/library/rccalc.html

http://www.rapidtables.com/calc/electri ... ulator.htm

Here is a video of my breadboarded 500C operating on a 10 second shutdown:

https://youtu.be/3hhhXcmpcac

The original post on this wasn't too far off the mark.

To get what I needed timewise, I ended up with a 1M ohm and a 47 uF. It gives me close to a minute on full charge. This should have a consumption near 2-4 mA, so not a huge imposition on the device.

mikey11
Posts: 354
Joined: Tue Jun 25, 2013 6:18 am
Location: canada
Contact: Website

Re: PowerBoost 500c Safe Shutdown

Sun Jun 28, 2015 6:20 pm

If you want to use the spdt switch with the RPI and detect a software shutdown, I propose the following:

The left pin goes to a GPIO with a voltage drop inline. The middle pin of the switch has to be the capacitors + terminal. The right pin has to be the BAT pin from the powerboost.

In this fashion, when the switch joins the capacitor and BAT, the rpi is on, and everything operates.

when the switch joins the GPIO and capacitor +, the GPIO goes high and you start the system shutdown.

mikey11
Posts: 354
Joined: Tue Jun 25, 2013 6:18 am
Location: canada
Contact: Website

Re: PowerBoost 500c Safe Shutdown

Sun Jul 05, 2015 5:47 pm

I've integrated this circuit into my device.

I did run into something which led me to change my initial circuit plans:

I thought the lipo battery would not exceed 4.2v. I figured a 1n4001 diode would provide enough drop. A fully charged lipo seemed to give me significantly more than 4.2v up in the region of 5.1v

I had planned on feeding the gpio through the diode for detection.

So I decided to build a voltage divider with resistors. I didn't realize the built in resistors on the pi's GPIO would act as an additional voltage divider. So I eventually just ended up replacing the diode with a 10kohm resistor. This gave me 3.3V on a full battery charge at the GPIO when I flipped the switch to the off position.

I increased the capacitor to 220 uF and got 16 seconds of time to shut down with. The total shutdown time is around 10 seconds for the pi, giving a reasonable extra interval before power drops.

https://youtu.be/VXzTouPj99g

Video of the circuit in action shutting down an embedded device project I'm working on.

JimmyN
Posts: 1109
Joined: Wed Mar 18, 2015 7:05 pm
Location: Virginia, USA

Re: PowerBoost 500c Safe Shutdown

Mon Jul 06, 2015 8:04 pm

If you have a lipo that's at 5.1V then I'd suggest a new multi-meter.

It could be a faulty charger that's overcharging it. But I'm a RC hobbist and LiPo's are the way to go, I've got 25~30 LiPo cells/packs and I've never heard of a lipo cell getting all the way up to 5.1V without experiencing what the manufacturers call "vent with flame", which literally means "splits open and burns like a road flare, setting fire to everything around it". 4.2V is the max cell voltage a lipo charger will output and many stop at 4.1 or 4.15 just to be safe. If the cell has a protection circuit that too will limit it to 4.2V or less. Charging to more than 4.2V on a single cell is very hazardous to both you and your surroundings. So either your LiPo charger is faulty and you've been extremely lucky, or your meter is off.

jeremiahrose
Posts: 4
Joined: Mon Feb 16, 2015 4:24 am

Re: PowerBoost 500c Safe Shutdown

Mon Dec 07, 2015 9:34 am

Hey guys, thanks for all the informative posts. I've tried to whittle down all the info in this thread into something dead-simple with only a few components and I came up with this:

Image

It uses a JFET transistor instead of a BJT to eliminate the drain current in Mikey11's circuit. I'm not 100% sure I've chosen the right transistor - maybe a p-channel MOSFET would be a better choice?

The pins are:
  • VS - supply voltage, always on even when the Powerboost is disabled. Ranges from 3-5v depending on the state of the battery or usb supply.
  • En - the "enable" pin on the Powerboost 1000C. This sits at VS. When pulled down the Powerboost will cut off power to the RPi.
  • GPIO - any available GPIO pin on the RPi. Used to trigger the shutdown script. Active low (i.e needs to have a pull-up resistor set).
It's supposed to work like this:
  • When the switch is ON, the voltage from VS causes the JFET to switch off. This isolates En from ground and the Powerboost boots up and provides power to the RPi. The capacitor is also quickly charged up, and the GPIO pin is disconnected and remains in it's high state.
  • When the switch is turned OFF, GPIO is shorted to ground which initiates a shutdown script on the RPi. The capacitor begins to drain through the 1M resistor, but the JFET remains pinched off because the capacitor is still applying a voltage to its gate, so En remains isolated from ground and the Powerboost keeps running.
  • After 15-30 seconds when the capacitor has discharged, the gate voltage drops and the JFET opens, connecting En to ground which signals the Powerboost to cut off power to the RPi. By this time the shutdown script should have completed successfully.
Does this look like it would work? The main thing I'm unsure about is the JFET: are the polarities right? Is it connected correctly? Do I need a p-type or n-type? Can you anyone suggest a specific JFET that would work best in this circuit? Should I use a MOSFET instead?

Return to “HATs and other add-ons”