---
title: "Project: a supercapacitor backup supply"
heading: Keep a circuit alive through a power cut, and choose the capacitor
eyebrow: C2 · Lesson 28 · Project
xp: 80
---

::: hook
A smart meter, a data logger or a car's dashcam has to finish writing its data when the power disappears. A supercapacitor, charged while power is on, can keep it running for the seconds that takes. Sizing one is a real design problem: the electronics behind it draw constant power, so the current rises as the voltage falls; the capacitor's own resistance drops voltage and wastes energy; and below a certain voltage the converter quits or the whole supply collapses. In this project you'll simulate the discharge in Python, see what the resistance costs, and choose the smallest capacitor that meets a hold-up specification.
:::

::: play
- A supercapacitor charged to $V_1$ feeds a converter drawing constant power $P$. The solid curve is the capacitor's internal voltage, ignoring losses; the dashed one is the voltage at its terminals, lower by the drop across its ESR.
- The ESR drop grows as the voltage falls and the current rises. Make the ESR large and watch the terminal voltage fall away early.
- The readouts give the ideal hold-up time to $V_2$ and the voltage below which the supply can't deliver $P$ at all.
:::
:::

```sim plot
view: graph
x: t = 0..10 s
y: V = 0..6 V
slider: C = 0.1..10 = 1 F log
slider: P = 0.5..5 step 0.1 = 2 W
slider: esr = 0..1 step 0.01 = 0.3 Ω
slider: V1 = 2.7..5.5 step 0.1 = 5 V
slider: V2 = 1..4 step 0.1 = 3 V
plot: sqrt(abs(V1^2 - 2*P*t/C))*step(V1^2 - 2*P*t/C) | label: capacitor voltage, no losses | samples: 500
plot: (sqrt(abs(V1^2 - 2*P*t/C)) + sqrt(abs(V1^2 - 2*P*t/C - 4*P*esr)))/2*step(V1^2 - 2*P*t/C - 4*P*esr) | label: terminal voltage | dashed | color: ch2 | samples: 500
readout: ideal hold-up to V2, s = C*(V1^2 - V2^2)/(2*P) | digits: 3
readout: collapse voltage, V = 2*sqrt(P*esr) | digits: 3
```

::: predict
## A converter draws a constant 2 W from a supercapacitor with 0.5 Ω of ESR. Below what capacitor voltage can it no longer get 2 W, however much current it draws?

- [ ] 0.5 V
- [ ] 1 V
- [x] 2 V
- [ ] 4 V

::: reveal
2 V. A source $V_c$ behind a resistance can deliver at most $\frac{V_c^2}{4R}$ (maximum power transfer, C1.17). Setting that equal to 2 W with R = 0.5 Ω gives $V_c = 2\sqrt{PR} = 2$ V. Approaching it, the converter draws more and more current and the terminal voltage collapses.
:::
:::

::: nameit
## The model

A capacitor $C$ at internal voltage $V_c$, with series resistance ESR, feeds a load drawing constant power $P$ at its terminals, where the voltage is $V_t = V_c - I\cdot\text{ESR}$. The load needs $V_tI = P$, a quadratic in $I$:

$$I = \frac{V_c - \sqrt{V_c^2 - 4P\cdot\text{ESR}}}{2\cdot\text{ESR}}$$

which has a real solution only while $V_c \ge 2\sqrt{P\cdot\text{ESR}}$. The capacitor discharges at $\frac{dV_c}{dt} = -\frac IC$. With ESR = 0 this integrates to the hold-up time of lesson 11, $\frac{C(V_1^2 - V_2^2)}{2P}$; with ESR it doesn't integrate neatly, so step it in time (lesson 25).

## The specification

The load stops when either the terminal voltage falls below the converter's minimum input $V_2$, or the quadratic has no solution (collapse). The design is the smallest capacitor that holds up for the required time, and capacitors with more capacitance usually have less ESR, so both change at once.

## Charging

The backup capacitor has to be charged, usually at a limited current $I_c$ so it doesn't overload the main supply: from empty, $t = \frac{CV}{I_c}$. Supercapacitors also need a voltage limit, typically 2.7 V per cell, so 5 V parts are two cells in series with balancing.
:::

::: example
## A 1 F supercapacitor at 5 V backs up a 2 W load that works down to 3 V. How long does it last, ideally and with 0.5 Ω of ESR?

::: solution
1. **Ideal backup time.**
   $$\begin{aligned} t &= \frac{1 \times (25 - 9)}{2 \times 2}\ \text{s} \\ &= 4.0\ \text{s} \end{aligned}$$
2. **With 0.5 Ω of ESR.** Stepping the model with 0.5 Ω gives 3.26 s.
3. **Where the time goes.** The ESR wastes energy as heat and, worse, drops the terminal voltage below the capacitor's own.
4. **The cutoff.** When the terminal voltage reaches 3 V, the load draws
   $$\begin{aligned} I &= \frac{2\ \text{W}}{3\ \text{V}} \\ &= 0.67\ \text{A} \end{aligned}$$
   which drops 0.33 V in the ESR, so the capacitor itself is still at 3.33 V.

**Answer:** ideally 4.0 s; with 0.5 Ω of ESR, 3.26 s.
:::
:::

::: example
## How long does a 1 A charger take to bring that 1 F capacitor from empty to 5 V?

::: solution
1. **Charge needed.**
   $$\begin{aligned} Q &= CV \\ &= 1\ \text{F} \times 5\ \text{V} \\ &= 5\ \text{C} \end{aligned}$$
2. **Time at 1 A.**
   $$\begin{aligned} t &= \frac QI \\ &= \frac{5\ \text{C}}{1\ \text{A}} \\ &= 5\ \text{s} \end{aligned}$$

**Answer:** the charger takes 5 s.
:::
:::

::: check
given: C = 0.47 | 1 | 4.7; V1 = 5 | 5.4; V2 = 2.5 | 3.3; P = 0.5 | 3
answer: C*(V1^2 - V2^2)/(2*P)
unit: s
tolerance: 0.5%

## A {C} F capacitor at {V1} V feeds a lossless {P} W load that works down to {V2} V. How long does it hold up?

::: right
Right. $\frac{C(V_1^2 - V_2^2)}{2P}$ = {answer}.
:::

::: misses
- [C*(V1 - V2)/(P/V1)] That treats the load as constant current; it draws more as the voltage falls.
- [any] Not yet. Energy available over power.
:::
:::

::: check
given: P = 1 | 5; esr = 0.1 | 0.5
answer: 2*sqrt(P*esr)
unit: V
tolerance: 0.5%

## A {P} W load runs from a capacitor with {esr} Ω of ESR. Below what capacitor voltage can it no longer be supplied?

::: right
Right. Maximum power transfer: $2\sqrt{P\cdot\text{ESR}}$ = {answer}.
:::

::: misses
- [sqrt(P*esr)] The available power is $V_c^2/(4R)$.
- [any] Not yet. Set $V_c^2/(4\cdot\text{ESR}) = P$.
:::
:::

::: check
given: Vc = 4 | 5; P = 2 | 3; esr = 0.3 | 0.6
answer: (Vc - sqrt(Vc^2 - 4*P*esr))/(2*esr)
unit: A
tolerance: 0.5%

## A capacitor at {Vc} V with {esr} Ω of ESR feeds a {P} W load. What current flows?

::: right
Right. The smaller root of $I^2\cdot\text{ESR} - V_cI + P = 0$: {answer}.
:::

::: misses
- [P/Vc] That ignores the ESR drop: the terminal voltage is a little lower, so the current is a little higher.
- [any] Not yet. Solve $(V_c - I\cdot\text{ESR})I = P$.
:::
:::

::: check
given: Vc = 4 | 5; P = 2 | 3; esr = 0.3 | 0.6
answer: Vc - esr*(Vc - sqrt(Vc^2 - 4*P*esr))/(2*esr)
unit: V
tolerance: 0.5%

## A capacitor at {Vc} V with {esr} Ω of ESR feeds a {P} W load. What voltage reaches the load?

::: right
Right. $V_c - I\cdot\text{ESR}$ = {answer}.
:::

::: misses
- [Vc] Subtract the ESR drop.
- [any] Not yet. Find the current first.
:::
:::

::: check
given: C = 1 | 10; V = 2.7 | 5; I = 0.5 | 2
answer: C*V/I
unit: s
tolerance: 0.5%

## A {I} A charger fills an empty {C} F capacitor to {V} V. How long does it take?

::: right
Right. $CV/I$ = {answer}.
:::

::: misses
- [any] Not yet. Constant current: $t = CV/I$.
:::
:::

::: check
given: C = 1 | 25; V = 2.7 | 5
answer: 0.5*C*V^2
unit: J
tolerance: 0.5%

## How much energy does a {C} F capacitor hold at {V} V?

::: right
Right. $\frac12CV^2$ = {answer}.
:::

::: misses
- [C*V^2] Include the ½.
- [any] Not yet. $\frac12CV^2$.
:::
:::

::: check
kind: python

## Write `load_current(vc, P, esr)`: the current a constant-power load `P` draws from a capacitor at internal voltage `vc` with series resistance `esr`, or `None` if it can't be supplied. Handle `esr == 0`.

```python starter
import numpy as np

def load_current(vc, P, esr):
    return P / vc

print(load_current(5, 2, 0.5), load_current(1.5, 2, 0.5))
```

```python solution
import numpy as np

def load_current(vc, P, esr):
    if esr == 0:
        return P / vc
    disc = vc * vc - 4 * P * esr
    if disc < 0:
        return None
    return (vc - np.sqrt(disc)) / (2 * esr)

print(load_current(5, 2, 0.5), load_current(1.5, 2, 0.5))
```

```python tests
import numpy as np
assert abs(load_current(5, 2, 0) - 0.4) < 1e-12, "With no ESR, I = P/V."
i = load_current(5, 2, 0.5)
assert abs(i - 0.41742430504416) < 1e-9, f"At 5 V with 0.5 Ω, the load draws 0.417 A; got {i}."
assert abs((5 - i * 0.5) * i - 2) < 1e-9, "Check: the load must get exactly 2 W at its terminals."
assert load_current(1.5, 2, 0.5) is None, "Below 2·sqrt(P·ESR) = 2 V the power can't be delivered: return None."
```

::: right
Right. Of the quadratic's two roots, the smaller current is the real operating point; the larger one would waste most of the power in the ESR.
:::
:::

::: check
kind: python

## Write `holdup(C, V1, V2, P, esr=0.0, dt=1e-3)`: step the capacitor's voltage from `V1` in steps of `dt` seconds, and return the time at which the terminal voltage would first fall below `V2` or the load can no longer be supplied. Use `load_current`.

```python starter
import numpy as np

def load_current(vc, P, esr):
    if esr == 0:
        return P / vc
    disc = vc * vc - 4 * P * esr
    return None if disc < 0 else (vc - np.sqrt(disc)) / (2 * esr)

def holdup(C, V1, V2, P, esr=0.0, dt=1e-3):
    return C * (V1 ** 2 - V2 ** 2) / (2 * P)

print(holdup(1, 5, 3, 2, 0.5))
```

```python solution
import numpy as np

def load_current(vc, P, esr):
    if esr == 0:
        return P / vc
    disc = vc * vc - 4 * P * esr
    return None if disc < 0 else (vc - np.sqrt(disc)) / (2 * esr)

def holdup(C, V1, V2, P, esr=0.0, dt=1e-3):
    vc, t = V1, 0.0
    while True:
        i = load_current(vc, P, esr)
        if i is None or vc - i * esr < V2:
            return t
        vc -= i * dt / C
        t += dt

print(holdup(1, 5, 3, 2, 0.5))
```

```python tests
t = holdup(1, 5, 3, 2)
assert abs(t - 4.0) < 0.005, f"With no ESR, 1 F from 5 V to 3 V at 2 W lasts 4.0 s; got {t:.3f}."
t = holdup(1, 5, 3, 2, 0.5)
assert abs(t - 3.256) < 0.005, f"With 0.5 Ω of ESR it lasts about 3.26 s; got {t:.3f}."
t = holdup(1, 5, 3, 2, 1.0)
assert abs(t - 2.534) < 0.005, f"With 1 Ω it lasts about 2.53 s; got {t:.3f}."
```

::: right
Right. The closed form in the starter is right only for a perfect capacitor; each 0.5 Ω of ESR costs here about 0.7 s.
:::
:::

::: check
kind: python

## Write `choose(caps, V1, V2, P, T)`: `caps` is a list of `(C, esr)` pairs. Return the smallest C whose hold-up (your `holdup`) is at least `T` seconds, or `None`.

```python starter
import numpy as np

def load_current(vc, P, esr):
    if esr == 0:
        return P / vc
    disc = vc * vc - 4 * P * esr
    return None if disc < 0 else (vc - np.sqrt(disc)) / (2 * esr)

def holdup(C, V1, V2, P, esr=0.0, dt=1e-3):
    vc, t = V1, 0.0
    while True:
        i = load_current(vc, P, esr)
        if i is None or vc - i * esr < V2:
            return t
        vc -= i * dt / C
        t += dt

def choose(caps, V1, V2, P, T):
    return min(C for C, esr in caps if C * (V1 ** 2 - V2 ** 2) / (2 * P) >= T)
```

```python solution
import numpy as np

def load_current(vc, P, esr):
    if esr == 0:
        return P / vc
    disc = vc * vc - 4 * P * esr
    return None if disc < 0 else (vc - np.sqrt(disc)) / (2 * esr)

def holdup(C, V1, V2, P, esr=0.0, dt=1e-3):
    vc, t = V1, 0.0
    while True:
        i = load_current(vc, P, esr)
        if i is None or vc - i * esr < V2:
            return t
        vc -= i * dt / C
        t += dt

def choose(caps, V1, V2, P, T):
    for C, esr in sorted(caps):
        if holdup(C, V1, V2, P, esr) >= T:
            return C
    return None
```

```python tests
caps = [(0.47, 0.3), (1.0, 0.15), (2.2, 0.08), (4.7, 0.05), (10.0, 0.03)]
assert choose(caps, 5, 3, 2, 2) == 1.0, "For 2 s, 1 F (3.78 s) is the smallest; 0.47 F lasts only 1.67 s."
assert choose(caps, 5, 3, 2, 4) == 2.2, "For 4 s, 1 F falls just short (3.78 s with its ESR), so 2.2 F."
assert choose(caps, 5, 3, 2, 30) == 10.0, "For 30 s, only 10 F (39.5 s) works."
assert choose(caps, 5, 3, 2, 100) is None, "Nothing lasts 100 s."
```

::: right
Right. The 4 s case is the point: the ideal formula says 1 F gives exactly 4 s, but its ESR takes about 0.2 s of that away.
:::
:::

::: explain
## Why does a supercapacitor with high ESR give less hold-up time than its stored energy suggests?

::: model
Two things go wrong. First, the ESR turns some of the energy into heat, an $I^2R$ loss that grows as the voltage falls and the constant-power load draws more current. Second, and usually worse, the ESR's voltage drop means the load sees a lower voltage than the capacitor holds, so the load reaches its minimum input voltage while the capacitor still has energy left. Near the end the current rises so much that the supply can collapse entirely, even though the capacitor isn't empty. A low-ESR capacitor delivers more of its stored energy.
:::
:::

::: practice

::: check
given: P = 1 | 4; V = 2.5 | 5
answer: P/V
unit: A
tolerance: 0.5%

## A {P} W load runs at {V} V. What current does it draw?

::: misses
- [any] $P/V$.
:::
:::

::: check
given: n = 2..8 int
answer: n*2.7
unit: V
tolerance: 0.5%

## {n} supercapacitor cells rated 2.7 V each are stacked in series. What is the stack's maximum voltage?

::: misses
- [any] Series voltages add.
:::
:::

::: check
given: I = 0.5 | 2; esr = 0.05 | 0.3
answer: I^2*esr
unit: W
tolerance: 0.5%

## What does {esr} Ω of ESR dissipate at {I} A?

::: misses
- [any] $I^2R$.
:::
:::
:::
