2

I'm looking for the easiest way to delay the loss of power to the pi (for a duration on the order of milliseconds) after the power supply is lost. I'm no good at designing circuits and I'm guessing that it's a bit more complicated than just sticking a capacitor somewhere but if there is a simple schematic (ideally that just integrates with the main power cables) I could probably build it. Most UPS systems I'm finding are too complex and provide enough time for a full shutdown and I just want a fraction of that.

Thanks for any pointers.

schmop
  • 179
  • 1
  • 8

3 Answers3

4

From the electrical point of view, adding a lithium battery would be the way to go. There are a lot tutorials on how to make your Pi ready for mobile use and if you have it permanently connected to the power supply and only need this as a backup, it should never run out of power.

Adding a capacitor would work, at least in theory, but let's talk about the dimensions first: The Pi 3 draws up to 2.5A (worst case scenario) from a 5V supply voltage. The definition of Farad is As/V. so by inserting current and voltage you get 0.5s from a whole (!) Farad, and only if it can hold the voltage until it is completely discharged... which, well, it simply doesn't. The voltage of a 1F capacitor would have dropped to 4.95V after only 20ms.

So you can see that to realize a capacitor solution for a whole shutdown you would need many F so it is going to a lot much more expensive than using a battery as a buffer. If you are still interested in the capacitor solution you could do some research about the capacitor discharge process. The circuit on the other hand would be super easy, just connect it in parallel to your Pi. So if you really need only a few ms go with the biggest capacitor you can afford. There are so called goldcaps which are quite cheap, but their voltage is low (around 2.3V) so you would have to connect some of those in serial. Just remember that this will also decrease the total capacity! I found a 22F 2.3V gold cap for 5,70€ so with 3 of them you could drive a Pi with around 7F. After 140ms the voltage would have dropped to 4.95V, after 282ms you would still have 4.9V... I don't know about the smallest voltage to drive a Pi but 4.95V (1% drop) sounds kind of realistic to me.

I think you will have to test it by yourself because noone knows what you're up to. I'd still go with the battery, though.

Domme
  • 375
  • 2
  • 11
2

You should be thinking of your worst case scenario here something like:

  • User has just sent large amount of data and filled all RAM buffers, say 100MB
  • Pi has not started to write any of this to SD card yet

How long will it take to write this to the SD card?

Assuming a decent SD card at 8MB/s you are looking at 12 seconds, double this for OS shutdown and other hiccups and you are looking at trying to get ~30 seconds of power after the Pi has been unplugged.

You know your application better than I do so can model the data writing better, but sticking a cap on the Pi's power isn't going to help in this case I think

Tim Fletcher
  • 131
  • 4
-1

The system will be writing to the disk almost the entire time between the shutdown command and the time it actually halts.

This makes the time between issuing the shutdown command and the shutdown being completed possibly the most dangerous time to pull the power.

I suggest you don't just give it a few ms here but ensure that you have enough power to complete the shutdown.

If you are just dealing with a single computer, a rechargeable USB charger should work great and be pretty cheap. If you are deploying this, a small stack of cheap batteries should cover the occasional few seconds of power down for a few years (I've seen these stacks of batteries in bulk LED toys that cost $0.10/ea, so there must be a way to get a supply of them for a reasonable cost)

Bill K
  • 281
  • 1
  • 2
  • 9