BMS1
BMS1
List of Figures 3
Abstract 5
2 State of Charge 23
2.1 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.2 SoC Evaluation methods . . . . . . . . . . . . . . . . . . . . . . 25
2.2.1 Coulomb Counting . . . . . . . . . . . . . . . . . . . . . 25
2.2.2 Open Circuit Voltage method . . . . . . . . . . . . . . . 26
2.2.3 Model-Based methods . . . . . . . . . . . . . . . . . . . 28
2.2.4 Kalman filter-based methods . . . . . . . . . . . . . . . 30
2.2.5 Neural networks-based methods . . . . . . . . . . . . . . 31
2.3 Algorithm implemented . . . . . . . . . . . . . . . . . . . . . . 32
st
2.3.1 1 grade model equation . . . . . . . . . . . . . . . . . 40
2.3.2 2nd grade model equation . . . . . . . . . . . . . . . . . 41
rd
2.3.3 3 grade model equation . . . . . . . . . . . . . . . . . 42
2.3.4 4th grade model equation . . . . . . . . . . . . . . . . . 43
th
2.3.5 5 grade model equation . . . . . . . . . . . . . . . . . 44
2.3.6 6th grade model equation . . . . . . . . . . . . . . . . . 45
2.3.7 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . 46
i
CONTENTS
3 Firmware 48
3.1 Master-Slave data exchange . . . . . . . . . . . . . . . . . . . . 50
3.1.1 UART message structure . . . . . . . . . . . . . . . . . 51
3.1.2 BMS data management function . . . . . . . . . . . . . 56
3.2 SoC value calculation and validation . . . . . . . . . . . . . . . 59
4 Conclusions 61
Bibliography 63
ii
Acronyms
CC Counting Coulomb. 26
1
Acronyms
MCU Microcontroller. 48
SoC State of Charge. 5, 18, 20, 23–30, 32, 33, 39, 46, 58–60, 62
2
List of Figures
3
LIST OF FIGURES
4
Abstract
Our times are characterized by numerous electronic applications that are chang-
ing the lifestyle of many. There are devices designed for various situations and
one of the biggest challenges is making sure these applications last as much as
possible. For this purpose, rechargeable batteries are the best solution until
now, guaranteeing a permanent and clean energy storage if we talk about the
automotive industry. In fact, batteries are starting to be the most common
electrical energy storage system for an Electric Vehicle (EV) or Hybrid Elec-
tric Vehicle (HEV). In Electric Vehicles, a Battery Pack can provide several
hundred Volts, since various functions within a car depend on it, including
powering the electric motor itself. The key aspect of all these applications is
that the batteries must be constantly monitored, to have better energy con-
sumption or to take safety measures.
A Battery Management System (BMS) is an integrated system, designed to
closely monitor battery circuits, implementing protective measures in case the
battery is operating outside its normal operating area, but also acquiring data
that can be used for better power management. The State of Charge (SoC) is
one of those data that must be tracked in a battery to optimize its performance
since it is essential to know how much capacity is available.
The purpose of this thesis work is to describe a set of functions of the Battery
Management System, with particular attention to the development of an algo-
rithm for the evaluation of the State of Charge, but still having the possibility
of being able to apply these functions to generic management systems of a bat-
tery in vehicles. The system used for data validation is the one developed for
the Formula SAE ”Squadra Corse PoliTo” prototype.
5
CHAPTER 1
1.1 Introduction
Inside Electric Vehicles, the battery pack contains one or more ECUs that are
able to perform for monitoring and protection for the vehicle and the user. This
system is what is usually referred to as Battery Management System (BMS)
made of a group of ECUs exchanging information in a Master-Slave fashion.
The Slave system is a group of ECUs connected to each other forming a Daisy
Chain and connected with the Master using standard digital protocols like
UART, SPI, I2C. Its work is to perform data acquisition from the battery such
as Voltage, Current and Temperature, and sometimes it is integrated with a
circuitry for balancing. Cell Balancing is a very useful technique that can be
implemented in order to increase the available capacity of the battery, extend-
ing its life. It is a typical solution for multi-cells systems including laptops,
phones, HEV and EV.
The Master is the main ECU, this why the device is referred most of the
time as the actual BMS, performing the most important algorithms according
to the received data and it is connected to the majority of protection devices
inside this circuitry. The BMS exchanges information with the vehicle, usu-
ally communicating with a Vehicle Contol Unit (VCU) that elaborates what
is important to know about the Battery. The most common communication
protocol implemented for information exchange in automotive, between ECUs,
6
CHAPTER 1. BATTERY MANAGEMENT SYSTEM
7
CHAPTER 1. BATTERY MANAGEMENT SYSTEM
• Control field: this is the field where the length and the type of frame
are defined. The IDE is 1-bit long, it defines whether the Identifier is:
The Data Length Code is 4-bit long portion which defines the number of
Bytes of the Data field
• Data field: It is the portion containing the actual data bytes to be sent,
its length goes from 0 to 8 bytes
• CRC and ACK fields: CRC is used to detect data corruption during
transmission. ACK is the receiver acknowledgment
For protection purposes the High Voltage Battery circuit is implemented with
devices that may be controlled by the BMS master.
• Isolation Monitoring Device (IMD) which make sure that the Gal-
vanic Isolation between HV and the Grounded Low Voltage System (GLVS)
is ≥ 500Ω/V in AC and ≥ 100Ω/V in DC. It can operate on its own and
perform protection procedure or it can be connected to the Master send-
ing a signal when the Battery Pack is no more safe.
8
CHAPTER 1. BATTERY MANAGEMENT SYSTEM
Inverter in order to reach the Motors, since they work in AC. Inverter
are provided with Capacitive elements that are used for energy storage.
With High Voltage systems, inrush currents may stress a lot the capacitive
components during power up. The solution adopted was to have a parallel
channel in which a resistive component is connected limiting the amount
of current delivered to the load.
• Fuses that are used for cable management. They may be connected to
both or one of the Terminals for over-current protection.
9
CHAPTER 1. BATTERY MANAGEMENT SYSTEM
10
CHAPTER 1. BATTERY MANAGEMENT SYSTEM
Figure 1.5: Parallel (on the right) and Series (on the left) configurations
Looking at Figure 1.5, in parallel configuration the Output voltage is still the
same while the Capacity increases. The opposite occurs with series configu-
ration. Usually a set of cells in parallel is called Group connected in series
forming a Module. A set of module in series assemble a Battery Pack. This
is important for the Design since whichever it is the number of parallel cells in
a group or the number of groups in series in a module, the amount of Energy
a Module can deliver can change. Emodule = gVcell × nCcell where g = groups
in series in a module and n = cells in parallel in a group. If you take
into account that a Battery Pack contains m number of modules, the amount
of Energy delivered is EBP = mEmodule .
11
CHAPTER 1. BATTERY MANAGEMENT SYSTEM
Single rechargeable cells must be chosen taking into account different main
features
• Power density [w/Kg]: the amount of stored power per unit mass
12
CHAPTER 1. BATTERY MANAGEMENT SYSTEM
Lithium ions cells are the most employed for low power solutions like smart-
phones and lately their appearance is common when designing accumulators
for EVs.
The Anode of a Li-ion cell is made of Carbon while the cathode is a Li-metal
Oxide, which means that, whatever the metal chosen for the Cathode, the cell
performance, costs and safety features may change as shown in Figure 1.8 [2]
13
CHAPTER 1. BATTERY MANAGEMENT SYSTEM
There exist some alternatives to Li-ion cells that have been exploited, some of
them are still used, like Lead Acid batteries. They are often used as auxiliary
batteries for vehicles, in order to supply low voltage circuitry, but not involved
in the traction system. Their Energy density is low and the Nominal Voltage
is usually around 2V, nevertheless they are very durable and reliable. Nickel
batteries are another example, their Energy density is higher then the previous
one, but not as much as Li-ion batteries. Less durable than Lead-acid batteries
but their charge time is very low. Nickel-Cadmium batteries are now out of
production due to their toxicity. Li-ion batteries, compared with all these
alternatives, are far better in terms of Energy density, since it is possible to
deliver the same amount of Energy with far less unit mass, as shown in Figure
1.9 [22], saving space and improving the vehicle design.
14
CHAPTER 1. BATTERY MANAGEMENT SYSTEM
15
CHAPTER 1. BATTERY MANAGEMENT SYSTEM
16
CHAPTER 1. BATTERY MANAGEMENT SYSTEM
The capacitive elements are the one that are physically shifting energy from
one cell to the next one, this implies a sequential action between adjacent cells,
very time consuming considering also the time needed for the capacitor to be
charged. This circuit have been improved in terms of spent time and efficiency
having different configuration involving DC-DC converters like buck-boost or
fly-back converters, but increasing a lot the circuitry complexity. Nowadays
software controlled solution tried to solve the problem aiming to reduce Hard-
ware usage, gaining in space and complexity [14].
17
CHAPTER 1. BATTERY MANAGEMENT SYSTEM
The idea is based on cell bypassing having as decision criterion the SoC of the
single cell calculated by the BMS. While charging, cells that reaches full charge
are bypassed, letting other cells to join. When discharging cells with low SoC
are disconnected, having minimal loss since those cells have very low capacity.
18
CHAPTER 1. BATTERY MANAGEMENT SYSTEM
1 1
RN T C = R0 eβ( T − T0 ) with R0 = R(@T0 = 25C)
The analog value measured by the ADC is the voltage drop on the NTC
itself. The simpler way to connect the NTC is to use a pull-up or pull-
down resistors, but there are Hardware solutions that may help forcing
a linear relation between temperature and voltage acquired by the slave.
Current sensing is usually done exploiting Faraday’s law of electromag-
netic induction, as illustrated in Figure 1.13 [15]. These kind of sensors
are designed to have a circular element, in which the magnetic field is in-
duced, looping around the HV cable and having two terminals forcing
a voltage upon a plate, called Hall plate, connected to an operational
amplifier whose output voltage is the one read directly by the Master for
data managing.
19
CHAPTER 1. BATTERY MANAGEMENT SYSTEM
20
CHAPTER 1. BATTERY MANAGEMENT SYSTEM
21
CHAPTER 1. BATTERY MANAGEMENT SYSTEM
For this thesis work the system implemented, shown in Figure 1.15, is far
simpler then the one shown before (see §1.4), also because the Battery Pack
monitored this time is a Low Voltage accumulator (output voltage < 60VDC ,
according to ISO-6469 [5]), so some of those system protection components and
strategies presented previously are not needed.
22
CHAPTER 2
State of Charge
2.1 Definition
State of Charge (SoC) represents the available battery capacity with respect
to its rated capacity. The preferred SoC reference should be the rated capacity
of a new cell rather than the current capacity of the cell. This is because the cell
capacity gradually reduces as the cell ages. For example, towards the end of the
cell’s life its actual capacity will be approaching only 80% of its rated capacity
and in this case, even if the cell were fully charged, its SoC would only be 80%
of its rated capacity [10]. State of Charge (SoC) is one of the most important
states that need to be monitored to optimize the performance and extend the
lifetime of batteries, its evaluation is not direct as it involves to take under
consideration voltage, current and temperature of a cell. In EVs, the number
of battery has series-parallel combinations to match the load requirement [7].
Due to manufacturing procedures, not all cells simultaneously attain full volt-
age during charging resulting in voltage imbalance among different cells and,
consequently, lower capacity from the entire battery. Knowing the amount of
energy that a battery can deliver is vital for EVs applications requiring to con-
stantly monitor the actual capacity of the cell in order to evaluate the actual
and practical capability of the battery in order to fit the different road con-
ditions and driving patterns of the vehicle. Another parameter important to
evaluate is the State of Health (SoH) whose purpose is to provide an indica-
23
CHAPTER 2. STATE OF CHARGE
tion of the performance which can be expected from the battery in its current
condition or to provide an indication of the how much of the useful lifetime of
the battery has been consumed and how much remains before it must be re-
placed. In critical applications such as standby and emergency power plant the
SoC gives an indication of whether a battery will be able to support the load
when called upon to do so. Knowledge of the SoH will also help the engineers
to anticipate problems to make fault diagnosis or to plan replacement. This is
essentially a monitoring function tracking the long term changes in the battery
[11]. A BMS must be not only a protection circuit but also a thorough and
accurate device that can predict the SoC, SoH, capacity, and available power to
increase the efficiency and the safety of the battery. By continuously measuring
current, voltage, and temperature in batteries, the aforementioned parameters
can be estimated. The estimation of the SoC is key in a BMS, but its online and
accurate estimation remains a challenge due to strong nonlinear and complex
electrochemical reactions in the battery and because of battery characteristics
change with aging [3] [13]. There is a dependency between the actual capacity
of a cell and the rate at which the battery is charged and discharged, due to the
fact that a cell’s internal electrochemical reactions take some time, this means
that the battery cannot easily follow instantaneous charge-discharge pulses, as
it happens in EV and HEV. The consequence of this is that when charging is
complete and a load is applied to the battery to discharge it, there is a delay
before the full current can be delivered through the load. This phenomenon is
called Hysteresis and leads to SoC evaluation errors, even for direct methods
like Counting Coulomb, that involves the monitoring of instantaneous capac-
ity. There’s still the possibility to minimize this error taking in account the
behaviour, implicating more complex calculation [10].
24
CHAPTER 2. STATE OF CHARGE
25
CHAPTER 2. STATE OF CHARGE
the net charge flow from the charge in a fully charged cell. This method, known
as Counting Coulomb (CC), provides higher accuracy than most other SoC
measurements since it measures the charge flow directly. CC depends on the
current flowing from the battery into external circuits since in some applications
such as automotive batteries the ”continuous” battery current is not monitored.
Instead the current is sampled and the continuous current is reconstructed
from the samples. In such cases the sampling rate must be fast enough to
capture the current peaks and troughs associated with the acceleration and
regenerative braking corresponding to the user’s driving style [10]. At present,
the Counting Coulomb method is the most used for SoC estimation since it
is the most accurate technique for short-term calculations. The CC method
defines SoC as
Z t0 +τ
100%
SoC(t) = SoC(t0 ) + Ibat δτ
Crated t0
where SoC(t0) is the initial SoC, Crated the nominal capacity, and Ibat is the
charging/discharging current. This method cannot estimate the initial value,
so the initial SoC must be known, and has an accumulative error. As it is an
open loop estimation system, small errors will accumulate with time due to the
integration term, being a source of significant inaccuracy. Several factors affect
its accuracy, such as battery age, discharge rate, and sensor precision [13].
Open Circuit Voltage (OCV) can be defined as the voltage drop on the termi-
nals of a battery when no load is connected. SoC estimation methods commonly
impose a characterization of the OCV curve derived through a polynomial or
a look-up table, as they use either a direct OCV curve inversion method, or a
cell model-based methods. SoC is therefore determined as function of the OCV
which relation, shown by the curve in Figure 2.2, is defined as:
SoC = f −1 (OCV )
In the OCV method, the cell’s voltage is continuously measured, and the corre-
sponding SoC is obtained from a table. The method is not practical due to the
requirement of measuring OCV which means SoC estimation is not available
26
CHAPTER 2. STATE OF CHARGE
while the battery is charging or discharging thus it cannot be used in real time.
Also, the OCV–SoC relationship differs among cells and, therefore results in
unacceptable error [13]. Problems can occur with some cell chemistry, partic-
ularly Lithium which exhibits only a very small change in voltage over most of
the charge/discharge cycle. The following graph shows the discharge curve for
a Lithium-ion cell.
As you can see the cell voltage does not fall rapidly as the cell is discharged,
but for the same reason, the actual cell voltage is not a good measure of the
SoC of the cell, since the smallest error in the OCV obtained from a battery
model can lead to divergence of SoC from the actual value. The rapid fall in
cell voltage at the end of the cycle could be used as an indication of imminent,
complete discharge of the battery, but for many applications an earlier warning
is required [10].
27
CHAPTER 2. STATE OF CHARGE
Electrical Cicruit Model-based methods are widely used for real-time battery
monitoring, using a circuit model built linking together parametric resistances
and capacitors. The idea behind is that the dynamic behaviour of the battery
needs to be mathematically modelled in a way that the SoC, derived from its
relation with OCV (§ 2.2), can be evaluated by just using voltage and current
measured at the terminals of the cell, in order to do this the circuit parame-
ters need to be found considering the operating condition of the cell, making
it the very big challenge of this technique. A very simple ECM is shown in
Figure 2.3 that describes the ideal battery as an OCV source in series with a
resistance representing the cell’s internal impedance.
Starting from the ideal model, the main improvement is given by adding two
parallel RC network that describe better the transient response of the battery
voltage.
28
CHAPTER 2. STATE OF CHARGE
The primary RC network describes the charge transfer procedures while the
secondary should be modeled to describe electrochemical polarizations. Of
course the number of circuit element implies the increasing accuracy modelling
together with the computational complexity. Moreover the procedure for find-
ing the correct parameters is costly and high time consuming, not being able
anyway to fully describe the electrochemical reactions occurring inside the bat-
tery and the inaccuracies related to those. Nevertheless, once the parameters
are found, the equations for SoC are simple enough to be implemented by low
cost micro-controllers.
29
CHAPTER 2. STATE OF CHARGE
The key element in this method is the feedback network performing the correc-
tion. As shown in Figure 2.5, the output of the actual system y is compared
with the prediction of the model ŷ. The result is used for correcting the model,
if the error between the prediction and the actual estimation is too wide, apply-
ing the gain K to the model. After a certain transitory period the estimation
converges to the state of the real system, meaning that the model is able to
perform an accurate prediction of the system behaviour. Kalman filter imple-
mentation resulted as an accurate SoC and SoH estimation method for Li-ion
Battery Pack, having nevertheless some drawbacks. Its complexity and compu-
tational cost are still very high, making its implementation difficult for ordinary
micro-controllers. Of course this kind of solutions is also highly dependant on
the battery model design, any inaccuracy in the system modelling may degrade
the performance of the filter, causing slow adaptation.
30
CHAPTER 2. STATE OF CHARGE
31
CHAPTER 2. STATE OF CHARGE
32
CHAPTER 2. STATE OF CHARGE
assumption that the accumulator is always constructed using the same kind
of cell. If cell is changed during design process, the model must be redefined
according to the empirical data describing that cell behaviour. The biggest
drawback is that if the number of data available is not enough the model de-
rived is not able to characterize the cell behaviour in different conditions. Of
course there’s still the possibility to implement advanced methods, like neural
network based once, that are able to extrapolate a model even if the amount of
data does not cover the whole cell performance, but the consequence is that the
implementation for on-line monitoring using a micro-controller is not feasible.
The best solutions is to use a simpler model assuming the availability of a big-
ger data set, which requires a big workload, since it needs to test the cell many
times, and very time consuming to be completed, in order to cover as much
as possible the whole cell performance. In any case using this method those
kind of errors on SoC evaluation, coming from cell internal chemical reaction
or cell external operating conditions, should be kept at minimum. For example
in this case, having at disposal both charge and discharge characteristics let us
minimize the error derived from battery hysteresis.
33
CHAPTER 2. STATE OF CHARGE
34
CHAPTER 2. STATE OF CHARGE
35
CHAPTER 2. STATE OF CHARGE
ship between the dependent and the independent variables is not linear. This
type of regression is used when data points are present in a non-linear fashion.
The polynomial regression algorithm transforms the data points into polyno-
mial features of specified degrees and models them using the linear technique
[24].
As shown in Figure 2.9 the model is able to better follow the data-set trend.
With this kind of regression there is the possibility to better follow the data
trend, but risking to overf it. This happens when the dataset has missing or
imbalanced data or contains noisy data, becoming more evident with higher
degree polynomials. The effect is that the model adapts very well to training
data points, like the blue line in Figure 2.10, and not so good to other points,
reducing the model accuracy. A linear regression in this example gives better
results.
36
CHAPTER 2. STATE OF CHARGE
There are still ways to minimize the error derived from overfitted models, by
eliminating those weights(θ) with higher value, since they may destabilise the
model trend, but still keeping the polynomial degree [6]. What has been shown
so far was the situation in which it is necessary to predict the performance of a
system starting from a single input. In real situations the models are based on
look-up tables that contain multiple columns. The easiest situation to present
is that the dependent variable Z, has two types of inputs, X and Y , making it
possible to have a data-set that can be represented in three dimensions.
Z = θ0 + θ1 X + θ2 Y + θ3 XY + ... + θn X n + θn Y n
In order to make sure that the model is able to predict the cell trend, the first
important step is to split the dataset in two or three subsets:
• Train set: it is the actual set of data used by our model to learn about
the relation between Y and X. From here the model is training to develop
and predict the output trend trying to minimize the difference between
prediction and real data. This is done by updating the weights θ.
37
CHAPTER 2. STATE OF CHARGE
• test set: this set is omitted most of the time. This is used to perform
further observation on the model prediction, after that its performed was
considered suitable with train and validation.
Due to its great importance, the train set is usually the one containing the
majority of the variables belonging to our input look-up table. The key is to
define the percentage of variables to be given at the validation set. A too large
validation set would mean stealing learning data, while a set too small is not
able to fully validate the model trend [19]. For this work the test set has been
omitted and the dataset division has been randomly performed between train
set and validation set as shown in Figure 2.11.
38
CHAPTER 2. STATE OF CHARGE
X_training = X(index_training);
Y_training = Y(index_training);
Z_training = Z(index_training);
X_validation = X(index_validation);
Y_validation = Y(index_validation);
Z_validation = Z(index_validation);
39
CHAPTER 2. STATE OF CHARGE
This equation represents also the multi-linear regression model, since it de-
scribes a linear relationship between dependent variable and a set of indepen-
dent variables. As we already know this model is not fitted due to the non
linearity of the dataset. This can be noticed looking at Figure 2.13.
Z = θ0 + θ1 X + θ2 Y
RM SE = 11.6085
40
CHAPTER 2. STATE OF CHARGE
Form now on the model starts to have non linear behaviour, as shown in Figure
2.14. Nevertheless this equation is still not suitable with respect to the input
dataset. Moreover the RMSE value is still too high to consider the model as
good.
Z = θ0 + θ1 X + θ2 Y + θ3 XY + θ4 X 2 + θ5 Y 2
RM SE = 9.0881
41
CHAPTER 2. STATE OF CHARGE
Z = θ0 + θ1 X + θ2 Y + θ3 XY + θ4 X 2 + θ5 Y 2 + θ6 X 2 Y + θ7 XY 2 + θ8 X 3 + θ9 Y 3
θ9 = 0.0004
RM SE = 5.4602
42
CHAPTER 2. STATE OF CHARGE
Having increased the degree, the number of parameters that make up the equa-
tion has increased accordingly. RMSE value still not valid and visually the
model in not enough accurate.
Z = θ0 + θ1 X + θ2 Y + θ3 XY + θ4 X 2 + θ5 Y 2 + θ6 X 2 Y + θ7 XY 2 + θ8 X 3 +
RM SE = 3.5718
43
CHAPTER 2. STATE OF CHARGE
Z = θ0 + θ1 X + θ2 Y + θ3 XY + θ4 X 2 + θ5 Y 2 + θ6 X 2 Y + θ7 XY 2 + θ8 X 3 +
RM SE = 2.9890
44
CHAPTER 2. STATE OF CHARGE
Z = θ0 + θ1 X + θ2 Y + θ3 XY + θ4 X 2 + θ5 Y 2 + θ6 X 2 Y + θ7 XY 2 + θ8 X 3 + θ9 Y 3
θ24 = −1.087 · 10−5 , θ25 = 7.816 · 10−8 , θ26 = −2.3131, θ27 = −4.7735 · 10−8
RMSE = 1.9796
45
CHAPTER 2. STATE OF CHARGE
2.3.7 Conclusions
The last model presented is the one with the lowest value of RMSE, so the
most accurate. The overfitting is minimal in regions where train data is not
present meaning that is not required any additional work and the equation can
be still employed, despite its complexity, for a real time online calculation by
the Battery Management System Master ECU. The main problem is that the
model presented is the one trying to predict the battery trend according to
Voltage and Current with constant temperature at 23 °C. This is not enough
since temperature is constantly changing around a Battery Pack, making the
SoC to change accordingly. For this purpose, there was the attempt to develop
a model using as independent variables voltage and temperature derived from
the cell characteristic from Figure 2.7. The problem was that the little amount
of data and the difficult behaviour of the voltage at low temperature, make the
model too imprecise with many regions where overfitting occurred, especially
where the train data is less dense. Figure 2.19 shows the model obtained
using polynomial regression with 6th grade equation. This one was the most
precise obtained, but the RMSE value is still too high.
Figure 2.19
46
CHAPTER 2. STATE OF CHARGE
Between these two models presented, the V-I model is the one easier to imple-
ment. There exist in fact solutions to let the temperature around the Battery
Pack to be constant, letting cells to operate at optimal conditions.
47
CHAPTER 3
Firmware
The firmware has been structured to have three main layers. Further visual
details are shown in the Figure 3.1
48
CHAPTER 3. FIRMWARE
• Application Layer: this is the upper level of the structure, where all
interactions with an external user take place. This is the upper level
of the structure, where all the interactions with an external user take
place, in this case the battery pack itself. Here the data coming from
the lower levels are acquired and consequently the management of the
battery system takes place according to the processing of this data.
The execution of the functions belonging to the three layers is carried out by
the scheduler inside the main. The idea is to entrust the execution of certain
portions of code to three different tasks that work at three different frequencies.
In order to assure that each code portion is executed at the same frequencies,
the constraints are:
• The frequency at which each task is executed is such that the period of
execution of each task must be an integer multiple of the fastest task
t1 = a · t3
with a, b ∈ N, 1 < a < b.
t2 = b · t3
The three tasks are executed with frequency of 1 ms, 2 ms, 5 ms each. Before
the execution of the main, during an initialization phase, a timer is set that
counts the number of clock cycles that correspond to the execution frequency
of the tasks. Figure 3.2 shows the flowchart of the pieces of codes belonging
to the three tasks.
49
CHAPTER 3. FIRMWARE
50
CHAPTER 3. FIRMWARE
• START bit: it is the bit used for node synchronization and to indicate
the start of the frame. To favor a correct coding of the protocol, the
UART line is kept at a high logic level when it is not used, therefore in
idle. The START bit is the first bit to force a transition from high to low
level, for this reason it is used for synchronization.
• STOP bit: the stop bit indicates the end of the frame. In some cases
there may also be two STOP bits and is always kept at a logical high
level, before going into idle state. The two states are differentiated by
the fact that the position, and number of bits that make up the stop of
the frame is known, once the stop bit is identified.
• 8-bit data: this portion of the frame is nothing more than the actual
information to be sent. In this case its length is 8 bits, but it can vary.
The most common cases concern 6 to 9 bit data transmission
51
CHAPTER 3. FIRMWARE
The UART protocol also provides for the use of an optional bit for parity
checking.
All these are parameters set in the UART driver that manages its interface.
The transmission rate of the message is also set at this level. This parameter is
defined as Baud Rate, which would be the amount of symbols transmitted in
one second, in this case the transmission speed is set to 1 MBaud, meaning that
the transmission of one bit requires 100ns. If the master transmits the message,
this means that the transmission of a bit requires to set a timer that counts
8 clock strokes, the latter having a frequency of 80MHz. The structure of the
UART messages that the master must send to the slave ECU is predefined
by the microcontroller manufacturer, as specified in the datasheet [23]. The
communication via UART by the master, at the beginning consists in having
to program and set the slave microcontroller, following the procedures already
defined by the manufacturer, in order to carry out the actual acquisition of
the battery monitoring parameters. This occurs by interacting directly with
the microcontroller registers, setting how to manage certain peripherals. Some
examples are the setting of the voltage reading thresholds, the sampling rate
and the BAUD rate. For this reason the procedure for communicating with
the slave involves the transmission of five different types of frames:
52
CHAPTER 3. FIRMWARE
• Data: The number of data Bytes is defined in the first frame. In case the
message is a command this frame contains the amount of data to write in
the destination register. Otherwise it contains the information contained
in the target register.0
• CRC: This portion is 2 bytes long, contained in two frames, useful for
checking the correctness of the transmitted message
53
CHAPTER 3. FIRMWARE
An example of command frame is the one used for setting the Baud rate:
54
CHAPTER 3. FIRMWARE
void DMA1_IRQHandler(void)
{
DMA -> CINT = 1; /*Clear channel 1 interrupt request*/
/*UART Tx management*/
BMSTxDMACallback();
}
void DMA0_IRQHandler(void)
{
/*Interrupt request for channel 0 - UART RX*/
DMA -> CINT = 0; /*Clear channel 0 interrupt request*/
/*Disable Timer*/
LPIT0Ch1Stop();
/*Callback function for managing received values in UART*/
BMSRxDMACallback();
}
The two functions shown above handle the interrupt request when the trans-
mission and reception procedures are finished. The first calls a function that
simply allows the system to be able to transmit again. The second, on the other
hand, starts the reading of a new data received and its subsequent processing.
55
CHAPTER 3. FIRMWARE
Before reaching the phase in which the voltage and temperature values are
cyclically acquired from the slave system, the Master ECU must first perform
a series of steps, concerning the transmission of messages via UART, predefined
according to the datasheet, in order to correctly set the functionality of the slave
system. There are two first stages, the first for initialization and a second one
for setting up the analog front-end. In both these states, the messages are only
transmitted by the master, with the possibility, however, of requesting to reply
to some messages to check the correctness of the previous actions. To speed up
the procedure, already knowing the structure of the messages, they have been
built in advance and saved in a matrix, in the order in which they must be
sent. So once the system is in one of the two states, it constructs the message
and saves it in DMA ready to be transmitted.
56
CHAPTER 3. FIRMWARE
The portion of code shown above is the matrix containing the structure of the
messages to be sent to the slave system for the initialization phase. Unlike the
next phase, that is the setting of the acquisition parameters, this requires to
be performed only once, while the second must be performed for each ECU
belonging to the slave chain. Once the slave system has been correctly set up,
the data acquisition phase begins by decoding the UART messages received
from the slave chain. The structure of the received message is quite complex.
In fact it is a concatenation of messages deriving from the single ECU, starting
from the one with the highest address.
57
CHAPTER 3. FIRMWARE
The response structure of a single device in the slave chain consists of:
• Header byte: this value represents the number of bytes given in the
response, subtracted by one, considering that for each reading the value
is saved in 2 bytes. This means that if an ECU has read 6 voltage values,
the response contains 12 data bytes representing those valued and the
value of the header byte would be 11.
typedef struct {
uint16t TotalPackV;
e_BMSStatus_t status;
}s_SysInfo_t;
s_SysInfo_t BMSSysInfo;
typedef struct {
sint16t High;
sint16t Low;
sint16t Avg;
uint08t HighId;
uint08t LowId;
}s_cell_t;
s_cell_t BMS_TCELL;
s_cell_t BMS_VCELL;
58
CHAPTER 3. FIRMWARE
As for the validation of the SoC model, the parameters were acquired by writing
a log file while charging the battery pack. A device for CAN Analyzing has been
used, connected to CAN Network, reading the target values and constructing
the log file. The acquired parameters are the same ones that are supplied in
input to the model and sent to the rest of the vehicle via CAN. In the case of
this thesis work, the temperature value is not considered because the model to
be validated is based on the calculation of the State of Charge having voltage
and current as independent parameters. The log file containing voltage, current
59
CHAPTER 3. FIRMWARE
and SoC was then reworked on MATLAB in order to graphically represent these
data.Figure 3.8 represents the graphs obtained while Figure 3.9 shows the
path for processing the values up to the final graph.
60
CHAPTER 4
Conclusions
This thesis work stems from the idea of developing a management system for
high voltage accumulators in vehicles, hybrid or fully electric, in such a way
as to optimize the use of the cells, prolonging their life times and reducing the
risks deriving from a bad handling, especially if the cells are made up of lithium
batteries. One of the key parameters is what defines the state of charge of a cell.
The main objective is to design and implement a mathematical model that can
calculate the SoC parameter starting from physical characteristics that describe
the battery, such as voltage, current and temperature. This model must be
implementable with a microcontroller for an evaluation of the SoC parameter
in real time, without blocking the execution of other functions that the MCU
manages. The model was built starting from experimental data provided by
the manufacturer of the lithium cells, with which it was possible to develop a
function that describes the performance of the battery according to these tables
and predict its behavior in different situations.The final result is a fairly precise
model, able to adapt to situations other than those used for the realization
of the input data set. The main limitation of the model is that the accuracy
reached with the model is valid when the temperature is around 23 ° C. As noted
in previous chapters, temperature is a vital parameter for monitoring sudden
changes and predicting cell instability. One possible solution is to be able to
have input datasets that describe as many situations as possible. However, this
is a procedure that requires a considerable expense in terms of time, since it
61
CHAPTER 4. CONCLUSIONS
would involve filling tables with experimentally measured values. However, this
can lead to a mathematical model capable of calculating the soc more precisely
in non-standard conditions. This would favor the implementation of techniques
for good battery management such as cell balancing with control criterion based
on the state of charge of the battery. The feasibility of solutions of this type
increases if the hardware design of the ECU is carried out according to the needs
of the designer. Currently the system has been implemented using demo boards
that mount the micro controllers that were needed. These modules offer the
ability to create a system without the need for hardware development, reducing
costs and saving time, provided you have a system not tailored to implement
any specific application. A further possible improvement is the possibility of
evaluating the State of Health of a cell, which together with the SoC, are very
useful parameters to understand how much the battery is able to deliver in
terms of capacity and how many number of cycles charge and discharge is able
to withstand.
62
Bibliography
[3] Ines Baccouche, Sabeur Jemmali, Asma Mlayah, Bilal Manai, Najoua Es-
soukri, and Ben Amara. Implementation of an improved coulomb-counting
algorithm based on a piecewise soc-ocv relationship for soc estimation of
li-ion battery. International journal of renewable energy research, June
2017.
[4] BSI ISO-11898-2 Road vehicles - Controller Area Network. British Stan-
dards Institution, December 2016.
[7] K.W.E. Cheng, B.P. Divakar, Hongjie Wu, Kai Ding, and Ho Fai Ho.
Battery-management system (bms) and soc development for electrical ve-
hicles. IEEE transactions on vehicular technology, Vol. 60, January 2011.
[8] Matteo Corno, Nimitt Bhatt, Sergio M.Savaresi, and Michel Verhaegen.
Electrochemical model-based state of charge estimation for li-ion cells.
December 2014.
63
BIBLIOGRAPHY
[15] Automotive current transducer open loop technology. LEM, 2018 March.
[18] Martin Murnane and Adel Ghazel. A closer look at state of charge (soc)
and state of health (soh) estimation techniques for batteries. Analog de-
vices.
[19] Davide Nardini. Train, validation, test: cosa sono e come si usano nel
machine learning. Pulp Learning, Novembre 2020.
[20] Java T Point. Can (controller area network) protocol. URL https://www.
javatpoint.com/can-protocol.
64
BIBLIOGRAPHY
[22] Ajit Sharma. Enabling the electric future of mobility: Robotic automation
for electric vehicle battery assembly. IEEE Access, page 32, September
2019.
65