Real-Time MCU Implementation of the SPICE Equivalent-Circuit Battery Model for Li-ion HILS
This document presents a real-time C implementation of Bee Technologies' LI-ION_BATTERY simple SPICE equivalent-circuit model on an MCU for a per-cell isolated 4-channel Li-ion battery Hardware-in-the-Loop Simulation (HILS) system. Rather than solving simultaneous circuit equations in real time, the model is reformulated into discrete-time recurrence equations split across two execution rates: 1 kHz (bm_step()): Updates state-of-charge (SOC) integration with self-discharge, discharge-rate smoothing, short- and long-term RC polarization voltages, effective SOC (SOC_eff), and open-circuit voltage (OCV) via a 22-point lookup table with correction to output v_core.200 kHz (cc_update() & control loop): Computes Vref = v_core - Rs' * Iout every PWM period so series resistance (Rs) voltage drops respond immediately to load steps without a 1 ms lag.Key numerical design choices include:Exact ZOH discretization ($\exp(-\Delta t/\tau)$): Prevents oscillation or divergence across varying time constants, capacities, and time-scaling factors (TSCALE from 1 to 3600, plus tau_mode options).Double-precision SOC integration: Avoids rounding loss of small 1 ms increments that occurs in single-precision float at low C-rates.Clamping SOC_eff < 0: Prevents extreme divergence seen in the original SPICE equation.In verification against the original SPICE model under identical current profiles (0.2C, 0.5C, and 1C constant-current discharges, as well as a 2C pulse discharge to 0.5C charge), the firmware matched SPICE closely with a maximum voltage difference of 1.19 mV (1C discharge) and a 0.19% difference in time to 2.75 V. Remaining tasks include confirming product-embedding licensing and $\tau \propto NS/C^2$ intent with Bee Technologies, and implementing the hardware layer (hal_stm32g4.c) for prototype comparison.
Tsuyoshi Horigome
Annual Pro sale · Save $30
Have presentations of your own?
Share with private links, password protection, and more control over your work.