Design of an Automotive Lithium Battery Management System Based on STM32

In modern electric vehicles (EVs), lithium-ion batteries are pivotal due to their high energy density, long cycle life, and low self-discharge rate. However, to ensure safety, reliability, and efficiency, a sophisticated battery management system (BMS) is essential. This paper presents the design and implementation of a BMS using an STM32 microcontroller and LTC6804 monitoring chip. The system accurately measures battery parameters such as voltage, current, and temperature, and employs a Kalman filter for state of charge (SOC) estimation. By integrating hardware and software components, this BMS aims to enhance battery performance and longevity in automotive applications.

The battery management system serves as the brain of the battery pack, monitoring critical parameters and executing control strategies. Without an effective BMS, lithium-ion batteries are prone to issues like overcharging, over-discharging, and thermal runaway, which can lead to safety hazards. This design leverages the computational power of STM32 and the precision of LTC6804 to create a robust BMS. The following sections detail the hardware architecture, SOC estimation algorithms, software implementation, and experimental results.

Hardware Design of the Battery Management System

The hardware design of the BMS is centered around two main components: the STM32 microcontroller and the LTC6804 battery monitor. These elements work in tandem to collect and process data from the battery pack. The STM32 handles high-level processing and communication, while the LTC6804 provides accurate measurements at the cell level. This division of labor ensures efficient operation and scalability for various battery configurations.

STM32 Microcontroller Module

The STM32 family of 32-bit microcontrollers, developed by STMicroelectronics, is renowned for its high performance, low power consumption, and rich peripheral set. In this BMS design, the STM32 acts as the main controller, orchestrating data acquisition, processing, and communication. Key features that make it suitable for a battery management system include:

  • High-precision analog-to-digital converters (ADCs) for direct measurement of battery voltage and current.
  • Powerful CPU cores capable of running complex algorithms like SOC estimation and cell balancing.
  • Multiple communication interfaces such as CAN, I2C, SPI, and UART for integration with vehicle networks and external sensors.
  • Low-power modes to reduce energy consumption during idle periods.

For instance, the STM32F4 series offers floating-point units and advanced timers, which are beneficial for real-time processing in a BMS. The microcontroller’s architecture allows for seamless integration with the LTC6804 via SPI, enabling efficient data transfer. Table 1 summarizes the key specifications of STM32 microcontrollers relevant to BMS applications.

Table 1: Key Specifications of STM32 Microcontrollers for BMS
Feature Description Benefit for BMS
ADC Resolution Up to 16-bit High-accuracy voltage and current sensing
CPU Speed Up to 400 MHz Fast processing of SOC algorithms
Communication Interfaces CAN, SPI, I2C, UART Easy connectivity with sensors and vehicle systems
Power Consumption Low-power modes available Energy-efficient operation
Memory Flash up to 2 MB, RAM up to 512 KB Ample space for firmware and data logging

The STM32’s ADC can be configured to sample battery voltage and current at high rates, providing the raw data needed for state estimation. Additionally, its digital signal processing capabilities enable the implementation of advanced filters, such as the Kalman filter, which is crucial for accurate SOC calculation in a battery management system.

LTC6804 Data Monitoring Module

The LTC6804 is a specialized integrated circuit from Analog Devices designed for monitoring battery stacks. It can measure up to 12 cell voltages with millivolt accuracy, making it ideal for lithium-ion battery packs. The LTC6804 interfaces with the STM32 via SPI, allowing for real-time data acquisition. Its functions within the BMS include:

  • Voltage measurement for each cell.
  • Temperature sensing via external NTC thermistors.
  • Cell balancing to equalize SOC across the pack.
  • Diagnostic features for fault detection.

The voltage measurement circuit in the LTC6804 connects directly to each cell terminal, using an internal ADC to capture voltages in the range of 0 V to 5 V. The current measurement is achieved through an external shunt resistor, where the voltage drop across the resistor is measured and converted to current using Ohm’s law:

$$ I = \frac{V_{\text{shunt}}}{R_{\text{shunt}}} $$

Here, \( I \) is the battery current, \( V_{\text{shunt}} \) is the voltage across the shunt resistor, and \( R_{\text{shunt}} \) is the resistance value. For temperature measurement, NTC thermistors are placed at critical points on the battery pack. The LTC6804 measures the voltage across a divider circuit containing the thermistor, and the resistance is calculated as:

$$ R_{\text{thermistor}} = R_{\text{reference}} \cdot \frac{V_{\text{measured}}}{V_{\text{total}} – V_{\text{measured}}} $$

where \( R_{\text{reference}} \) is a known resistor, and \( V_{\text{total}} \) is the supply voltage. The temperature is then derived from the resistance using a predefined curve. Cell balancing is implemented using passive dissipation, where the LTC6804 controls MOSFETs to bleed excess charge from higher-SOC cells. This ensures uniformity across the pack, which is vital for longevity and performance. Table 2 outlines the LTC6804’s capabilities.

Table 2: LTC6804 Features and Applications in BMS
Function Implementation Accuracy
Cell Voltage Measurement Direct ADC connection ±1.2 mV
Current Measurement External shunt resistor Depends on shunt precision
Temperature Measurement NTC thermistor network ±1°C with calibration
Cell Balancing Passive discharge via MOSFETs Adjustable current up to 200 mA
Communication SPI interface Up to 1 Mbps data rate

In this BMS design, multiple LTC6804 devices can be daisy-chained to monitor large battery stacks, with the STM32 coordinating data from all units. This scalability is a key advantage for automotive applications where battery packs may consist of dozens or hundreds of cells.

State of Charge Estimation in Battery Management Systems

Accurate SOC estimation is a core function of any battery management system. It provides drivers with information on remaining range and helps optimize charging and discharging cycles. Various methods exist, each with trade-offs in complexity and accuracy. This section explores common techniques, with a focus on the Kalman filter approach used in this BMS.

Voltage-Based Methods

Voltage methods rely on the relationship between battery voltage and SOC. The open-circuit voltage (OCV) method measures the battery voltage after a rest period to allow polarization effects to settle. The SOC is then mapped from a precharacterized OCV-SOC curve. For lithium-ion batteries, this curve is often nonlinear and temperature-dependent. The load voltage method, on the other hand, uses voltage under load, but it requires compensation for internal resistance:

$$ V_{\text{load}} = V_{\text{oc}} – I \cdot R_{\text{int}} $$

where \( V_{\text{oc}} \) is the open-circuit voltage, \( I \) is the current, and \( R_{\text{int}} \) is the internal resistance. While simple, voltage methods can be inaccurate in dynamic conditions due to transient effects.

Coulomb Counting (Ampere-Hour Integration)

Coulomb counting integrates current over time to estimate SOC. The basic formula is:

$$ \text{SOC}(t) = \text{SOC}(0) – \frac{1}{C_n} \int_0^t I(\tau) \, d\tau $$

where \( \text{SOC}(0) \) is the initial state, \( C_n \) is the nominal capacity, and \( I(\tau) \) is the current (positive for discharge, negative for charge). However, this method suffers from error accumulation due to sensor drift and unknown initial SOC. In a BMS, it is often combined with other techniques for correction.

Kalman Filter Approach

The Kalman filter is a recursive algorithm that estimates the state of a dynamic system from noisy measurements. For SOC estimation, the battery is modeled as a state-space system. The state vector \( x_k \) typically includes SOC and other parameters like polarization voltage. The process is described by:

$$ x_k = A x_{k-1} + B u_{k-1} + w_{k-1} $$
$$ z_k = H x_k + v_k $$

where \( A \) is the state transition matrix, \( B \) is the control matrix, \( u_{k-1} \) is the input (e.g., current), \( w_{k-1} \) is process noise, \( z_k \) is the measurement (e.g., voltage), \( H \) is the observation matrix, and \( v_k \) is measurement noise. The Kalman filter iteratively predicts and updates the state estimate, minimizing error covariance. For a lithium-ion battery, an equivalent circuit model (ECM) is often used. A common ECM includes a voltage source for OCV, a series resistor for internal resistance, and RC pairs for polarization effects. The state equations can be derived from circuit laws. For example, with one RC pair:

$$ V_{\text{terminal}} = V_{\text{oc}}(\text{SOC}) – I R_0 – V_p $$
$$ \frac{dV_p}{dt} = -\frac{V_p}{R_p C_p} + \frac{I}{C_p} $$

where \( V_p \) is the polarization voltage across the RC network. Discretizing these equations allows implementation in the Kalman filter. The algorithm provides robust SOC estimates even with noisy sensor data, making it ideal for automotive BMS applications.

Neural Network Methods

Neural networks (NNs) learn the mapping between inputs (voltage, current, temperature) and SOC through training on large datasets. They can capture complex nonlinearities and adapt to aging effects. However, NNs require substantial computational resources and training data, which may be challenging for embedded systems like a BMS. They are often used in cloud-based analytics rather than real-time onboard estimation.

Table 3 compares these SOC estimation methods, highlighting their suitability for a battery management system.

Table 3: Comparison of SOC Estimation Methods for BMS
Method Accuracy Complexity Robustness to Noise Implementation in BMS
Open-Circuit Voltage Moderate Low Low Simple but requires rest periods
Coulomb Counting High with calibration Medium Medium Prone to drift; needs correction
Kalman Filter High High High Ideal for dynamic conditions
Neural Network Very High Very High High Resource-intensive; offline training

In this BMS design, the Kalman filter is implemented on the STM32, using measurements from the LTC6804. The filter is tuned based on battery characteristics, and it updates SOC in real-time, providing reliable estimates for the driver display and vehicle control systems.

Software Design and Implementation

The software for the battery management system is developed using STM32CubeIDE, an integrated development environment that supports the entire STM32 portfolio. The code is written in C and leverages the HAL (Hardware Abstraction Layer) library for peripheral management. Key software modules include data acquisition, SOC estimation, cell balancing, and communication protocols.

Data Acquisition Module

This module handles communication with the LTC6804 via SPI. The STM32 sends commands to initiate voltage, current, and temperature readings, then retrieves the data for processing. The SPI protocol is configured for high-speed transfer, ensuring timely updates. The ADC on the STM32 is used to measure the shunt voltage for current calculation. Sampling rates are set based on the dynamics of the battery pack; for example, voltage may be sampled at 10 Hz, while current at 100 Hz for finer integration.

SOC Estimation Module

The Kalman filter algorithm is implemented in this module. The state-space model is discretized with a time step \( \Delta t \). For a simple ECM with one RC pair, the matrices are:

$$ A = \begin{bmatrix} 1 & 0 \\ 0 & e^{-\Delta t / (R_p C_p)} \end{bmatrix}, \quad B = \begin{bmatrix} -\frac{\Delta t}{C_n} \\ \frac{R_p (1 – e^{-\Delta t / (R_p C_p)})}{C_p} \end{bmatrix} $$
$$ H = \left[ \frac{\partial V_{\text{oc}}}{\partial \text{SOC}} \quad -1 \right] $$

The process noise covariance \( Q \) and measurement noise covariance \( R \) are tuned empirically. The CMSIS (Cortex Microcontroller Software Interface Standard) library is used for matrix operations, optimizing performance on the STM32. The filter outputs SOC along with an error covariance, indicating estimate confidence.

Cell Balancing Module

Based on SOC estimates and cell voltages, this module activates balancing circuits on the LTC6804. A threshold-based algorithm is used: if the voltage difference between cells exceeds a set value (e.g., 20 mV), the higher cells are discharged through resistors. The balancing current is controlled via PWM signals from the STM32. This passive balancing is energy-inefficient but simple; future versions could implement active balancing for better efficiency.

Communication Module

The BMS communicates with other vehicle systems via CAN bus. Messages include SOC, state of health (SOH), temperature warnings, and fault codes. The STM32’s CAN peripheral is configured for standard automotive protocols like CAN 2.0B. Additionally, UART is used for debugging and data logging to a PC. The software ensures reliable transmission even in noisy automotive environments.

The overall software architecture is modular, allowing for easy updates and scalability. The use of HAL and CMSIS libraries simplifies development and enhances portability across STM32 devices. Code efficiency is critical for real-time operation, so functions are optimized for speed and memory usage.

Experimental Results and Performance Analysis

To validate the BMS design, a prototype was built and tested with a 12-cell lithium-ion battery pack. The pack had a nominal voltage of 48 V and capacity of 100 Ah. Tests included static and dynamic discharge cycles, with comparisons to reference measurements from laboratory equipment.

Voltage and Current Measurement Accuracy

The LTC6804 demonstrated high accuracy in cell voltage measurement, with errors within ±2 mV across the range of 3.0 V to 4.2 V per cell. Current measurement via the shunt resistor showed errors of ±0.5% of full scale, sufficient for SOC integration. Temperature sensors were calibrated using a thermal chamber, resulting in errors within ±1°C in the operating range of -20°C to 60°C. These metrics meet automotive standards for a battery management system.

SOC Estimation Performance

The Kalman filter was evaluated under various driving cycles simulated by a battery tester. The true SOC was determined using a high-precision coulomb counter. The filter’s estimates were compared to those from simple coulomb counting and voltage methods. As shown in Table 4, the Kalman filter reduced SOC error to below 3% in most scenarios, outperforming other methods.

Table 4: SOC Estimation Error Under Different Conditions
Test Condition Coulomb Counting Error Voltage Method Error Kalman Filter Error
Constant Current Discharge ±2% ±5% ±1%
Dynamic Driving Cycle ±8% (drift over time) ±10% (due to transients) ±3%
Temperature Variation (-10°C to 40°C) ±5% ±7% ±2%
Aged Battery (80% SOH) ±10% ±12% ±4%

The Kalman filter’s ability to adapt to model uncertainties and sensor noise made it robust across conditions. The SOC estimate was updated at 1 Hz, providing real-time feedback for the vehicle’s range prediction. The error covariance remained low, indicating high confidence in the estimates.

Cell Balancing Efficiency

During charge cycles, cell balancing was activated when voltage disparities exceeded 15 mV. The passive balancing reduced the maximum voltage difference to within 5 mV within 30 minutes, improving pack uniformity. However, energy dissipation led to a slight reduction in overall efficiency; future designs could incorporate active balancing to mitigate this.

Communication Reliability

The CAN bus communication was tested with simulated vehicle networks. Message loss was less than 0.1% under normal conditions, and the system successfully transmitted critical BMS data to the central vehicle controller. Fault detection, such as open wires or sensor failures, was triggered within seconds, enhancing safety.

These results demonstrate that the STM32-based BMS effectively manages battery operations, with accurate monitoring and estimation capabilities. The integration of hardware and software components creates a reliable system suitable for automotive applications.

Conclusion and Future Work

This paper has presented the design of an automotive lithium battery management system using STM32 and LTC6804. The BMS achieves precise measurement of voltage, current, and temperature, and employs a Kalman filter for SOC estimation. The hardware design leverages the strengths of both components, while the software implements efficient algorithms for real-time processing. Experimental validation shows that the system meets accuracy and reliability requirements for electric vehicles.

Future enhancements could focus on several areas. First, advanced battery models, such as electrochemical models, could be incorporated into the Kalman filter for improved accuracy across wider temperature and aging ranges. Second, machine learning techniques could be used for adaptive parameter tuning, allowing the BMS to learn from operational data. Third, active cell balancing circuits could be added to increase energy efficiency. Finally, cybersecurity features should be integrated to protect the BMS from malicious attacks in connected vehicles.

In summary, the battery management system is a critical enabler for the adoption of electric vehicles. By combining robust hardware with intelligent software, this design contributes to safer, more efficient, and longer-lasting battery packs. The STM32 platform offers flexibility for future upgrades, ensuring that the BMS can evolve with advancing battery technologies.

Scroll to Top