The Investigation and Prototype
This project will first investigate the possibilities for a DIY UPS system for all Raspberry Pi models, at least that is the goal for the design.
When this investigation is successful, I will design a PCB for it in a later Blog post.
Why do I do this?
Well, I have a pretty long history of building a number of UPS versions for my Pi projects, starting with an elaborate version for my wireless thermostat that was running on the first version of the Pi, now many years ago (2015). That post is on my Blog, search for "UPS". Since then, I designed a number of other attempts to basically protect the SD card in the Pi from power outages or glitches.
My friend Bud, in 2018 and 2019, designed two very nice UPS systems, using the HAT module layout, that could use 14500 and 18650 Li-Ion cells, used a dedicated chip to handle the power and charging, but used a micro-controller to keep things "under control". The latest version worked for years for me, and at least two of them in Bud's applications, but recently the one I used developed an issue.
Here is Bud's posting with all the details : https://hackaday.io/project/162653-u1liupsrpi
It turned out that I used an older IMR cell that got bad, but the UPS also showed an issue that I wanted to investigate. During that process, I successfully managed to create some magic smoke and blew a hole in the main chip, the LTC4040. Replacing that chip has it's challenges due to the footprint, and getting just one would cost me way too much, and I still would not know if there are other bad parts on the board.
I abandoned that project as being too costly, cumbersome and risky.
Although I do not have an immidiate need for a UPS, I kept thinking about it and the challenges. Although Bud designed a very nice UPS, there were way to few Makers that build one. Putting muself in their shoes, there are two road blocks preventing more global use.
- First the LTC4040. It's not widely available, and not cheap. The other challenge is the package, a 24-Lead 4mm × 5mm QFN that makes it a challenge for most Makers to solder.
- Second is the controller, a PIC16F18323. The package is OK, but the programming is not. You need to have a programmer and a socket for the chip. Bud published the Microchip MLAB information and the flow-chart, but you have to program the chip.
So, while thinking about another DIY version that is sturdy, reliable and easy to build I started to pice a few things together that will eliminate some of the chellenges that plague most UPS systems for applications like the Pi.
With the advent of newer Pi models and ways to circumvent the SD card, or protect it better, the UPS functionality is a bit less on that part, but if you have applications that do not tolerate a sudden powerdown or power glitch, you still need protection.
The UPS goals for this project
Rather than keeping the Pi alive for a very long time, the focus will be on riding out power glitches and to provide a controlled power down and restart when power returns.
The powerdown will be under control of the Pi itself so you are free to do what's needed to cleanly terminate your processes and then execute the powerdown.
The UPS function only needs to supply power to the Pi for a few minutes. Three minutes should be enough to do whats needed, so there will be enough remaining capacity in the cells to go through another cycle that happends before the cells are fully recharged again.
The main power and the battery power switching should be automatic and instantenous without glitches.
To make the design simple, I'm planning to use a normal (raspberry Pi certified) 5.1V power-brick to supply the normal power to the Pi. It should have at least 2.5A capacity, more if you need that for Model 4 or 5 and if you use USB adapters.
To avoid the issues with Boost regulators that will convert a single Li-Ion cell (between 4.2 and 3.0V) to the 5V the Pi needs, I elected to use two cells in series. That needs a simple Buck regulator to regulate the cell voltage between say 8 and 6V down to the 5V the Pi needs.
The charger will be one that can handle a 2S (2 cells in series) configuration with all the protection needed for Li-Ion cells. An active and simple balancer circuit willl be used to keep both cells happy and at the same voltage level. This is important because the cells will normally be off-duty with only an occasional use.
To supply the charger, I'm planning to use a 12V or 15V wall-wart that many of us have from other devices, most likely a drawer full of them, like I do. They typically have the capability to deliver 2A, which is plenty for the re-chargeing of the cells.
So why two wall-warts? Seems a bit daft at a first glance, but it avoids either a high power Buck regulator to bring the 12 or 15V down to the 5V for the Pi, and that 24x7 so it needs to be very reliable and provisions need to be made for the developed temperature generation. The other option is to use a high power Boost regulator, to bring the 5V up to 12V so the two cells can be charged. If you add both current requirements, you're getting into a territory of 5 Amps plus, where you will not be able to use wall-warts anymore. Then there is the high additional switching noise generated by higher currents for either the Buck or Boost regulator. We already have one, that will only be used when the pi is on cell power, and that's enough.
To switch between the mains 5V and the Cell generated 5V, I will be using two so called active Ideal Diodes in an OR configuration. This will ensure that the main 5V going into the Pi will not have a significant voltage drop and nothing will get hot.
The two Li-Ion cells can be 14500 or 18650 IMR cells that feature a very high discharge current. I'm planning to use two 14500 IMR cells, but will also test the 18650 cells that will have more oompf for high current applications.
So there is no required micro-controller, although I will plan to have the possibility to add an ESP32 for overal measurements and reporting.
I'm also planning to add an ADC so voltages and currents can be measured and logged if wanted, but this is optional and not required.
With the obove building blocks, we can provide the Pi with power when the mains drops away and will use the Pi itself to initiate a powerdown all by itself.
The trick for all these UPS solutions is to wake-up the Pi when power returns. This is where the micro-controller is used, but we won't have one. A clever circuit will keep an eye on the power loss and will turn-off the Buck regulator output when the Pi is made powerless after a powerdown. That process will allow the Pi to start normally when main power returns. Yes, you can use the features newer models have, but these features are not available on the older model Pi's. Allowing the Pi to startup when power is applied is reliable for all current models.
The Prototyping phase
When I had this rough design done, mostly in my head, I looked for the modules that would allow me to build the system and test it out.
I could find everything I needed on Amazon, for reasonably low prices and with a fast delivery.
Here are the building blocks:
Li-ION 2S Charger Module:
This is actually a solar panel based charger with a MPPT feature that I won't need, but it's easily disabled. The input is the 12 or 15V from the wall-wart, and the output goes to the two cells in series.
The specifications are:
Model: CN-3795-2A.
Input voltage: DC 6,5-24 V.
Output current : max. 2 A
Output voltage range: adjustable from 2,4 V to 20 V.
Can be sued for : 1 to 5 lithium-ion cells in series.
Charging modes: constant current / constant voltage plus MPPT.
DC-DC-efficiency: ca. 85%
Module size: 20 x 35 mm.
The 2S Balancer Circuit:
The output from the charger above goes to the plus of the top cell, the middle to the connection of both cells, and to the bottom of the second cell. That's it. It simply balances the voltage of both cells to within 30mV and uses a 10mA charge to reduce a high voltage cell.
The Buck Convertor:
This is a very common and inexpensive Buck regulator that uses the XL4015 regulator.
The key specifications are:
Input voltage: 4-38VDC
Output voltage: 1,25-36 VDC adjustable
Output current: 0-5A (stay below 3 to keep heat down).
This board does not have an EN pin to disable the output, but there are other ones available that do, but there is another way, see below.
The Ideal Diode Switch
This circuit uses N-Fet's (very low RDS-on) and the LM74700 controller. It is ground based (many other boards are not and that gives a problem) The LM747001 has an EN (enable pin) that I need to bring out for this board, so the Pi can switch-off the battery supply when it has reached the powerdown status. To use an N-FET in this circuit the LM74700 has a built-in charge pump.
Specifications:
Input voltage: 5-30V (another spec says 0-50V; that's not correct)
Current: up to 10A
These Ideal Diode boards will need a minimum input voltage to let the LM74700 function, typically 4V is OK. We'll find that out when we're testing.
The create the diode OR circuit, the inputs are connected to either the main 5V or the cell generated 5V, and the outputs from both boards are then connected together and go to the Pi power input.
These parts are all on order and will arrive shortly.
When I have them wired-up, I will do some testing and show the results here.
Stay tuned, I'm only beginning...