---
title: "Capstone: a solar MPPT charger"
heading: A solar panel's current–voltage curve and its single maximum power point, why connecting a panel straight to a battery wastes half its power, how a buck converter's duty cycle sets the panel's operating voltage, and a perturb-and-observe tracker that finds the peak on its own as the sun changes
eyebrow: D2 · Lesson 9 · Capstone
xp: 80
---

::: hook
A solar panel is an awkward source. Short it and it delivers its full current at no voltage; leave it open and it holds its full voltage at no current; in between there's exactly one voltage at which it delivers the most power, and that voltage drifts with sunlight and temperature. A battery, meanwhile, insists on its own voltage. A **maximum power point tracking** (MPPT) charger is a DC-DC converter placed between them, with a small algorithm that keeps adjusting the duty cycle so that the panel always sits at its peak. This capstone puts the course's converter ideas to work on that problem.
:::

::: play
- A 60-cell panel's power against its voltage, at a fraction G of full sun (8 A short-circuit current, 37 V open-circuit at full sun).
- A buck charger feeds a 13.5 V battery, so the panel's voltage is set by the duty cycle: $V_\text{panel} = V_\text{batt}/D$ (the dashed line).
- Move D to find the peak, then change the sunlight and watch the best duty cycle move: that's the tracker's job.
:::

```sim plot
view: graph
x: v = 0..40
y: P = 0..260
slider: G = 0.1..1 step 0.05 = 1
slider: D = 0.35..1 step 0.005 = 0.6
plot: v*(G*8 - 8/(exp(37/(1.2*0.025693*60)) - 1)*(exp(v/(1.2*0.025693*60)) - 1)) | samples: 500 | label: panel power, W
marker: v = 13.5/D | label: operating voltage
readout: panel voltage, V = 13.5/D | digits: 4
readout: panel power, W = 13.5/D*(G*8 - 8/(exp(37/(1.2*0.025693*60)) - 1)*(exp(13.5/D/(1.2*0.025693*60)) - 1)) | digits: 4
readout: charging current at 95%, A = 0.95/D*(G*8 - 8/(exp(37/(1.2*0.025693*60)) - 1)*(exp(13.5/D/(1.2*0.025693*60)) - 1)) | digits: 4
```

::: predict
## The panel makes 239 W at its peak, at 31.6 V. Connected straight to a 13.5 V battery, about how much power does it deliver?

- [ ] 239 W
- [ ] About 200 W
- [x] About 108 W
- [ ] Nothing: the battery's voltage is too low

::: reveal
At 13.5 V the panel is far below its knee and delivers almost its full short-circuit current, 8 A, so P ≈ 13.5 × 8 = 108 W, 45% of what it could make. A buck converter with D = 13.5/31.6 = 0.427 lets the panel run at 31.6 V while the battery takes 0.95 × 239/13.5 = 16.8 A, more than twice the current of a direct connection.
:::
:::

::: nameit
## The panel

A panel behaves like a current source (proportional to sunlight) in parallel with a diode, so its current stays near $I_{sc}$ until the voltage approaches $V_{oc}$ and then collapses. Its power, VI, has a single peak, the **maximum power point** $(V_{mp}, I_{mp})$. The **fill factor**

$$FF = \frac{V_{mp}I_{mp}}{V_{oc}I_{sc}}$$

measures how square the curve is, about 0.75 to 0.82 for silicon. Less sun lowers the current a lot and the voltage only a little; heat lowers the voltage.

## The converter

A buck converter with duty cycle D between the panel and a battery forces $V_\text{panel} = V_\text{batt}/D$ (lesson 2), so choosing D chooses where on its curve the panel runs. Power is conserved apart from losses, so the battery's charging current is $\eta P/V_\text{batt}$.

## The tracker

**Perturb and observe**: change the operating voltage by a small step, measure the power, keep going the same way if it rose and reverse if it fell. It climbs to the peak and then hops back and forth across it. Smaller steps sit closer to the peak but track changing sunlight more slowly.
:::

::: example
## The panel's peak at full sun is 31.64 V and 7.558 A, with $V_{oc}$ = 37 V and $I_{sc}$ = 8 A. Find its fill factor and the duty cycle that holds it at its peak while charging a 13.5 V battery.

::: solution
1. **Fill factor.**
   $$\begin{aligned} \text{FF} &= \frac{239.16}{37 \times 8} \\ &= 0.808 \end{aligned}$$
2. **Duty cycle.**
   $$\begin{aligned} D &= 13.5/31.64 \\ &= 0.427 \end{aligned}$$

**Answer:** the fill factor is 0.808, and a duty cycle of 0.427 holds the panel at its peak.
:::
:::

::: example
## With 5 hours of full-sun-equivalent light a day, what does the MPPT charger deliver to the battery at 95% efficiency?

::: solution
1. **Energy delivered.**
   $$\begin{aligned} E &= 239.16 \times 5 \times 0.95 \\ &= 1136\ \text{Wh} \end{aligned}$$
2. **In amp-hours.**
   $$1136/13.5 = 84\ \text{Ah}$$
   at 13.5 V.
3. **Compare with a direct connection.** That would give about
   $$108 \times 5 = 540\ \text{Wh}$$

**Answer:** about 1136 Wh a day, or 84 Ah at 13.5 V.
:::
:::

::: example
## At the panel's 239 W peak, with the charger 95% efficient, how long does it take to put 50 Ah into the 13.5 V battery?

::: solution
1. **Charging current.**
   $$\begin{aligned} I &= 239 \times 0.95/13.5 \\ &= 16.8\ \text{A} \end{aligned}$$
2. **Time.**
   $$\begin{aligned} t &= 50/16.8 \\ &= 3.0\ \text{h} \end{aligned}$$
   of full sun.
3. **In a real day.** The sun isn't full for long, so that's more like most of a day's harvest.

**Answer:** about 3.0 hours of full sun.
:::
:::

::: check
kind: python

## Model the panel, find its maximum power point, and write a perturb-and-observe tracker.

```python starter
import numpy as np

A = 1.2*0.025693*60   # diode ideality × thermal voltage × 60 cells, V

def pv_current(v, isc, voc):
    # Single-diode panel: I = isc - I0*(exp(v/A) - 1), with I0 chosen so that I(voc) = 0
    # at full sun (isc = 8 A, voc = 37 V). Pass g*8 as isc for g of full sun, with voc = 37.
    return isc

def mpp(isc, voc):
    # The panel's maximum power point (v, p): solve dP/dv = I + v*dI/dv = 0 for v in (0, Voc)
    # by bisection, where Voc at this isc is A*ln(isc/I0 + 1).
    return 0.0, 0.0

def perturb_observe(isc, voc, v0, step, n):
    # Perturb and observe: start at v0, move by step, and keep going the same way while the
    # power rises; reverse when it falls. Return the list of n voltages visited after v0.
    return [v0]*n
```

```python solution
import numpy as np

A = 1.2*0.025693*60   # diode ideality × thermal voltage × 60 cells, V

def pv_current(v, isc, voc):
    i0 = 8.0/(np.exp(voc/A) - 1)
    return isc - i0*(np.exp(v/A) - 1)

def mpp(isc, voc):
    i0 = 8.0/(np.exp(voc/A) - 1)
    vo = A*np.log(isc/i0 + 1)
    def dp(v):
        return pv_current(v, isc, voc) - v*i0*np.exp(v/A)/A
    lo, hi = 0.0, vo
    for _ in range(200):
        mid = 0.5*(lo + hi)
        if dp(mid) > 0:
            lo = mid
        else:
            hi = mid
    v = 0.5*(lo + hi)
    return v, v*pv_current(v, isc, voc)

def perturb_observe(isc, voc, v0, step, n):
    v, p = v0, v0*pv_current(v0, isc, voc)
    d = step
    out = []
    for _ in range(n):
        v2 = v + d
        p2 = v2*pv_current(v2, isc, voc)
        if p2 < p:
            d = -d
        v, p = v2, p2
        out.append(v)
    return out
```

```python tests
assert abs(pv_current(0.0, 8.0, 37.0) - 8.0) < 1e-9 and abs(pv_current(37.0, 8.0, 37.0)) < 1e-9, "At full sun the current should be 8 A at 0 V and 0 A at 37 V."
assert abs(pv_current(31.642, 8.0, 37.0) - 7.5581) < 1e-3, f"At 31.642 V the panel should give 7.558 A; got {pv_current(31.642, 8.0, 37.0):.4f}."
v, p = mpp(8.0, 37.0)
assert abs(v - 31.642) < 2e-3 and abs(p - 239.157) < 2e-3, f"Full sun's maximum power point is 31.642 V, 239.157 W; got {v:.3f} V, {p:.3f} W."
v, p = mpp(1.6, 37.0)
assert abs(v - 28.827) < 2e-3 and abs(p - 43.343) < 2e-3, f"At 20% sun it's 28.827 V, 43.343 W; got {v:.3f} V, {p:.3f} W."
vs = np.linspace(1, 36.9, 2000)
assert v*pv_current(v, 1.6, 37.0) >= np.max(vs*pv_current(vs, 1.6, 37.0)) - 1e-9, "No voltage on a fine grid should beat your maximum power point."
tr = perturb_observe(8.0, 37.0, 20.0, 0.5, 60)
assert len(tr) == 60 and abs(tr[0] - 20.5) < 1e-12, "The tracker should take 60 steps of 0.5 V starting upward from 20 V."
assert all(abs(x - 31.642) <= 1.0 + 1e-9 for x in tr[-10:]), f"After 60 steps the tracker should stay within a step or two of 31.6 V; ended at {tr[-10:]}."
assert len(set(round(x, 6) for x in tr[-10:])) <= 3, "Near the peak, perturb and observe should hop back and forth between neighboring voltages."
```

::: right
Right. Your bisection finds the 239.16 W peak at 31.64 V, and your tracker climbs to it from 20 V and then hops across it.
:::
:::

::: check
given: a = 12 | 13.5 | 26; v = 30 | 32 | 36
answer: a/v
tolerance: 0.5%

## A buck MPPT charger feeds a {a} V battery from a panel whose maximum power point is at {v} V. What duty cycle holds the panel at its peak?

::: right
Right. $V_\text{batt}/V_{mp}$ = {answer}.
:::

::: misses
- [v/a] A buck's duty cycle is output over input, less than 1.
- [any] Not yet. $V_\text{panel} = V_\text{batt}/D$.
:::
:::

::: check
given: P = 100 | 240 | 400; e = 0.93 | 0.97; a = 12.8 | 13.5 | 26
answer: e*P/a
unit: A
tolerance: 0.5%

## An MPPT charger with efficiency {e} holds a panel at its {P} W peak while charging a {a} V battery. What's the charging current?

::: right
Right. $\eta P/V_\text{batt}$ = {answer} A.
:::

::: misses
- [P/a] Include the efficiency.
- [any] Not yet. Power balance.
:::
:::

::: check
given: m = 30 | 31.6; i = 7.2 | 7.6; o = 36.5 | 37.5; s = 7.9 | 8.2
answer: m*i/(o*s)
tolerance: 0.5%

## A panel's maximum power point is {m} V at {i} A, its open-circuit voltage {o} V and short-circuit current {s} A. What's its fill factor?

::: right
Right. $V_{mp}I_{mp}/(V_{oc}I_{sc})$ = {answer}.
:::

::: misses
- [any] Not yet. Peak power over $V_{oc}I_{sc}$.
:::
:::

::: check
kind: parts
given: Vm = 30 | 31.6 | 36; Im = 5 | 7.56 | 9; Voc = 37 | 44; Isc = 8 | 9.5; B = 12.8 | 13.5 | 25.6

## A panel's maximum power point is {Vm} V at {Im} A; its open-circuit voltage is {Voc} V and short-circuit current {Isc} A. A buck charger feeds a {B} V battery.

::: part
answer: Vm*Im/(Voc*Isc)
tolerance: 0.5%

### What is the fill factor?

::: misses
- [any] $V_mI_m/(V_{oc}I_{sc})$.
:::
:::

::: part
answer: B/Vm
tolerance: 0.5%

### What duty cycle holds the panel at its peak?

::: misses
- [any] Battery voltage ÷ panel voltage, for a buck.
:::
:::
:::

::: check
kind: parts
given: P = 100 | 239 | 400; h = 3 | 5 | 6; e = 92 | 96; B = 12.8 | 13.5

## A {P} W panel gets {h} full-sun-equivalent hours a day; its MPPT charger is {e}% efficient into a {B} V battery.

::: part
answer: P*h*e/100
unit: Wh
tolerance: 0.5%

### What energy reaches the battery each day?

::: misses
- [any] Power × hours × efficiency.
:::
:::

::: part
answer: P*h*e/100/B
unit: Ah
tolerance: 0.5%

### How many amp-hours is that?

::: misses
- [any] Energy ÷ battery voltage.
:::
:::
:::

::: explain
## Why does a solar charger need a DC-DC converter between the panel and the battery?

::: model
A solar panel delivers its maximum power only at one particular voltage, which changes with sunlight and temperature, while a battery holds its terminals at its own voltage, set by its chemistry and state of charge. Connected directly, the panel is forced to the battery's voltage, usually well below its peak, where it delivers roughly its short-circuit current at a low voltage and wastes much of its potential power. A converter decouples the two: by adjusting its duty cycle, it lets the panel run at its maximum power point while delivering that power to the battery at the battery's voltage and a correspondingly higher current. A tracking algorithm keeps adjusting the duty cycle as conditions change.
:::
:::

::: practice

::: check
given: a = 6 | 50; v = 60 | 120
answer: a/v
tolerance: 0.5%

## MPPT duty: {a} V battery, {v} V peak?

::: misses
- [any] $V_\text{batt}/V_{mp}$.
:::
:::

::: check
given: P = 10 | 1000; e = 0.85 | 0.99; a = 3.7 | 48
answer: e*P/a
unit: A
tolerance: 0.5%

## Charge current: {P} W, η = {e}, {a} V?

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