Design and Implementation of SOC Prediction for a Li-Ion Battery Pack in an Electric Car with an Embedded System

Li-Ion batteries are widely preferred in electric vehicles. The charge status of batteries is a critical evaluation issue, and many researchers are studying in this area. State of charge gives information about how much longer the battery can be used and when the charging process will be cut off. Incorrect predictions may cause overcharging or over-discharging of the battery. In this study, a low-cost embedded system is used to determine the state of charge of an electric car. A Li-Ion battery cell is trained using a feed-forward neural network via Matlab/Neural Network Toolbox. The trained cell is adapted to the whole battery pack of the electric car and embedded via Matlab/Simulink to a low-cost microcontroller that proposed a system in real-time. The experimental results indicated that accurate robust estimation results could be obtained by the proposed system.


Introduction
Li-Ion, LiPo, Pb, NiMH, and VRLA battery types are used in electric vehicles [1].Li-Ion batteries are popular because of their light weight, stability, energy intensity and long life [2].Battery packs are used to get the power to run the vehicle.The battery pack consists of serial and parallel connected battery cells.The battery management systems (BMS) are used to use batteries safely without exceeding the limit values of the battery packs.Some BMSs can do condition monitoring, fault diagnosis, state-of-charge (SOC) and state of health (SoH) estimation [3].The SOC was used to denote the usable energy of the battery pack [4].Knowing the SOC in electric vehicles gives information about how much range can be driven, and when and how long the battery will be charged.For this reason, accurate SOC determination is a crucial issue that researchers are studying.Wrong predictions may cause overcharge or over-discharge of the battery [5].
Although batteries seem to be simple, they are nonlinear and complex systems because of their physical and chemical structure.Moreover, it is important to estimate SOC of the battery accurately in battery management systems to use the battery efficiently [6].Mathematical, electrical, and electrochemical methods are used to determine the SOC of the battery; mathematical and electrochemical methods include complex equations, which is why it is hard to calculate them.These equations must be redesigned for other types of batteries.The electrical method is easy to calculate and the user can develop a battery model by looking at a datasheet of the battery or measuring the battery parameters.Successful battery models can be achieved using data sets generated by electrical methods.SOC can be estimated by direct measurement of parameters like open circuit voltage, terminal voltage, impedance, impedance spectroscopy [7][8][9][10], adaptive systems like coulomb counting modified coulomb counting, back propagation neural network, radial basis neural network, neural network, support vector machine, fuzzy neural network, Kalman filter [11][12][13][14][15][16], extended Kalman filter [17], hybrid systems like coulomb counting and extended Kalman filter combination, coulomb counting and Kalman filter combination, per-unit system and extended Kalman filter combination [18], and wavelet neural network based [19].Most of these methods are widely used and give acceptable results in various applications.
Li-Ion batteries are more stable and light-weight, and an organic electrolyte provides practical cell voltage to be above 4 V.They have high energy densities, and they provide easy applications without the need for connecting several cells in a series [20][21][22].In recent years, the need for portable power has accelerated due to the miniaturization of electronic applications, where, in some cases, the battery system is as much as half the weight and volume of the powered device [23].Li-Ion batteries have no memory effect.Therefore, users do not have to fully discharge batteries to recharge them again and do not have to fully charge [24].They are usually expensive since they require advanced knowledge of chemistry and advanced studies.
In this study, a feed-forward neural network (FFNN) neural network is proposed to predict the SOC of a Li-Ion battery pack used in an electric car.FFNN is the most popular type in artificial neural networks.The FFNN is applied in SOC estimation due to its excellent ability of nonlinear mapping and self-learning [25].As the problem defined, the relationship between input and target is nonlinear and very complicated in SOC estimation [26].
A discharge test for SOC prediction is easy, has high accuracy, is suitable for all batteries, and it is independent of the state of health of the battery.Artificial intelligence techniques can be adapted to all kind of batteries.It requires training data and works in real time [27].
In this study, SOC estimation is implemented and designed for a battery pack of an electric car with an embedded system.The SOC of one cell of the battery pack is trained with FFNN using different discharge constant current outcomes.In this way, the requirement for training data sets will reduce in addition to the reliance of artificial neural network (ANN) on data sets since constant current discharge data are easier to obtain and are usually given in battery datasheets [12].The SOC of one battery cell is adapted to the whole battery pack of the electric car via Matlab/Simulink (R2009a, Natick, MA, USA).The Matlab/Simulink model is directly embedded into a low-cost microcontroller.The developed system is portable, which can be used for other electric vehicles or systems including the battery pack.There are many studies on prediction of the SOC of Li-Ion batteries in the literature.However, a few of them include the embedded system.Using embedded systems has some advantages such as less coding, ease of use, ease of adapting to another type of battery pack connection, practicality, flexibility, fast building time, time-savings, and reliability.Thus, the study contributes to researchers, manufacturers, research and development laboratories that are related to this area.

Electric Car and Battery Pack
An electric car is developed to compete in the TÜB ˙ITAK Efficiency Challenge Electric Vehicle event.The schematic layout of the electric car is given in Figure 1.The technical specifications of the electric car are shown in Table 1.The critical measurement data, and the video of the driver and the road is stored in a black box.
A single cell Li-Ion battery has low voltage, low capacity and energy storage and may not meet the energy requirements of an electric car, so hundreds and thousands of cells are always composed through series or parallel to build up a battery system [28].The battery pack of the electric car in our system consists of 8 parallel and 28 serial connected NCR1850B Li-Ion battery cells.The BMS of the car protects the battery from threshold values, but this equipment is not able to predict the SOC of the battery.The battery cell is trained in this study and adapted to the whole battery pack of the electric vehicle.The technical properties of the single cell and the whole battery pack are given in Table 2.

Experimental Setup
In this study, an experimental setup is developed to collect electrical measurement data while charging and discharging the battery cell.Open circuit voltage, current, power, load, ambient temperature and battery temperature are measurement parameters.The measurement setup of this study is given in Figure 2. To charge the battery, Imax B8+ charge equipment (Array, Shenzhen, China) and to discharge battery Array 3711A programmable DC load equipment (LEM, Nanjing, China) are used.A circuit is designed to choose the charger or load from software.The LTS25-NP current sensor ( LEM, Geneva, Switzerland), LV25P voltage sensor ( LEM, Geneva, Switzerland) and LM35 temperature sensor (Texas Instruments, Dallas, TX, USA) are also located on this circuit.Three batteries can be connected to this circuit and the experiment battery can be chosen from the software.There are also contacts to control buttons of the charger on this circuit.The contacts on this circuit are controlled by digital I/O on an Advantech USB-4716 data acquisition (DAQ) card (Advantech, Taiwan, China).The programmable DC load is connected to the PC via an Array 3312 Seri-USB port converter (Array, Shenzhen, China).Square codes are glued to all batteries that define their identity.A Perkon Spider SP400 square code reader (Perkon, Umraniye, Turkey) is used to read codes.This equipment is connected to the computer via a USB port.A web camera is used to watch the experiments [18].

Graphical User Interface
A graphical user interface is developed in Visual Studio 2010 software (Microsoft Redmond, WD, USA) in C# programming language to monitor conditions of batteries and save the measurement data.The user selects the test battery, duration of the experiment, and sample time and chooses to charge or to discharge the battery from software.If the user decided on the discharge battery discharging method (constant current, constant load, constant power) and the discharge value is determined.If the user wants to charge and discharge the battery for a number of times, he chooses to automatically charge and discharge selection and makes some adjustments on it.Automatically charging/discharging can be done from full charge to full discharge, or it can be done for desired times.The discharge value can be adjustable.When all the adjustments are finished, an experiment code is generated automatically.A table is generated called this code in the database and the measurement data is saved to this table in real time.During the experiments, if battery exceeds the limit values of voltage, current or temperature, the experiment stops automatically [28].
In general, the SOC of a battery is defined as the ratio of its current capacity (Q(t)) to the nominal capacity (Q n ).The nominal capacity is given by the manufacturer and represents the maximum amount of charge that can be stored in the battery [18].The SOC can be defined as Equation (1): The SOC of the battery can be determined from the current curve of the battery while discharging the battery.From full charge to full discharge, the area under the current curve represents 100% SOC, and it can be estimated by the trapezoid method.The rate of remaining capacity of the battery can be calculated from Equation (2).In this equation, U A represents the used capacity of the battery, TA − U A is the remaining capacity and TA is the full capacity of the battery To obtain the data set for usage to determine the SOC of the battery pack, the battery cell is fully charged firstly and then fully discharged at constant current levels.In Figure 3

Artificial Neural Network
An ANN is basically a data-based model for mapping input/output relationships [29,30].The NN imitates the learning process of a human brain.Instead of using complex rules and mathematical routines, the NN is able to learn the key information patterns within a multi-dimensional data domain.In general, it consists of an input layer, some hidden layers and an output layer [31].Main parameters used in the SOC of battery predictions are battery terminal voltage and battery current.P and C Vt parameters can be derived from these variables.P is power and obtained by multiplying voltage and current parameters.C Vt is a counter parameter.The counter increments if the voltage is the same as the previous voltage measurement value and resets if these two parameters are different.Using only current or only voltage value gives incorrect estimation results.Using P and C Vt values increases the performance of the neural network.The input values of FFNN are normalized between 0 and 1 by dividing input value into the absolute maximum input vector value.The architecture of FFNN to determine the SOC of the battery is given in Figure 4.There are 4 inputs, 2 hidden layers and 1 output in this architecture.There are 21 neurons in each hidden layer.The number of hidden layers and neurons in hidden layers are determined by trial and error.The number that gives the best result is chosen.The input values are current (A), voltage (V), power (P) and C Vt .The output of NN is between 0 and 1.In addition, 0 represents the fully discharged battery and 1 accounts for the fully charged battery.
The voltage value of the battery can be constant for some time during the discharging process.However, during this period, the SOC of the battery is not the same, and this causes incorrect SOC estimations via a neural network.For example, as given in Figure 5, from a time to b for 400 s voltage, current and power values of the battery are the same, but the SOC is different.To protect incorrect predictions of the SOC, one more input variable called C Vt is added to the neural network.This variable is calculated from the change of voltage value using Equation ( 3).As seen Table 3, C Vt is an important parameter:  The SOC value is determined according to the measurement data.The input variables of this FFNN are voltage, current, power and time.
Eighty percent of measurement data is used as training data and 20% of measurement data is used as test data for FFNN.The FFNN neural network training results are given in Table 4.The Levenberg-Marquart learning algorithm is used and the performance is calculated using the mean squared error.It took 1338 s and 293 iterations to train the neural network.A Simulink model of FFNN is generated using the gensim() function.The success rate is 99.54% when the training data set is applied and 99.45% when the test data is applied to the neural network.There is no doubt that the success rate of this study is acceptable in literature.

Embedded System Based SOC Prediction
A low-cost STM32F4DISCOVERY card has a STM32F407VGT6 microcontroller featuring a 32-bit advanced reduced instruction set computing machine cortex.It includes an ST-LINK/V2 embedded debug tool.It has analog and digital inputs and outputs.Matlab/Simulink supports programming the microcontroller.A card is designed to use the pins efficiently.Voltage sensors, current sensors, temperature sensors, a liquid crystal display (LCD) and a secure digital (SD) card slot, and input and output connectors are located on this card.The input connector is connected to the battery grid and the output connector is connected to the electric car.The connection scheme is given in Figure 6.The Matlab/Simulink model presented in Figure 7 is embedded into STM32F4DISCOVERY.The measured values of current, voltage, temperatures and output of FFNN are viewed in real time on the LCD and saved to the SD card.The ANN gives noisy output while the input values are noisy.Therefore, the output of the neural network is filtered using a moving average method.The equation of moving average method used in this study is given in Equation (4).SOC[] is filtered SOC value, ANN[] is output of ANN; i and j are index values in this equation.

Results and Discussion
The system is tested on the electric car at the TÜB ˙ITAK Efficiency Challenge Electric Vehicle in 2016 in Kocaeli/Turkey [32].A photo of the electric vehicle is given in Figure 8. Three drives have been done on the driving track.Real-time measurements and battery packs' SOC estimations corresponding to these measurements are given below.Figures 9-11 first present graphs of battery voltage, current and C Vt parameters, and, in the following graphs, SOC and estimated SOC of the battery are given.The estimated SOC of the relative battery error rates of the first experiment is 0.75%, the second experiment is 0.27%, and the third experiment is 0.14% respectively.The average success rate is 99.61%.The results show that the system operates successfully.

Conclusions
In this study, an Li-Ion battery cell is trained using FFNN.The trained cell is adapted to an entire battery pack and used for estimating the SOC of an electric car in real time.The dataset to train FFNN is obtained from discharge curves of a single battery cell at different C rates at constant currents.The model developed in Matlab/Simulink is embedded in the low-cost STM32F4DISCOVERY kit.The system is tested in real time on the electric car and performs with a 99.61% success rate.Modelling a single cell and adapting the model to a whole battery pack made the experiments easier and time and cost savings were achieved.The C Vt parameter is an innovation of this study.Using C Vt parameters as an input variable of FFNN reduced the incorrect estimations and increased the system's accuracy.In closing, this study performs well in real-time SOC estimation of an electric car.It is possible to adapt the system to systems that include battery packs.Furthermore, this study can be used in range prediction of electric vehicles.

Figure 1 .
Figure 1.Schematic layout of the electric car.
, from left to right, 0.1 C, 0.3 C, 0.5 C, 0.8 C, 1 C, 1.2 C, 1.5 C, 1.7 C, and 2 C constant current discharging curves are given.This experimental data is used as training data for FFNN to determine the SOC of the battery.The electric car that we used in experiments does not support regenerative breaking; for this reason, only discharge data is used to train the neural network.However, it is possible for a mixture charge-discharge data pool to develop an ANN.

Figure 3 .
Figure 3. Discharging curves at different constant current levels.

Figure 4 .
Figure 4. Feed forward neural network architecture of the study.

Figure 8 .
Figure 8. Driving test of the electric vehicle.

Figure 9 .
Figure 9. (a) Battery voltage, current and C Vt parameters; (b) SOC and estimated SOC of the battery.

Figure 10 .
Figure 10.(a) Battery voltage, current and C Vt parameters; (b) SOC and estimated SOC of the battery.

Figure 11 .
Figure 11.(a) Battery voltage, current and C Vt parameters; (b) SOC and estimated SOC of the battery.

Table 1 .
Technical specifications of the electric car.

Table 2 .
Technical specifications of the single battery cell and battery pack.

Table 3 .
Input and output variables of feed forward neural network between 400 and 800 s for 0.1 C discharging dataset.

Table 4 .
Training results of FFNN.