A lithium-ion charger has two jobs that look like one. It must not push more current into the cell than the cell is rated for, and it must not take the cell above its charge voltage. A constant-current, constant-voltage (CC-CV) charger does both with two control loops, one inside the other, and a single clamp between them. This article builds that controller on a buck converter, shows the moment it hands over from current to voltage, and then runs a real four-cell pack through a whole charge.
The cell sets the two numbers
Both numbers come from the cell's data sheet, not from the charger. For the Molicel INR-21700-P45B (E-One Moli Energy, Product Data Sheet, Model INR-21700-P45B, version 1.2, "Charge" rows):
- charge voltage 4.2 V per cell,
- standard charge current 4.5 A, with a standard charge time of 1.5 hours,
- typical capacity 4500 mAh, and a typical DC impedance of 15 mΩ at 50 % charge.
For four cells in series the charger therefore holds at most 4.5 A and at most 16.8 V. The sheet gives no termination current; the charger designer chooses one. C/10 (0.45 A for this cell) is a common choice and is used below.
Two loops and a clamp
The power stage is a synchronous buck from 24 V. The control has two PI loops:
- The inner current loop makes the inductor current follow a reference . A feedforward duty does most of the work, so the PI only corrects. The plant from duty to current is about , and the loop crosses over well below the switching frequency.
- The outer voltage loop compares the filtered pack voltage with the target and gives .
The clamp is the whole trick: the output of the voltage PI is limited to . While the pack is below its target, the voltage error is large and positive, the PI sits on its upper limit, and : the charger is a current source. As the pack voltage approaches , the error shrinks, the PI leaves the limit, and from then on it holds the voltage: the charger is a voltage source, and the current falls by itself.
Two details matter in practice:
- Anti-windup. While the voltage PI sits on its limit, its integrator must stop integrating. Otherwise it winds up during the whole CC phase and the pack overshoots at the handover. Voltecx's
piblock holds its integrator so that its output stays betweenloandhi. - Measure the voltage at the cell. The current through the pack's internal resistance raises the terminal voltage by . Regulating the terminal voltage is right (it is what the cell's limit refers to), but it means the CV phase starts early, while the cell's rest voltage is still below the target.
The handover, simulated
The batteryCharger example uses this controller with A and V (4.15 V a cell) at 10 kHz. Its pack has a capacity of only 1 mAh, so a fraction of a second of simulated time shows the whole charge with every switching cycle; the controller's behaviour does not depend on the capacity, only the time scale does.
The simulation shows the three phases:
- CC. The current holds 5.00 A while the pack voltage climbs. The current loop is fast enough that the 2 ms mean of sits on .
- Handover. At 149 ms the mean current falls below 4.9 A: the voltage PI has left its clamp. The current turns down smoothly, without a step, because the integrator did not wind up. The 2 ms mean of the pack voltage goes 45 mV above 16.6 V before it settles: the 300 Hz filter in the voltage feedback lets the pack run a little ahead of what the loop sees. That is about 11 mV a cell; a slower filter or a lower target would trade it against ripple.
- CV. The pack voltage holds 16.61 V and the current tapers. It is below 0.5 A, a tenth of , at 233 ms, and under 10 mA at the end of the run, with the charge at 95.6 %.
In CV the current is set by the gap between the target and the cell's rest voltage, divided by the internal resistance. That gap closes as the cell fills, so the current decays roughly exponentially and never quite reaches zero.
A real pack over a real charge
A switching simulation of 1.5 hours at a 2 µs step would take billions of steps. The batteryChargerLongRun example puts four P45B cells (the data sheet's 4.5 Ah, 16.8 V, 4.5 A and 60 mΩ for the pack) behind the same controller, and simulation.batteryRun runs it on the converter's averaged model: short bursts until the current settles, then jumps of seconds to minutes in which only the battery's charge moves.
The current holds 4.5 A for 45 minutes. It reaches C/10 at 54 minutes with the pack at 99.6 %, and at the end of the data sheet's 1.5 hours the pack is at 100.0 %. The last half percent after C/10 takes nearly as long again as the CV phase before it, which is why chargers stop at a termination current rather than waiting for zero.
The pack model keeps the battery part's default rest-voltage curve (illustrative, not from the data sheet) and no RC branch, because the sheet gives neither. The times above depend on that curve; the shape of the charge does not.
Checklist
- Take and from the cell's data sheet, per cell, and multiply by the number in series. Leave margin for the tolerance of your voltage measurement: an error of 1 % is 42 mV a cell.
- Clamp the voltage PI's output at and stop its integrator while it is clamped.
- Make the current loop at least five times faster than the voltage loop, so the voltage loop sees a current source.
- Choose a termination current and say where it comes from: the data sheet, if it gives one, otherwise your own trade between charge time and capacity.
- Add the protections the loops do not provide: a charge timer, a temperature window (most cells must not be charged below 0 °C), and a pre-charge at low current for a deeply discharged cell, all per the cell's data sheet.
Try it in Voltecx
- Open the
batteryChargerexample and plotvbat,ibat,irefandsoc. ChangeIccorVcvin the variables and run again. - Open
batteryChargerLongRunand runsimulation.batteryRunwithtEnd5400, or withstopCurrent0.45 to stop at C/10. - The battery charger tutorial builds the charger step by step, and long battery runs explains the averaged run. The analyses page lists the measurements used here.