# SED3: The State of Charge Measurement This is a sub-section of my posts describing the Sustainable Energy Design 3 course group project to Design and Build a Micro Wind Turbine – for more information see here

## The Battery

We are charging 12V leisure lead acid battery. The two biggest concerns in charging a lead acid battery are:

• Overcharging – this causes sulfation in the chemicals which damage the battery in the long term and reduces its capacity
• Undercharging – inefficient and means wasting lots of power as heat dissipated in resistors which means cooling might be needed

However, at what values the battery overcharges and undercharges changes not just battery to battery but also mostly with the state of charge (SOC) whilst the battery is charging and discharging.

There are different types of charging systems to accommodate for these factors:

• Unregulated (transformer-based) chargers – cheapest chargers, wall mount transformer and a diode, deliver 13 to 14 volts over a reasonable current range, but when the current tapers off, the voltage raises to 15, 16, 17, even 18 volts
• Regulated Taper chargers – Either constant voltage or constant current is applied to the battery through a combination of transformer, diode, and resistance, don’t let the voltage climb higher than the trickle charge voltage
• Constant-current chargers – maintains a constant current below the minimum safe amount
• Constant-voltage chargers – A circuit that is set for the maximum allowable charge voltage, but has a current limit to control the initial absorption current can produce a very nice charger
• Fast chargers – measures the SOC and changes supply parameters to always achieve the maximum possible, without overcharging for that SOC

By controlling our BMS via software this enables us the flexibility to trial and implement different possible systems to find an ideal solution for our design. Ideally we will implement an effective fast charging system but we can also just program a backup plan of regulated taper charging if none of the algorithms appear to be working. To do this we will need to measure the SOC and have a method to change the supply parameters accordingly.

## State of Charge (SOC) Systems

There are a large variety of methods for measuring the state of charge (SOC) of batteries, it is an area under a lot of research.

### Voltage measurement

When you measure voltage during charging, discharging you are not measuring the open circuit voltage OCV AND even if you measure OCV, because of internal resistance and capacitance in the battery chemistry, this varies in how it relates to SOC V which is both unique to the specific battery and changes over its lifetime depending on how the battery has been used.

So you need to decide how you are relating the voltage measurements you take to the ones you ideally need from your calculation.

You can take experimental data of charging your battery a bit, measuring OCV, then charging a bit more, and then approximate this to be the calibration values across the lifetime of that specific battery. Sometimes manufacturers supply such tables themselves.

Some people believe that a very accurate way of continuously updating and measuring the actual useful voltage is sufficient to calculate the SOC without the need to look at any other variables.

### Current measurement

The most popular method of measuring SOC is by ‘Coulomb counting’ i.e. by using the battery’s chemistry to assume that there is a finite and fixed number of Coulombs to be transferred in and out and so by measuring the rate at which this happens – by integrating the flow of current measured over time, you can calculate the state of charge.

However, this requires a knowledge of the battery’s properties and also needs to calibrated using variables such as temperature which affect the current. Again, some manufacturers or research experimentally derive these properties for a specific battery and use the resulting data to then make an algorithm to accordingly interpret the readings taken, whereas others try and use machine learning to interpret either from current measurements alone or from current and temperature readings.

Generally the more information about the battery is measured, the more accurate the resulting algorithm is about the SOC and the less processing power is needed to try and calculate or estimate the other values. However combining all the variables, with their assorted errors and variations is very difficult to do normally due to the constantly changing relationships between them all. However, machine learning algorithms have proved very successful at doing this.

Use machine learning algorithms to continuously predict and then update predictions based on the measurements they take in so it continuously learns or adapts to the specific system at that point in time. There are a variety of different algorithms and many papers discussing the pros and cons of each in this context with no clear obvious single solution. Algorithms are however always a compromise of the processing power available – in our case the Photon microcontroller and any communication it can achieve between it and a more powerful computer – and the most optimum solutions.

Lots of recent research has gone into developing machine learning algorithms specifically for battery state of charge measurements. Generally the most popular methods discussed in literature are: BP neural networks; RBF neural networks; Support vector machines; Fuzzy neural networks; and Kalman filters .

Due to the limited processing power of microcontrollers, and the unreliability of communication to a higher processing unit, we are limited in our choice of suitable machine learning techniques. Additionally, we have limited time in our schedule, and limited data available for this project and so algorithms that require long times or lots of data spent ‘training’ are also not suitable for the proof of concept, but perhaps are possibilities for an ideal commercial design.

Therefore Kalman filters are a good choice – there are lots of resources available specifically within the field of battery SOC and they are easily within the processing power available on our microcontroller.

## Kalman Filters

A Kalman filter is “an algorithm that uses a series of measurements observed over time, containing statistical noise and other inaccuracies, and produces estimates of unknown variables that tend to be more precise than those based on a single measurement alone”  and in our case we are using it to gain a more accurate estimation of the battery state of charge than individual measurements alone. It is commonly used in battery SOC measurements because it is well suited to “estimate system states that can only be observed indirectly or inaccurately by the system itself.”  However, it’s use in this application isn’t perfect – Kalman filters are really supposed to be used for linear systems  which battery SOC measurements are not. This is accommodated for by either by using Extended Kalman Filters (EKFs) to approximate the battery SOC to a linear system across a particular application, or by using Unscented Kalman Filters (UKFs) which are a special type of Kalman Filter that uses a non-linear ‘unscented transform’.

EKFs suffer from linearization errors and “complicated computation of Jacobian matrix” which limit accuracy,  requires “powerful processor due to the intensive computation” and “a precise model of cell dynamics, which changes as the battery ages” and so, we have attempted to use an Unscented Kalman Filter based around that used by Zhang and Xia in 2010 . Their UKF works by merging both the Thevenin model of EMF measurement to derive SOC and Coulomb counting into one Kalman filter algorithm.

### Battery Thevenin Model

Firstly, we need to consider the Thevenin model of the battery. The actual EMF of the battery according to model is as shown in Equation 1.

Which rearranged gives us the current function in Equation 2.

We know that theoretically the internal EMF of the battery relates to SOC by Equation 3.

Coulomb counting method relates the integrated current measurements to the SOC by Equation 4.

### Kalman Filter Structure

Firstly for the Kalman filter itself we need the state matrix. This is a matrix, normally made of two variables of the same units – the variable we are trying to measure, and some kind of adjustment or bias factor in the same units. In our case that is the SOC and from the Thevenin model.

Secondly we need the state transition model, a matrix that defines how the state matrix variables should be changing with time. Normally this would be done by using the method “for each value in x, we write an equation to update that value, a linear equation in all the variables in x. Then we can just read off the coefficients to make the matrix” . However in our case we are using a non-linear equation taken from Zhang and Xia  to create F.

Then we need to define the control input which in our case is the current – this is the input we are putting back into the system and trying to predict the effect of. It will be defined as positive for charging the battery and negative for discharging.

Then we need to define the control-input model – a matrix to define the input at that moment k of measurement.

In our case that is easily derived from the equations of our models – the top function from the Coulomb counting and the second from the Thevenin model of the battery.

Thirdly in defining our system we need to account for the noise of the whole process of taking that step in time. For Kalman filters to work we have to assume that this noise is white Gaussian distributed. This needs to be defined in a symmetrical matrix of the process noise covariance – therefore identify the covariances of the system……

Therefore to define altogether how we think the system theoretically changes over time we have the prediction equation to calculate the state matrix at time k.

However, we are not directly measuring the state variables such as the SOC, we are measuring other things and deriving it. So we have to have an equation to define the observation or measurement we actually take and how that relates to the ‘true’ state we want to be looking at. This relationship is stated in the H extraction matrix and with a bias of measurement noise v.

Again the noise is assumed to be white Gaussian distributed and is defined by a matrix R. This is symmetrical and made from the variances and covariances in the errors in measurements themselves, such as from the sensors. It is an m by m matrix and shouldn’t change throughout the algorithm because the accuracy of the sensors is a property of the sensors themselves and so is fixed. We have derived the variances here by looking at the accuracy of the sensors in measuring the current and the setup used….

So now the algorithm can predict an estimate of the state matrix based on the previous state using Equation ….

It then updates the process noise covariance to an estimate according based on what the prediction is – defined with the a priori error covariance matrix P. This increases if we trust our measurements less, and decreases if we can trust them more. Ideally this should start off larger than you think and then converges to its most appropriate value, if it is too small then it is likely to completely diverge and derail the process – the less we trust, the poorer the predictions and so the less we trust, and so on in an infinite loop.

Then we define ‘the innovation’ – the difference between what we measured and what we predicted.

Then we define the innovation covariance matrix S– this is effectively the covariance of what has happened in that time step which is a result of the covariances of the theoretical process as define by P, and the covariances of the measurements and measured state.

Then we calculate the Kalman gain. This tells us how much we trust the innovation we have calculated.

Then we update the state matrix to what we actually now think it is for that time step by adding the innovation, adjusted according to the Kalman gain, to the theoretical prediction of the state.

Then similarly we update P from an estimate to what we now think it to have been for this time step.

Then we loop through it all again with the next time step!

## References

Battery University. (n.d.). Charging The Lead Acid Battery. Retrieved February 2016, from http://batteryuniversity.com/learn/article/charging_the_lead_acid_battery

Jinlong Zhang, C. X. (2011). State-of-charge estimation of valve regulated lead acid battery based on multi-state Unscented Kalman Filter.

Linden, D. (2010). Linden’s Handbook of Batteries.

Particle Core Official Website. (n.d.). Retrieved February 2016, from https://www.particle.io/

Paulson, A. (n.d.). CS373 – Programming A Robotic Car, Extra Material: Kalman Filter Matrices. Retrieved March 2016, from https://www.udacity.com/wiki/cs373/kalman-filter-matrices

Power Stream. (n.d.). SLA. Retrieved February 2016, from http://www.powerstream.com/SLA.htm

Power Stream. (n.d.). SLA Fast Charging. Retrieved February 2016, from http://www.powerstream.com/SLA-fast-charge.htm

Simon, D. (2001). Kalman Filters. In Embedded Systems Programming (pp. 72 – 79).

Wikipedia. (n.d.). Kalman Filter. Retrieved March 2016, from https://en.wikipedia.org/wiki/Kalman_filter

Yeau-Chang, W. (2013). The State of Charge Estimating Methods for Battery: A Review.

### Next: The Voltage Regulator

This is a sub-section of my posts describing the Sustainable Energy Design 3 course group project to Design and Build a Micro Wind Turbine – for more information see here