Skip to main content
emobility.academy
PhDEdge AI & estimationResearch About 18 weeksKit + add-ons

On-Device Incremental Learning for Battery Ageing Adaptation

You build a BMS estimator on the kit's STM32 that keeps learning on the device as the battery ages, updating a small model from its own measurements stored in SPI flash, without sending data to a server. You evaluate it with accelerated ageing data replayed in hardware-in-the-loop and with the kit's real cell.

Uses: ADC · SPI · UART

The problem

Battery models are calibrated for new cells, but parameters drift as cells age, so SOC and power estimates degrade over a vehicle's life. Updating models in the field without cloud connectivity, within the memory and compute of a small BMS controller, and without unsafe or unstable behaviour, is an open problem.

Objectives

  • Design a model split into a fixed part and a small adaptable part suitable for on-device updates.
  • Implement incremental update rules (recursive least squares and last-layer gradient updates) in fixed point.
  • Use SPI flash as a bounded replay buffer of past measurements.
  • Evaluate adaptation, stability and forgetting on replayed ageing data and the kit cell.

What you need

From the EV Embedded Development Kit

  • Second STM32F103C8T6 as the Smart BMS unit
  • 1S battery with connector and T-sense input
  • Battery charging unit with its own switch
  • Charge/discharge control relay
  • Load section: three switchable resistive loads with LEDs
  • SPI flash memory
  • BMS power switch, OLED and six navigation buttons
  • Serial UART interface

Software

  • STM32CubeIDE
  • Embedded C with HAL drivers
  • Python (NumPy, SciPy, pandas, PyTorch or TensorFlow)
  • NASA PCoE and CALCE ageing datasets
  • A Python hardware-in-the-loop replay script

Extra parts

  • INA219 I2C current/power monitor module — Measured current is needed for coulomb counting labels and for the model inputs used in adaptation.

This project uses the kit's lithium cell. Respect polarity, never short the terminals, and don't leave the cell charging unattended.

Key concepts

Incremental (continual) learning
Updating a model as new data arrive, without retraining from scratch and without storing all past data.
Recursive least squares (RLS) with forgetting
An exact, cheap update for linear parameters, such as a last layer or model resistances, that discounts old data with a forgetting factor to follow drift.
Catastrophic forgetting
When updates on new data erase what the model knew about other conditions. A small replay buffer of stored past samples reduces it.
Self-supervised labels
On the device there is no true SOC, so update targets come from relationships that are known, such as voltage prediction error, or from OCV after long rests.

Step-by-step guide

  1. 1

    Define the learning problem

    Decide what adapts and from what signal. A practical choice: a fixed feature extractor or OCV table, plus adaptable parameters (R0, R1, C1 and capacity, or a network's last layer) trained to predict terminal voltage, which is always measured. Write how SOC is then obtained and what safety bounds limit each parameter. Include the rules that decide when updates are allowed, for example only after a rest period or within a known temperature range.

    Checkpoint: A formal problem statement with adaptable parameters, update targets and bounds.

  2. 2

    Build the offline reference

    Using NASA PCoE and CALCE ageing data, train the base model on early-life cycles. Show the error growing on later cycles without adaptation; this is the problem you will reduce. Then simulate the incremental update in Python on the same data to choose update rules and hyperparameters. Use these simulations to set the forgetting factor and learning rate before writing firmware, since changing them later on hardware is slow and harder to analyse.

    Checkpoint: Plots of error versus cycle for the frozen model and for simulated adaptation.

  3. 3

    Set up the BMS hardware

    Fit the INA219 with the cell disconnected. Configure the Smart BMS STM32 for ADC with DMA (voltage, T-sense), I2C (INA219), SPI (flash), relay and load GPIOs and a UART. Add a replay mode where measurements come from the PC over UART instead of the sensors. Follow lithium safety: polarity, no shorts, voltage limits and supervised charging. Check that replayed and live data share the same units, scaling and sample rate.

    Checkpoint: The controller runs from live sensors or from replayed data with the same code path.

  4. 4

    Implement fixed-point update rules

    Implement RLS with a forgetting factor for the linear parameters in Q-format, with covariance reset and bounding to avoid numerical blow-up, and a last-layer SGD update with a small fixed learning rate. Clamp parameters to physical ranges. Measure cycles per update with the DWT counter and check against the sample period. Test the updates with long synthetic runs that include sudden parameter jumps, slow drifts and periods with no excitation, where RLS can become unstable.

    Checkpoint: Updates match the Python simulation on the same inputs, with measured cost.

  5. 5

    Implement the flash replay buffer

    Store compressed summaries of past operating points (for example SOC, current and temperature bins with averaged measurements) in SPI flash in a ring with CRCs. During idle time, interleave replayed samples with new ones in updates to limit forgetting. Track flash erase counts to stay well within endurance. Choose a binning scheme that covers the operating range evenly, so the buffer does not fill with samples from the most common conditions and forget rarer ones.

    Checkpoint: The buffer survives power cycles and its contents are read back correctly.

  6. 6

    Run hardware-in-the-loop ageing experiments

    Replay full ageing campaigns from public data to the controller over UART, faster than real time, and log its estimates. Compare frozen, adaptive without replay and adaptive with replay. Measure error over life, recovery after a sudden change and parameter stability. Repeat each configuration with several cells from the public data, so results do not depend on one cell. Record parameter trajectories as well as estimation error, since stable and physically sensible parameters are part of the evidence.

    Checkpoint: Error-over-life plots from the device itself for all three configurations.

  7. 7

    Test on the kit cell

    Run the adaptive BMS on the real kit cell over many supervised cycles with the kit loads. Real ageing will be small, so also introduce controlled parameter changes, such as adding a known series resistance in the load path, to check that adaptation follows a real change in the right direction. Follow lithium safety throughout: check polarity, never short the cell, respect its voltage limits and never leave it charging unattended.

    Checkpoint: Adaptation tracks an introduced resistance change, confirmed by a direct pulse test.

  8. 8

    Study safety and failure modes

    Inject sensor faults, such as a stuck current reading, and check that adaptation does not learn the fault. Add a supervisor: freeze updates when residuals or parameters behave abnormally, and fall back to the base model. Report how quickly it reacts. Also test what happens when the supervisor wrongly freezes learning during a genuine change, and how long the model then takes to recover once updates resume. Both kinds of error belong in the safety analysis.

    Checkpoint: No unbounded parameter drift under injected faults, and measured supervisor response.

  9. 9

    Write the research contribution

    Present the method, embedded implementation cost, experiments and safety analysis. Release firmware, replay tools and logs. Discuss limits honestly: replayed data from other cells and limited real ageing on the kit. Structure the chapter around the research questions, with one section each for adaptation accuracy, forgetting, implementation cost and safety. Include an honest comparison with periodic offline recalibration and explain when each approach would be preferred in a real vehicle fleet.

    Checkpoint: A reproducible package and a draft paper-style chapter.

Testing & validation

  • Device updates verified against the Python simulation.
  • Ageing replay comparing frozen, adaptive and adaptive-with-replay.
  • Tracking of an introduced, independently measured resistance change.
  • Fault injection showing bounded behaviour.

Expected results

An adaptive BMS estimator that updates itself on a Cortex-M3 with bounded memory, measured evidence of reduced error over simulated battery life, and a safety supervisor that stops it learning from faults.

Research angle for your PhD

Research questions: can a BMS on a 20 KB RAM MCU adapt its model to ageing on the device with stable, bounded behaviour, and how much does a small flash replay buffer reduce forgetting? How should adaptation be supervised so it does not learn sensor faults? Metrics: estimation error over life, adaptation time after changes, parameter stability, cycles per update, flash wear. Baselines: frozen model, offline recalibration, adaptation without replay. Datasets: NASA PCoE and CALCE for ageing replay. A strong contribution is a safe adaptation scheme with characterised cost and fault behaviour on real hardware.

Take it further

  • Add uncertainty estimates that grow when the model is extrapolating.
  • Share learned parameters between two BMS units over CAN.
  • Compare with periodic offline recalibration.
  • Use RTC timestamps to model calendar ageing.

Viva and review questions

What target do you use for learning without true SOC?

Terminal voltage, which is always measured. Parameters are updated to reduce voltage prediction error, and SOC follows from the updated model.

How do you stop the model learning a sensor fault?

A supervisor checks residuals and parameter changes against bounds and freezes updates when they look abnormal, falling back to the base model.

How do you avoid wearing out the SPI flash?

We store compact summaries, append in a ring and erase a sector only when it fills, and we tracked erase counts to stay far below the rated endurance.

Related EV projects

All 100 EV projects