# Solar charger: perturb and observe

A solar array gives its most power at one voltage, and that voltage moves with the sunlight. A tracker (MPPT) finds it by trying: step the duty, see whether the power rose, and keep going the same way if it did. Here you open a boost charger with a perturb-and-observe tracker, watch it climb to the peak, and then cut the sunlight in half. About 15 minutes.

`File › Open Example` is a menu path and `F5` a key.

The numbers on this page are checked by the tests of `crates/engine/tests/tutorial_wpt_charger_mppt.rs`, which run the same example. All parameters are illustrative.

## 1. Open the charger

Choose `File › Open Example › Renewable energy › Solar charger with MPPT`.

Two 60-cell modules in series (each 38 V open circuit, 9.5 A short circuit, maximum power at 31 V and 9 A) feed a boost converter that charges a 104 V battery. The battery holds the output, so the duty sets the array voltage: `Vpv = Vbat·(1 − D)`. At standard test conditions the array's most power is `62 V · 9 A` = 558 W, which needs a duty near 0.40.

## 2. Read the tracker

Every 5 ms the blocks `ZV` and `ZI` sample the array voltage and current and `Pw` multiplies them. `DV` and `DP` keep the previous samples, and the sign of `ΔP·ΔV` says which side of the peak the array is on: positive on the rising side, where the voltage must go up. A comparator turns that into 1 or 0 and a sampled integrator moves the duty by 0.01 in the right direction. The 5 ms period leaves the array's input filter time to settle between steps.

## 3. Run it

Press `F5` (0.15 s). The duty starts at <!-- run:pv.stc.start -->0.29<!-- /run --> and the sampled power `ps` first reaches 98 % of its final value at <!-- run:pv.stc.reach -->55 ms<!-- /run -->. In the last 30 ms the array gives <!-- run:pv.stc.power -->557 W<!-- /run --> at <!-- run:pv.stc.vpv -->62.0 V<!-- /run -->, with a duty of <!-- run:pv.stc.duty -->0.41<!-- /run -->, close to the 558 W and 0.40 expected from the ratings. The duty does not stop: it steps between three neighbouring values around the peak, which is the cost of tracking by trying.

## 4. Cut the sunlight

Select `PV1` and set `irr` to 500 W/m², then run. The array now peaks lower, and the tracker settles at <!-- run:pv.half.power -->279 W<!-- /run --> with a duty of <!-- run:pv.half.duty -->0.41<!-- /run -->; the array voltage is <!-- run:pv.half.vpv -->61.8 V<!-- /run -->, close to the <!-- run:pv.stc.vpv -->62.0 V<!-- /run --> at full sun: the voltage of a cell depends on the light only by its logarithm, while the current is proportional to it.

For a step, as a cloud would make, add a `Step` block (`circuit.addComponent`, kind `step`, `t0` = 0.06, `before` = 1000, `after` = 500), join its output to the `g` pin of `PV1` and run. The tracker follows the new peak within the run: in the last 30 ms the array gives <!-- run:pv.step.power -->279 W<!-- /run -->, against <!-- run:pv.half.power -->279 W<!-- /run --> for the run that started at 500 W/m².

The [manual](https://voltecx-web.nguyenvanqui291.workers.dev/docs/manual/) lists every command used here.
