Thalyn
Posts: 4
Joined: Tue Jul 23, 2019 2:47 pm

Using GPIO 5V for power - current limiting required?

Tue Jul 23, 2019 3:19 pm

This is my first post so I'm not exactly sure where this should go. There's no dedicated hardware section and this doesn't really feel like a beginner thing, so I'm hoping this is the right place.

I've recently acquired a RPi 2B. A little old, but it does the job. I'm trying to implement a very, very basic shutdown on power loss circuit. My idea is to track the "mains" power by way of an optocoupler (a 4N25) fed from PP1 and PP5 with a ~470 resistor (value yet to be determined). When the optocoupler stops being active, a signal is sent to a GPIO pin, informing the Pi that it needs to shut down. This signal is little more than a straight line with a 10K resistor in the way, just as a precaution.

In order to make this useful, I've acquired a pair of 25f 2.5V supercapacitors, which I plan to run in series to allow for 5V. The intent is to plug these into 5V and ground on the GPIO so that they can both charge and discharge without any interaction from myself or anything else. But I'm left with one main concern: do I need to limit the current in this situation?

My initial thought was to plug the caps in directly and leave it at that. But that relies entirely on the ESR of the caps, could potentially overload my power supply (a buck converter I've already tested to have voltage sag when going past around 2.5A), and may give the Pi itself grief. My next thought is to include a current limiting resistor, but I'd need this to be at least a 5W (wire-wound from my supplier) in order to allow for just 1A (dis)charging, which starts getting big and hot.

Which leads me to my question: is current limiting required, does the Pi natively have some form of current limiting built in for the GPIO, or is the ESR likely to be sufficient restriction on its own?

Cheers.

trejan
Posts: 2238
Joined: Tue Jul 02, 2019 2:28 pm

Re: Using GPIO 5V for power - current limiting required?

Tue Jul 23, 2019 5:40 pm

It isn't as simple as just putting two super capacitors in series across 5V and ground. You need to do voltage balancing or risk one capacitor getting damaged from over voltage. You'll want to limit charge current as well.

https://hackaday.io/project/25107-singl ... spberry-pi has a design of a suitable supercap based mini UPS. It uses a dedicated chip which handles balancing and charging. It also has a PIC uC to make sure it cleanly starts up and shuts down.

User avatar
davidcoton
Posts: 5084
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: Using GPIO 5V for power - current limiting required?

Tue Jul 23, 2019 8:38 pm

The second problem with your plan is that the capacitors will keep the opto signalling good until they are exhausted -- at which point it is too late to start shutting down. You need to take all the power circuits away from the Pi, and prevent the caps backfeeding the opto. I haven't checked, but I expect the Hackaday design will do that.
Signature retired

Thalyn
Posts: 4
Joined: Tue Jul 23, 2019 2:47 pm

Re: Using GPIO 5V for power - current limiting required?

Wed Jul 24, 2019 6:11 am

My understanding of the two PP tabs I plan to use is that they're before all of the power protection stuff, which shouldn't be allowed to receive any back-fed power (at least I'm hoping power won't feed backwards through Q3 or U14). So unless the circuit diagrams are wrong (or I'm just not reading them correctly) there shouldn't be any issue with regards to having the caps supply the opto.

Regarding the unbalancing, I'm hearing conflicting information on that. I see it mentioned more than once that it's a real consideration, but I also hear from a physicist (well, BA in Physics) that it's a non-issue. I had actually seen that Hack-a-Day project before and it just seems massively over-complicated for what it needs to do. Though, in having said that, I've no direct experience with it so I guess there's always the potential for difference between "what should be" and "what is".

But you have mentioned that I will need to limit current, which is the main question I had. Which I guess means I'll need to look into some high-wattage resistors. I'd been hoping to avoid that because everything in me says they're going to run HOT, which I'm trying to avoid.

*ed: I'm wondering if the addition of an LTC4041 could solve both issues - current limiting and potential unbalancing. It again seems massively over-complicated for the task, and sourcing milliohm resistors may be an issue, but I guess it's an option.

*2nd ed: Also poking around, I'm finding some "Capacitor Balancing/Protection board" things. They seem to be the kind of thing I could just stick in - one per cap - to solve the balancing issue. Unfortunately they all seem to be quite large (30mm across, where I need maybe 15mm) and the multi-cap versions are for 6+ caps, but it seems like something worth considering for simplicity.

User avatar
davidcoton
Posts: 5084
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: Using GPIO 5V for power - current limiting required?

Wed Jul 24, 2019 9:10 am

Sorry, yes, I think your scheme will work on a 2B (but not on all Pi models), at least as regards separation of caps and opto.

It is worth looking a how the commercial UPS solutions work. AFAICT they mainly package everything on a HAT, but still use the microUSB to connect power (main and reserve) to the Pi.
Signature retired

drgeoff
Posts: 10832
Joined: Wed Jan 25, 2012 6:39 pm

Re: Using GPIO 5V for power - current limiting required?

Wed Jul 24, 2019 9:28 am

I would try the following.

Put a 10 ohm resistor between the caps and 5 volt pin on GPIO header. That will limit the charging current to 0.5 amp maximum. The resistor does not need to be very high wattage as it only passes current for a brief period each time power is reapplied to the micro-USB socket.

Put a Schottky power diode across the resistor. Anode to the capacitors end and cathode to the GPIO end. That will allow the caps to supply current to the RPi with a much smaller voltage drop than without the diode.
Quis custodiet ipsos custodes?

Thalyn
Posts: 4
Joined: Tue Jul 23, 2019 2:47 pm

Re: Using GPIO 5V for power - current limiting required?

Wed Jul 24, 2019 9:39 am

davidcoton wrote:
Wed Jul 24, 2019 9:10 am
It is worth looking a how the commercial UPS solutions work. AFAICT they mainly package everything on a HAT, but still use the microUSB to connect power (main and reserve) to the Pi.
The ones that I've seen (admittedly not a large selection) all seem to involve a power passthrough setup. ie You plug the main power into the HAT, then it gets passed via either the GPIO header or a loop-back cable to power the Pi itself. They even go so far as to explicitly state to not plug the power supply directly into the Pi (though they don't actually specify why). To the best of my knowledge this is the only way to do it without soldering, since there's no on-board way to detect the presence or absence of the 5V input separate to the post-protection 5V line.

In case you're wondering, only reason I'm not looking to use one of those pre-built options instead is because they seem to be designed for a larger capacity battery. I may not even use my Pi for days, if not weeks, which means it will be sitting there draining sleep power the whole time. It's not much, sure, but I can't imagine it being good for the long term health of the battery, be it LiI-on or NiMH.
drgeoff wrote: I would try the following.

Put a 10 ohm resistor between the caps and 5 volt pin on GPIO header. That will limit the charging current to 0.5 amp maximum. The resistor does not need to be very high wattage as it only passes current for a brief period each time power is reapplied to the micro-USB socket.

Put a Schottky power diode across the resistor. Anode to the capacitors end and cathode to the GPIO end. That will allow the caps to supply current to the RPi with a much smaller voltage drop than without the diode.
I like the diode idea. Hadn't even considered that.

My concern with a 10Ω resistor is that the ones I normally use are only 1W jobs. They're probably not even going to handle that well, either, if I'm honest. Even if it's not for a long time, running 2½ times the power through them doesn't feel like a great idea to me. Of course they're cheap, so I could always experiment with it to see how it holds out.

drgeoff
Posts: 10832
Joined: Wed Jan 25, 2012 6:39 pm

Re: Using GPIO 5V for power - current limiting required?

Wed Jul 24, 2019 11:38 am

Thalyn wrote:
Wed Jul 24, 2019 9:39 am
My concern with a 10Ω resistor is that the ones I normally use are only 1W jobs. They're probably not even going to handle that well, either, if I'm honest. Even if it's not for a long time, running 2½ times the power through them doesn't feel like a great idea to me. Of course they're cheap, so I could always experiment with it to see how it holds out.
If the power handling of the resistor is a problem, remember that four 1 watt resistors each of resistance R ohms can be wired to give you one 4 watt resistance of R ohms.
Quis custodiet ipsos custodes?

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13142
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Using GPIO 5V for power - current limiting required?

Wed Jul 24, 2019 2:24 pm

I would create a power circuit that generates power to the PI with some reserve. And yes with super caps, there are some supercaps (two paired in series) that can withstand more than the normal (about) 2.7Volt, and can be used to buffer 5V, and cab be simply attached in parallel with the 5V power rail.
Then I would design a parallel independent "mains power good circuit" consisting of a capacitive voltage dropper, a bridge rectifier and a LED (in the opto-isolator) that will react immediately to any mains power missing a cyclus, and will instantaneously start a shutdown procedure.
remever that during the shutdown the 5V should be kept as close as possible to 5V for as long as possible, so diodes in the feed pad are bad.

keep it simple (KISS).

drgeoff
Posts: 10832
Joined: Wed Jan 25, 2012 6:39 pm

Re: Using GPIO 5V for power - current limiting required?

Wed Jul 24, 2019 2:54 pm

mahjongg wrote:
Wed Jul 24, 2019 2:24 pm
I would create a power circuit that generates power to the PI with some reserve. And yes with super caps, there are some supercaps (two paired in series) that can withstand more than the normal (about) 2.7Volt, and can be used to buffer 5V, and cab be simply attached in parallel with the 5V power rail.
Then I would design a parallel independent "mains power good circuit" consisting of a capacitive voltage dropper, a bridge rectifier and a LED (in the opto-isolator) that will react immediately to any mains power missing a cyclus, and will instantaneously start a shutdown procedure.
remever that during the shutdown the 5V should be kept as close as possible to 5V for as long as possible, so diodes in the feed pad are bad.

keep it simple (KISS).
An issue to be considered is that if such a reserve circuit is able to supply the running current at adequate voltage to the RPi for 10 or more seconds then the charging time for that reserve circuit with a current of similar order from a mains PSU will also be many seconds. During those seconds the voltage applied to the RPi will be increasing from zero quite slowly. WIll the RPi boot properly?
Quis custodiet ipsos custodes?

Thalyn
Posts: 4
Joined: Tue Jul 23, 2019 2:47 pm

Re: Using GPIO 5V for power - current limiting required?

Thu Jul 25, 2019 7:38 am

drgeoff wrote:
Wed Jul 24, 2019 11:38 am
If the power handling of the resistor is a problem, remember that four 1 watt resistors each of resistance R ohms can be wired to give you one 4 watt resistance of R ohms.
Wouldn't that have to be N resistors in parallel of N*R resistance to get R resistance with N wattage? So 4x 40Ω or 10x 100Ω to get 1x 10Ω, and so forth.

But you're right, though. A small bank of resistors would give better options with regards to spreading the heat and positioning, likely with less error on the final value.
drgeoff wrote: An issue to be considered is that if such a reserve circuit is able to supply the running current at adequate voltage to the RPi for 10 or more seconds then the charging time for that reserve circuit with a current of similar order from a mains PSU will also be many seconds. During those seconds the voltage applied to the RPi will be increasing from zero quite slowly. WIll the RPi boot properly?
This is something I've been concerned by. If I just leave the SCaps open (ie No current limiting resistance) than I've no idea what they'll drop my buck converter down to. So it's safe to assume that such a circuit wouldn't start the Pi immediately, which isn't terrible, but when it gets to around the right voltage (4.7v?) will the Pi start correctly or will the sudden (albeit small) increase in load cause the voltage to sag, resulting in multiple, failed attempts to start up? I can't imagine that being at all good for the Pi, or at least the SD card.


Just some napkin math here...

If I aim to limit it to 1.5A (leaving 0.5A to 1A for the Pi to run without voltage sag), that's going to be 3.33Ω. If I opt to use 8 resistors (the packs I get usually contain 8) the closest I can get is 27Ω, leading to a final resistance value of 3.375Ω, yielding 1.481A recurring for 7.405W (the resistors should handle 8W). Two 25F SCaps in series gives 12.5F total capacity. If I'm right (and I have no idea if I am because I can't find formulae telling exactly what units are in use - just τ=RC) this should take about 42 seconds to charge to 63% capacity, and around 210 seconds (3:30 minutes) to hit 99%, which is fine. Heck, I could double the capacity and still have times shorter than it takes to start a print due to heating on a 12V PSU.

As for discharge time... well, I can't find formulae for that. But hopefully it's enough to give ~20 seconds. Otherwise I may have to double it up (or more).

drgeoff
Posts: 10832
Joined: Wed Jan 25, 2012 6:39 pm

Re: Using GPIO 5V for power - current limiting required?

Thu Jul 25, 2019 9:03 am

1. Put two R resistors in series and the resistance is 2R. Put another two in series with each other, not with the first two, to make another 2R. Put the two 2R pairs in parallel and you are back to a resistance of R. The current through and the voltage across each of the 4 resistors is the same so if one can handle w Watts, the compound resistance can handle 4w.

2. Do not overlook the fact that the capacitors need to hold enough charge that the voltage sag from +5 needs to be small enough that the RPi keeps working for longer than the software shutdown takes. Contrast that with the voltage increase from zero to whatever is required to get the RPi going. This I believe that the startup time will be significantly longer than than the required hold-up time.

3. The whole point of the diode suggestion is the increased flexibility to met the conflicting requirements of limiting supercap charging current, running normally and running from the supercaps.
Quis custodiet ipsos custodes?

Return to “Advanced users”