# Poor Man's UPS for a Microcontroller

I'm planning to create a Control Box for my Home Solar System which will involve using a microcontroller (STM32F103C8T6) as my control system. This uC will handle my current sensing for power monitoring, data logging to an SD Card, Battery Bank capacity detector, and a lot more. I was planning to add a "poor man's UPS" by using a Supercapacitor to power the uC only and make sure that it shuts down everything safely before going to standby mode.

Based on the datasheet of the uC that will be used, its maximum current draw is 150 mA. I'll be assuming that this is at 3V3, which will equate to around 22 Ohms. Will this assumption be correct? Can I use this value to determine the Capacitor discharge rate?

I will be going for the worst case scenario and assume that the uC will draw 300 mA of current. That means that at 3V3, this will equate to 11 Ohms of load. simulate this circuit – Schematic created using CircuitLab

Since supercapacitors usually are rated at 2V7, I have to put 2 in series to give me a maximum voltage of 5V4 with a total capacitance of 250 F. Using the capacitor discharge equation, this will give me around 176 seconds, which is more than enough to shut everything down and go to standby mode.

EDIT: I used the capacitor discharge equation to get this time value. The voltage drop that I allowed is from full charge which is 3.5 Volts up to 3.3 Volts. Based on this link, during standby mode, the uC will only consume around 70uA of current, which means that the capacitors will keep my uC alive for around 8 days. Are my calculations correct? Or are there other things that I should be aware of?

EDIT: The 8 days that I was talking about was still from the same capacitor discharge equation. 691200 seconds is roughly 8 days. The 50k Ohms resistance is from R=V/I which is 3.5V/70uA=50k Ohms. • 1) "maximum current draw is 150 mA [...] at 3V3, which will equate to around 33 Ohms" - actually that should be 22 ohms, not 33. 2) If 150mA is the absolute worst-case current of the processor, then why not just design to that number instead of 300mA? It seems that 150mA already gives you some design margin. 3) "Using the capacitor discharge equation, this will give me around 176 seconds" - please provide some detail. What math did you use? Specifically, how much are you allowing the capacitor voltage to droop? That is THE most important question here. – Mr. Snrub Sep 15 '19 at 7:17
• First, I would recommend using a different MCU; take a look at the STM32F0 series. However, be aware any MCU-based system is probably going to need a regulated supply. The NUCLEO-L031K6 may meet your requirements. – Caleb Reister Sep 15 '19 at 7:22
• It would help to see how you calculated came up with those numbers to begin with - it does not look like they are from the datasheet. The F103 itself won't consume more than 50mA, with maximum speed and all internal peripherals on. Sleep current could be 200uA. And it only works down to 2.0V. – Justme Sep 15 '19 at 7:35
• @Mr.Snrub My bad. Edited. 22 Ohms. Also, I edited my post to let you know how I got those time values. – thisjt Sep 15 '19 at 8:34
• @CalebReister I will take that into consideration. However, this mcu also has an LDO regulator located at the back. I'm planning to use that instead of powering the mcu directly. This is the mcu in question. link – thisjt Sep 15 '19 at 8:37

Based on the datasheet of the uC that will be used, its maximum current draw is 150 mA. I'll be assuming that this is at 3V3, which will equate to around 33 Ohms. Will this assumption be correct? Can I use this value to determine the Capacitor discharge rate?

No you can't (reliably)

..which means that the capacitors will keep my uC alive for around 8 days. Are my calculations correct? Or are there other things that I should be aware of?

No your calculations are not correct.

You are forgetting (or neglecting) the fact that at the same time you are consuming current from the capacitor the voltage across it is decreasing linearly, in other words, once the capacitor is fully discharged then the voltage across it is also zero, meaning that you will run out of useful supply voltage long before you fully discharge the capacitor.

First of all my recommendation would be don't do it, supercapacitors are super-useful in the right applications, yours is not it. If you need your system to stay powered without a constant power source then I would recommend you instead use a small battery, like everybody else.

If however you really want to use a super-capacitor then you need to know the following parameters;

V_max (the highest supply voltage that your system can accept) let's say for the purpose of this example that V_max = 5V4.

V_min (the minimum supply voltage that your system can run off) let's say for the purpose of this example that V_min = 2V4, which matches the minimum voltage requirement of many 3V3 systems.

C_supercap (the capacitance in farads of the super-capacitor) let's say for the purpose of this example that C_supercap = 250F

Now first we calculate the useful voltage drop across the battery as; V_useful = V_max - V_min = 5V4 - 2V4 = 3V0

Then we calculate the useful charge stored in the super-cap in Coulombs [C] as a function of the voltage difference as; Q_useful = V_useful * C_supercap = 3V0 * 250F = 750 C

Now we calculate the total power that can be retrieved from the super-cap over the discharge of 750C from 5V4 to 2V4. Here you have to appreciate the fact that the average voltage provided by the super-cap while discharging from 5V4 to 2V4 is going to be the average voltage in between the two, first, we calculate the average voltage provided by the super-cap while discharging as; V_avg = (V_max + V_min) / 2 = (5V4 + 2V4) / 2 = 7V8 / 2 = 3V9

Now that we know the average voltage output and the total charge difference we can calculate the total energy output of the super-cap in joule [J] as; E_useful = V_avg * Q_useful = 3V0 * 750C = 2250J

So after analyzing the super-cap and doing some math we now know that we can get a total of 2250J of energy out of the super-cap. Now we need to calculate how long it is going to take the IC to consume those 2250J of energy, this is more tricky as we don't know the exact power consumption of the IC at any one point/ at any specific voltage.

The best we can do given the data you provided is to calculate the minimum and maximum amount of time that the system can stay powered. To do this we first calculate the maximum power consumption of the IC as; P_max = V_max * I_max where I_max = 150mA P_max = V_max * I_max = 5V4 * 150mA = 0.81W = 0.81 J/S (Joule pr. second)

Assuming a maximum power consumption of 0.81 J/S (W) we can calculate the minimum time that the system can stay powered as; T_on_min = E_useful / P_max = 2250J / 0.81J/S = 2778s (seconds)

So to get this in hours; T_on_min(hours) = T_on / 3600s = 0.77h (hours)

Now let's calculate the maximum amount of time the IC can stay powered using the minimum supply voltage and maximum supply current as; P_min = V_min * I_max = 2V4 * 150mA = 0.36W = 0.36J/S T_on_max = E_useful / P_min = 2250J / 0.36J/S = 6250s T_on_max(hours) = T_on_max / 3600s = 1.74h (hours)

So likely your IC will stay powered between 0.77 and 1.74 h while not in standby mode.

Now to calculate the minimum powered up time when in standby mode; P_stdby_max = 5V4 * 75uA = 0.004W = 0.004J/S P_stdby_min = 2V4 * 75uA = 0.002W = 0.002J/S T_on_stdby_min = E_useful / P_stdby_max = 2250J / 0.004J/S = 562500s = 156.25h = 6.5days T_on_stdby_max = E_useful / P_stdby_min = 2250J / 0.002J/S = 1125000s = 312.5h = 13days OBS!: The above assumes that the system starts out fully charged and discharges in standby mode the whole time.

I have left out the internal resistance of the super-cap which is going to cause an additional power loss and I have also left out the internal leakage resistance which is going to cause the super-cap to discharge by itself without you even drawing power from it.

PLEASE NOTE THAT: Most MCU's need a regulated power supply and can not run on everything from 2V4 to 5V4 continuously. Probably you are going to need to put a 3V3 LDO between the batteries and the MCU, if you do this then the time the system can stay powered for is much much less:

Let's assume a 3v3 LDO with a minimum voltage drop across it of 1v2

5V4 - (3v3 + 1v2) = 0v9 0v9 * 250F = 225C 225C * (5V4 + (3v3 + 1v2))/2 = 1114J (5V4 + (3v3 + 1v2))/2 * 150mA = 0.74J/S 1114J / 0.74J/S = 1500s = 0.4h

This is a much more realistic calculation.

• I did take into consideration the voltage drop that happens when I discharge the capacitor using the capacitor discharge equation. The 176 seconds that I got is the time it takes for the capacitor to discharge from 3.5 Volts to 3.3 Volts. I edited my post above for more information. – thisjt Sep 15 '19 at 8:50
• Okay, regardless, modeling your MCU as a resistive load is not going to work. – Vinzent Sep 15 '19 at 8:58
• Oh. Okay. How about using an efficient boost converter? – thisjt Sep 15 '19 at 9:16
• What about that? sure you can use a boost converter, but I still wouldn't recommend you use a super-cap. People who are not very experienced working with electronics and who don't have a degree in electrical engineering tend to often want to use exotic components for which they have no need, because "super-capacitor" sounds at least twice as good as just "capacitor" or "battery", or because they think that it can somehow make everything much better. The important point that I am trying to make is KISS (Keep It Simple Stupid), no need to invent the wheel, somebody already has. – Vinzent Sep 15 '19 at 17:05
• What myself and other electrical engineers I know often do when we need a "poor mans UPS" is just to find a small USB power bank which can be charged on at the same time as you discharge on it (look for one with both a USB-A and a USB micro-A/B connector) now a days you can often get those for much less than it would cost you to buy the super-cap and the other components etc. – Vinzent Sep 15 '19 at 17:14