61
Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection A Thesis Topic Proposal Presented to the Faculty of the Department of Electronics and Communication Engineering College of Engineering, De La Salle University In Partial Fulfillment of The Requirements for the Degree of Bachelor of Science in Computer Engineering by:

Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

Embed Size (px)

Citation preview

Page 1: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection

A Thesis Topic ProposalPresented to the Faculty of the

Department of Electronics and Communication EngineeringCollege of Engineering, De La Salle University

In Partial Fulfillment ofThe Requirements for the Degree of

Bachelor of Science in Computer Engineering

by:

CHUA, John Robert B.CHUA, Lawrence S.

DE GUZMAN, Carlo M.LIM, Chester C.

UTTOH, Benjamin O.

March, 2014

Page 2: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

1. INTRODUCTION

1.1 Background of the Study

The most troublesome part of current electric vehicle implementations is the

battery module. Current batteries are yet to be optimized for larger capacity so as to gain

the ability of powering an electric car that matches that of gasoline powered cars.

Chemical engineers have developed various types of batteries for different uses but a

better battery is yet to be developed (Hettrich, 2014).

Engineers are in the pursuit of making current battery systems safer and more

efficient. Optimization of the battery management system of an electric vehicle is a

remedy for the lack of capacity a battery has. Methods such as battery characterization

are being implemented so as to pair up the batteries that have the most similar

characteristics thus resulting to a more efficient system. In addition, some electric car

systems can be quite problematic because of the lack of inherent safety features in its

battery management system.

Battery balancing modules improves both efficiency and safety by continuously

equalizing paired batteries while the car is running.

1.2 Statement of the Problem

Battery balancing is often done once before a battery module would be used in an

electric car. This does not solve the problem of two paired batteries becoming unbalanced

for a certain period of time rendering it inefficient and less safe. An automated

implementation that would implement the use of MOSFETS and capacitors would enable

the module to be balanced while the car is running.

Page 3: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

1.3 Objectives

1.3.1 General Objectives

To design implement an automated battery balancing module that can improve

battery lifespan, safety, and overall performance.

1.3.2 Specific Objectives

1.3.2.1 To implement the fast switching of the balancing capacitor using MOSFET.

1.3.2.2 To determine the optimal capacitor and MOSFET specification to be used.

1.3.2.3 To implement a voltage monitoring module using Android.

1.3.2.4 To optimize the balancing frequency using a PIC microcontroller.

1.3.2.5 To test the lifespan, safety and overall performance of the entire module by

means of comparison to current systems.

1.4 Scope and Delimitation

The study will include testing the devised module in three cases, immediate

charging at 75% minimum capacity, 50% minimum capacity, and 25% minimum

capacity. These conditions will be tested until the battery balancing operation gains

optimal efficiency. The group will be constrained to ideal conditions and will not

simulate the strains of actual vehicle testing. The group will devise a scaled down battery

system for the balancing module to test on. The testing would be implemented with

working standards of measurement.

1.5 Significance of Study

Nowadays, air pollution, emitted by automobiles, is the number one contributor

on destroying the environment. To prevent this issue, electric cars has been developed to

be an alternative for engine powered vehicles to lessen the pollution produced from

Page 4: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

vehicles. Unfortunately, the number one problem of electric cars are their batteries.

Batteries have different charge and discharge rate. Thus, batteries can be over discharged

and malfunction which can cause the system to fail. To prevent this from happening, an

active balancing methods has been deduced. This will ensure that the pack of batteries

will always have the same voltage level without the big energy loss that passive

balancing wastes. Furthermore, active balancing does not only prevent batteries from

getting over discharged but it will also improve the lifespan of the whole battery pack and

will ensure safety as it will prevent the failing of each individual batteries in the pack.

1.6 Description of Project

1.6.1 Block diagram

Figure 1: Block diagram of the proposed battery balancing system

Page 5: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

The 9 batteries were grouped in three paralleled connections hence “3P”. Then the

three “3Ps” would be put in series to attain 12.6V. Each of the three groups are controlled

with a slave and each of the slaves is controlled by the master module. The capacitor

switching occurs when the master sends a command to the specific slave. The slave then

controls the circuit which balances the batteries.

1.6.2 Flowchart

The master module initiates the i2c connection then waits for response of the

slaves which sends out the voltage of the batteries. This is followed by the master module

which checks whether the voltage levels of paired batteries are equal, if they are equal,

the master calls the interrupt and will wait for a certain interval before it checks again, if

not the master module sends out a command to the slaves which balances the batteries.

Figure 2: Flowchart of the proposed system

Page 6: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

1.7 Methodology

The testing of the system will be carried out in different cycles and conditions. The cycles

will be performed with the following durations:

- 75% capacity

- 50% capacity

- 25% capacity

Different capacitor models will be tested in order to obtain the optimal balancing

efficiency of the system. Lifespan and safety will be taken into consideration when

choosing the capacitor. The data acquisition system will be carried out by the individual

slave's current, voltage and temperature sensors. The derived system will be compared to

existing researches. The group will implement a test bench that will simulate the load in

typical electric car systems wherein the consumption of the power will vary. The data

will be evaluated with the following parameters:

- Accuracy of balancing.

- Precision.

- Comparison to existing researches.

Page 7: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

1.8 Gantt Chart

1.8.1 Chua, John Robert B.

Page 8: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

1.8.2 Chua, Lawrence S.

Page 9: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

1.8.3 De Guzman, Carlo M.

Page 10: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

1.8.4 Lim, Chester C.

Page 11: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

1.8.5 Uttoh, Benjamin O.

Page 12: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)
Page 13: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

1.9 Estimated Budget of the Project

Table 1: Estimated budget proposal for the entire system

Materials Quantity Price

Molicel IBR18659BC 9 P 1350.00

Presentized PCB 2 P 500.00

PIC16F877A 1 P 250.00

PIC16F88 3 P 450.00

Miscellaneous Components N/A P 200.00

Total P 2750.00

2. LITERATURE REVIEW

Page 14: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

There is an abundant amount of related literature regarding battery balancing methods

and the method that the researchers are trying to implement. Related literature can be

seen way back to the year 1993 when a research was conducted in order to extend battery

life by charge equalization [1]. This meant that the battery was to be controlled in its

charging so that it doesn't overcharge so as to extend battery life. Cell balancing among

groups of batteries which should share the same characteristics and are in parallel was

also said to be effective in extending the capacity and life span of the battery [2]. Electric

Vehicles, or EVs, use paralleled battery packs that are connected in series to reach a

certain current and voltage respectively. The researchers are attempting to implement an

efficient battery balancing method for the batteries per pack in order to make them last

longer, parallel to the goal of Cao, Schofield and Emedi in their study [3]. Currently

implemented in the Electric Vehicle's battery is the passive balancing method, where a

resistor is used to dissipate extra energy. In this research, the goal of active battery

balancing methods serve as an inspiration to implement a new style of battery balancing

which may be simpler than the methods mentioned in the past experiments done by

researchers [4]. The batteries are lithium ion batteries, where readings on past research by

Chang et al. and Lee et al. provide the constraints of where the new battery balancing

method has to fit in [5][6]. For the design method, inspiration comes from Mohamed et.

al and Baughman et. al in their research of single and double switched capacitor for

battery balancing [7][8]. Performance evaluation of previous battery balancing methods

were done by Daowd et. al which was implemented in Matlab [9]. Preindl, Danielson and

Burrelli also provided the researchers the overview and insights into the currently

implemented battery balancing methods [10]. Finally, Hettrich discusses in his paper the

challenge that Electric Vehicles are deemed to take, wherein battery life among other

Page 15: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

problems, are discussed [11]. He provided floating solutions in order to serve as

pathways for future researchers to take.

3. THEORETICAL CONSIDERATIONS

Page 16: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

3.1. PIC programming and Implementation of I2C system management bus

An integrated circuit is an electronic component that consists of several electric

circuits that are compacted together to form small single chip. These integrated circuits

are very independent that every electronic device has been using it. Most of these

integrated circuits performs a specific task but some integrated circuits can be

programmed by the use of a programming software installed on a computer and a

programming device. This programmable integrated circuits is very popular because of

its multiple features, low power consumption, and usually has low cost. The

programming language that will be used depends on the user whether it is high level

programming or assembly programming.

When programming a programmable integrated circuit, or commonly known as

PIC, configurations, e.g. what range of the oscillator is being used, are need to be set.

Because of its multiple features, pin configurations are needed to be set. These pin

configurations whether the pin is used as an input/output, analog-to-digital conversion,

pulse-width-modulation, communication such as UART, SPI, I2C and CAN, and many

more.

The I2C bus system is comprised of two lines, the SDA and the SCL line. These

two lines are used to synchronize all data transfers in the I2C bus. SCL is the clock line

that synchronizes the all the devices on your bus and the SDA line serves as the data line.

One notable thing about I2C is that both SCL and SDA lines are “open drain” drivers

which means that the chip can drive its output low but not high. With this in hand, a

Page 17: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

single pull up resistor must be provided for both lines. The value of the pull up resistors

may range from 1.8kOhm to 47kOhm.

Devices in the I2C bus are categorized into two, namely the master and the slave.

Typically, there is only one master and multiple slaves, but multi-master systems are also

being done but will not be covered by this paper. Slaves can never initiate data transfer

over the I2C bus, only the master can do this. A transfer is initiated by the master through

a start sequence. A demonstration of the start and stop sequence clocking is shown in

figure x below.

Figure 3: Timing diagram of I2C start and stop sequence

Data transfer is transmitted in lengths of 8 bits, but an acknowledge bit is always

followed by the 8 bit data, so practically speaking, each data transfer consists of 9 bits.

The maximum clock speed is defined by the device that will be used and the application

of the system. A 7 bit addressing mode will be used as the complexity of a 10 bit

addressing mode is not required, this means that the system can have a total of 127

slaves. The 7 bit address is followed by a R/W bit that denotes whether the master is

reading or writing to the slave. An acknowledge bit is also present in the 9th bit.

Page 18: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

3.2 Cell Balancing

Cell balancing is a technique that improves efficiency, lifetime, and maximizes

battery capacity. A battery balancer, which is usually a relay or high powered transistors

such as MOSFET performs the balancing by switching charges from one cell to

another. Typically, individual cells in a battery pack have different capacities and

state of charge even though it is manufactured by same machine. Without active cell

balancing, a battery pack will stop functioning or discharging once the cell with the

lowest capacity in the pack becomes empty even when the other cells are still not empty.

To prevent this and maximize the battery life, the battery balancer will discharge the cell

with the highest state of charge and use it to charge the lowest state of charge so that

when the two cells become equal, both will reach zero level at the same time.

3.3 Fast Switching Devices

The research study aims to use fast switching devices in order to implement the

said active battery balancing method. MOSFETs or Metal Oxide Semiconductor Field

Effect Transistors are utilized because they have certain advantages over other electronic

switching devices like relays and BJTs. One big difference between MOSFETs and

Relays are their switching speed. Comparing a mechanical relay to MOSFET, switching

speed of the MOSFET is faster and more reliable than a relay's. A solid state relay may

be faster, but its internal workings are composed of several MOSFETs. Such complexity

would only allow it to run slower than one single MOSFET. A BJT can be compared as a

switching device, but its unstable characteristics of relying on current would render it

much harder to control than a MOSFET which entirely relies on voltage. MOSFET

switching is done by having a voltage between the gate and the source. This would

Page 19: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

depend on whether an N or a P channel MOSFET is to be used. An N channel MOSFET

would use a positive voltage between the gate and the source in order to activate said

MOSFET, while a P channel MOSFET would use a negative voltage. Such application in

active battery balancing would use one or both kinds of MOSFETs in order for it to be

implemented.

3.4. Battery and Capacitor Characteristics and Behavior

The said research study will be utilizing a Li-ion type battery for the

implementation of active cell balancing. The battery model that will be used is

IBR18650BC from Molicel with a nominal voltage of 3.6 Volts and has a typical

capacity of 1500mAh. Battery’s measurement of stored energy is referred to as State-of-

Charge (SoC) and is expressed in percentage with 100% as a representation of a fully

charged battery. Typically, batteries should not be charged above 80% SoC to prevent

stress to the battery and prolong its life. If ever a fully charged battery is desired, the

charging process should observe its saturation time which is the time needed for the

battery to still acquire more charge despite the fact that it already matched the set

charging voltage. It is also advisable to leave the batteries at around 50% SoC during

long-time storage to minimize stress on the battery while still providing enough charge

for its leakage current. Li-ion batteries are also sensitive to over-discharge and should not

be left in storage with SoC below 20%. In case the battery was over-discharge, it should

immediately be charged up to its working voltage range or else it will be permanently

damaged.

Page 20: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

The capacitors that will be used in the said research study will vary depending on

the demands of the battery and the circuit that will be implemented. Ideally, it should

have enough capacitance to properly and effectively charge and discharge the batteries

with taking into account the frequency of the switching between the batteries. Using

capacitors as a temporary storage of energy provides an excellent job as it can charge and

discharge at a very high current. This means that the batteries can be balanced at a fast

rate given that the system demands a high frequency switching to the capacitor since it

can easily handle the fast transition of energy from one battery to another. The capacitor

selection for the active balancing will not only take into account its rated capacitance and

voltage but also the manufacturer of the capacitor to fully obtain the best capacitor for the

said application.

3.5 Android Interface

The research study also will utilize Android technology as a tablet will be used in

order to display voltage levels in the pack to be balanced. A tablet will be used in order to

display the output. Android technology can be used in such applications because it can be

connected to the circuit via a microcontroller which would send pulses for the device to

interpret. A program will be used to decode such pulses and interface it into a GUI which

can be read by the user.

Page 21: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

4. DESIGN CONSIDERATIONS

4.1 Pseudo code

4.1.1 ADC pseudo code

The ADC initialization is required so as to acquire data from the battery balancing module. This is required so as to read the voltage levels of individual batteries.

Void ADC_init(){

adcon0 = 0x01; //sets ADC acquisition

adcon1 = 0x00; //line,adc pin

adcon2 = 0x3E; //+ - vref

unsigned char ADC_getpin (unsigned charpin){

adcon00 = 0x01;

adcon01 = pin<<z;

_delay_us(1000); //wait until cap is charged

go=1;

while(go);

return adresh; // returns 8 bit data gathered from ADC}

4.1.2 I2C pseudo code initialization

This code snippet is to initialize the communications mode of the entire system.

Initi2c(){

Int scl = 0; //initialize clock line

Int sda = 0; //initialize data line

Int data[8] = “00000000”; //initialize data pin

Int address[8] = “00000000”; //initialize address pin

Page 22: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

}

4.2 Schematic Diagram

Figure 4: schematic diagram of the battery balancing module

Page 23: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

4.3 Block Diagram

Figure 5: A more detailed block diagram of the proposed battery balancing module.

The block diagram shows the setup of the whole system. 3 sets of 3 batteries are

connected in parallel so as to obtain a certain voltage rating and current rating. Each set is

connected to a slave which is basically a voltage reader that utilizes the analog to digital

conversion function of the PIC microcontroller. From there, data is gathered from the

slaves to the master using the I2C protocol. A bus is needed for the data bits to travel

from the slaves to the master. The master is the one that gathers the data. The process

works in the following manner: the master module will tell the slaves that something is

not balanced, and the slaves will correct it by themselves. Data collected is sent thru the

Universal Asynchronous Receiver/Transmitter Protocol to a USB-UART Module which

can communicate with the Android Device so that it can display the output in the tablet.

Page 24: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

5. DATA AND RESULTS

Data collection

Data collection is implemented together with the Android display in the tablet. An excel

spreadsheet is provided together with the program in order to collect and save data for later

analysis. From the circuits, the master module will provide data display from the slaves and

transmit it using the USB-UART module. Bit stream is interpreted by the Android device for

display and data is also saved into the spreadsheet where quantitative data regarding different

parameters like voltage, temperature among others are arranged in columns.

Model

Figure 6: Model of the Battery Balancing Module

Parts list I2c Codes New pics android codes android scrnshot

Page 25: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

Data:

Figure 7: Schematic model of the Bidirectional MOSFET

Page 26: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

Figure 8: Actual Implementation of the Schematic Diagram

Page 27: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 213.9

3.95

4

4.05

4.1

4.15

4.2

Voltage vs Time for 100 uF (50 ms switching time)

B1 B2 B3

Time (mins)

Volta

ge (V

)

1 2 3 4 5 60

0.5

1

1.5

2

2.5

3

3.5

4

4.5

Voltage vs Time for 100 uF (100 ms switching time)

B1 B2 B3

Time (mins)

Volta

ge (V

)

Page 28: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 243.3

3.4

3.5

3.6

3.7

3.8

3.9

4

4.1

4.2

Voltage vs Time for 1 mF (50 ms switching time)

B1 B2 B3

Time (mins)

Volta

ge (V

)

Page 29: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

1 2 3 4 5 6 7 80

0.5

1

1.5

2

2.5

3

3.5

4

4.5

Voltage vs Time for 10 uF (50 ms switching time)

B1 B2 B3

Time (mins)

Volta

ge (V

)

1 2 3 4 5 6 7 83.4

3.5

3.6

3.7

3.8

3.9

4

4.1

4.2

Voltage vs Time for 1 uF (50 ms switching time)

B1 B2 B3

Time (mins)

Volta

ge (V

)

Page 30: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

Table 1: Testing for Battery Internal Resistance

Battery Voltage Load (2.5 ohms)

I, 2.5 ohms

Load (2.5 ohms)

I, 2.5 ohms

1 3.834 3.68 V 1.3 A 3.821 V 0.86 A2 3.948 3.824 V 1.36 A 3.931 V 1.47 A

Formula for computation of Internal Resistance:

Internal Resistance=V 1−V 2

I 1−I 2

Battery 1: 167mΩ=3.68V−3.821V1.3 A−0.41 A

Battery 2: 120mΩ=3.864V−3.931V1.36 A−0.47 A

Page 31: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

Therefore, Rtotal = 120 mΩ + 90 mΩ = 210 mΩ.

Maximum voltage tested = 4.045 Volts.

4.045V210mΩ

= 19.262 A.

Therefore, MOSFET saturation current >> 19.262 A.

Page 32: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

Figure 9: Schematic Diagram of the Simulated Circuit

Page 33: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

Figure 10: Actual Implementation of the Circuit – Version 1

Figure 11: Actual Implementation of the Circuit – Version 2

Page 34: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

I2C Communications:

The data of the voltage and temperature of the battery are being collected by converting their

analog data into digital by the Analog-to-Digital Conversion of the pic. As soon as the data is

collected, the pic connected to the battery, which is called Slave, will send it to another pic,

called Master, using Inter-Integrated Circuit or commonly known as I2C. The Master will begin

by sending a start bit followed by SSPADD. The SSPADD determines the address of the slave

and whether the Master wants to Read from or Write to the Slave. If the address sent by the

master is equal to the slave, an acknowledgement will be sent by the Slave. Then, the data will

be sent by the slave. When the data is sent, the Master will now send an acknowledgement to the

Slave for it to know that the data was accepted. A stop bit will also be sent by the master to end

the transmission.

I2C Slave Code:

/* * File: i2cSlave_pic16f1823.c * Author: carlo * * Created on March 1, 2014, 3:09 PM */

#include <stdio.h>#include <stdlib.h>#include <xc.h>#include <pic16f1823.h>/*#pragma config FOSC = INTOSC#pragma config PWRTE = ON#pragma config LVP = OFF#pragma config WDTE = OFF#pragma config CP = OFF*/

__CONFIG (FOSC_INTOSC & WDTE_SWDTEN & PWRTE_ON & MCLRE_ON & CP_OFF & CPD_OFF & BOREN_OFF & CLKOUTEN_OFF & IESO_OFF);__CONFIG (FCMEN_OFF & WRT_OFF & PLLEN_OFF & STVREN_OFF & LVP_OFF );

Page 35: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

#define ADDRESS_I2C 0x30

/* * */unsigned char dummy;

void interrupt isr();main(){// initialization// internal oscillator //set to 8MHz IRCF3 = 1; IRCF2 = 1; IRCF1 = 1; IRCF0 = 0;//set system clock select bits to internal osc SCS1 = 1; SCS0 = 0;// i2c slave init TRISC = 0x03; // Make i2c pins input SSP1CON1 = 0b00110110; // Enable MSSP module as I2C slave w/ 7bit addr SSP1CON3bits.SDAHT = 1; // 300ns hold time on SDA after SCL falling edge SSP1CON3bits.AHEN = 1; // Address Hold Enable SSP1ADD = (ADDRESS_I2C<<1); // Slave Address GIE = 1; PEIE = 1; SSP1IE = 1; // Enable interrupts SSP1IF = 0; TRISA = 0; //SSP1MSK = 0xFE; while(1);}

void interrupt isr(){ if(SSP1IF){ if(1){ // State 1: Write operation, last byte was an address if(!R_nW && !D_nA && BF){ SSP1IF = 0; dummy = SSP1BUF; //I2C_var1 = 0; CKP = 1; } // State 2: Write operation, last byte was an data else if(!R_nW && D_nA && BF){ SSP1IF = 0; //I2C_receiveArray[I2C_var1++] = SSP1BUF; CKP = 1;

Page 36: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

} // State 3: Read operation, last byte was an address else if(R_nW && !D_nA){ SSP1IF = 0;

dummy = SSP1BUF; //I2C_var2 = 0; SSP1BUF = 0x04; CKP = 1; } // State 4: Read operation, last byte was an data else if(R_nW && D_nA && !BF){ // RC4 = 0; SSP1IF = 0; SSP1BUF = 0x01;

CKP = 1; } // State 5: Slave I2C logic reset by NACK from master else if(D_nA && !BF && CKP){

} } }}

Page 37: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

I2C Master Code:

/* * File: i2cMaster.c * Author: carlo * * Created on February 25, 2014, 8:44 PM */

#include <stdio.h>#include <stdlib.h>#include <pic16f877a.h>#include <xc.h>

#pragma config FOSC = HS#pragma config PWRTE = ON#pragma config LVP = OFF#pragma config WDTE = OFF#pragma config CP = OFF

#define _XTAL_FREQ 16000000#define CLOCKSPEED 1000#define BAUDRATE 19200#define CTRLIN 0XA0 // Control In Byte configures the EEPROM to be in input mode#define CTRLOUT 0XA1 // Control Out Byte configures the EEPROM to be in output mode#define TEST_PIC#define I2C_DEBUG

void wait_SSPIF();void init_I2C();void init_UART();void sendByte_I2C(unsigned char TX);void UART_send(unsigned char data);void dispError();void errorCheck_I2C();unsigned char readFrom_PIC(unsigned char ctrl);unsigned char readFrom_EEPROM(unsigned char ctrl, unsigned char address);void writeTo_PIC(unsigned char ctrl, unsigned char data);void writeTo_EEPROM(unsigned char ctrl,unsigned char address, unsigned char data);void UART_sendString(unsigned char* data);void UART_sendHex(unsigned char data);void UART_sendBytes(unsigned char* data, unsigned char num);

main(){ init_I2C(); init_UART(); //while(1) UART_send('A');

Page 38: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

#ifdef TEST_EEPROM TRISB = 0; PORTB = 0; //writeTo_EEPROM(1,0,0x12); //writeTo_EEPROM(0,0,0x21); while(1){ PORTB = readFrom_EEPROM(1,0); __delay_ms(500); } //PORTB = readFrom_EEPROM(0,0);#endif

#ifdef TEST_PIC TRISB = 0; PORTB = 0; while(1){ readFrom_PIC(0x30); __delay_ms(1000); }#endif

}

void init_I2C(){ SSPSTAT = 0x80;//10X0 0000 SMB off & SMP std mode SSPCON = 0x28;//0X1X 1000 SSPEN on & Master mode SSPADD = (_XTAL_FREQ/(4*CLOCKSPEED)) - 1; TRISC = 0B00011000; SSPIF = 0;}void init_UART(void){//sync =1 syncro, sync = 0 ascn// spen = 1;// 8 bit

/* TRISC6 = 0; TRISC7 = 1; SPBRG = 129; BRGH = 1; TXSTA = 0x24; //00100100 RCSTA = 0x90;*/ SPEN = 1; CREN = 0; ADDEN = 0; TXSTA = 0b00100100;// SPBRG = 129; TRISC6 = 0; TRISC7 = 1; //SPBRG = (_XTAL_FREQ/(16*BAUDRATE))-1; SPBRG = 51;}

Page 39: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

void UART_send(unsigned char data){

while(!TXIF); TXREG = data;}

/*Reading from PIC*/unsigned char readFrom_PIC(unsigned char address){

unsigned char read_ctrl = (address<<1) | 1; //read_ctrl =| 1;

unsigned char read_bat = 0x00;

#ifdef I2C_DEBUG UART_sendString("\r\nI2C Master Read\r\n"); UART_sendString("Start Condition\r\n");#endif /*Start*/ RSEN = 1; wait_SSPIF();#ifdef I2C_DEBUG UART_sendString("Sending Start bit was successful!\r\n"); UART_sendString("Sending address..\r\n");#endif /*Control Byte*/ sendByte_I2C(read_ctrl); wait_SSPIF(); //errorCheck_I2C();#ifdef I2C_DEBUG UART_sendString("Adress sent\r\n");#endif#ifdef I2C_DEBUG if(ACKSTAT){ UART_sendString("Slave Acknowledge failed\r\n"); return 0; }#endif

#ifdef I2C_DEBUG UART_sendString("Slave Acknowledge was successful!\r\n"); UART_sendString("Start Receiving data\r\n");#endif /*Start Receive*/ RCEN = 1; wait_SSPIF();

read_bat = SSPBUF;#ifdef I2C_DEBUG UART_sendString("Data was received successfully!\r\n"); UART_sendString("Data was:\r\n");

Page 40: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

UART_sendHex(read_bat); UART_sendString("\r\nSending Acknowledgement\r\n");#endif ACKDT = 1; //ACKDT is originally = 0 ACKEN = 1; //Send Acknoweldge bit wait_SSPIF();#ifdef I2C_DEBUG UART_sendString("Acknowledgement sent!\r\n"); UART_sendString("Sending Stop bit\r\n");#endif /*Stop*/ PEN = 1; wait_SSPIF();#ifdef I2C_DEBUG UART_sendString("SUCCESSFULY READ from Slave\r\n"); #endif

return read_bat;

}unsigned char readFrom_EEPROM(unsigned char ctrl, unsigned char address){

unsigned char ctrl_in = CTRLIN | (ctrl<<1); unsigned char ctrl_out = CTRLOUT | (ctrl<<1); unsigned char read_bat; /*Start*/ RSEN = 1; wait_SSPIF(); /*Send Control IN*/ sendByte_I2C(ctrl_in); wait_SSPIF(); errorCheck_I2C(); /*Send address*/ sendByte_I2C(address); wait_SSPIF(); errorCheck_I2C();

RSEN = 1; // Sends Restart Bit so that EEPROM will distinguish that the next data byte will be a control byte. wait_SSPIF(); // Wait until tranmission is finished. /*Send Control OUT*/ sendByte_I2C(ctrl_out); wait_SSPIF(); errorCheck_I2C();

/*Start Receive*/ RCEN = 1;

Page 41: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

wait_SSPIF();

ACKDT = 0; //NACK bit ACKEN = 1; //Send Acknoweldge bit

/*Stop*/ PEN = 1; wait_SSPIF();

//read_bat = SSPBUF;

return SSPBUF;

}

/*Writting to EEPROM*/void writeTo_EEPROM(unsigned char ctrl,unsigned char address, unsigned char data){

unsigned char ctrl_in = CTRLIN | (ctrl<<1); unsigned char ctrl_out = CTRLOUT | (ctrl<<1); /*start*/ SEN = 1; wait_SSPIF(); /*Send control*/ sendByte_I2C(ctrl_in); wait_SSPIF(); errorCheck_I2C(); /*Send Address*/ sendByte_I2C(address); wait_SSPIF(); errorCheck_I2C(); /*Send data*/ sendByte_I2C(data); wait_SSPIF(); errorCheck_I2C(); /*Stop*/ PEN = 1; wait_SSPIF(); __delay_ms(1); return;}

/*Writting to PIC*/void writeTo_PIC(unsigned char ctrl, unsigned char data){ /*Start*/ SEN = 1; wait_SSPIF();

/*Send Ctrl*/ //sendByte_I2C(); wait_SSPIF(); errorCheck_I2C();

Page 42: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

/*Send data*/ //sendByte_I2C(); wait_SSPIF(); errorCheck_I2C(); /*Stop*/ PEN = 1; wait_SSPIF(); return;}

/**/void wait_SSPIF(){ while(!PIR1bits.SSPIF); PIR1bits.SSPIF = 0;}void sendByte_I2C(unsigned char TX){ SSPBUF = TX;}

void errorCheck_I2C(){ if(ACKSTAT) dispError();}

void dispError(){ PORTB = 0xFF; while(1);}void UART_sendString(unsigned char *data){ while(*data!=0) UART_send(*data++);}

void UART_sendHex(unsigned char data){ char buffer[2]; for(int i=1; i>=0; i--){ if(data%16 < 10) buffer[i] = (data%16 + 48); else buffer[i] = (data%16 - 10 + 'A'); data/=16; } UART_sendBytes(buffer,2);}void UART_sendBytes(unsigned char *data, unsigned char num){ for(int i=0;i<num;i++) UART_send(*data++);}

Page 43: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

Android Application UI:

Figure 12: Android User Interface – Version 1

Android Application Code:

package com.prolific.pl2303hxdsimpletest;

import java.io.IOException;import java.util.Arrays;import java.util.Random;

import tw.com.prolific.driver.pl2303.PL2303Driver;import tw.com.prolific.driver.pl2303.PL2303Driver.DataBits;import tw.com.prolific.driver.pl2303.PL2303Driver.FlowControl;import tw.com.prolific.driver.pl2303.PL2303Driver.Parity;import tw.com.prolific.driver.pl2303.PL2303Driver.StopBits;import android.app.Activity;import android.app.ActivityManager;import android.app.PendingIntent;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.content.IntentFilter;import android.content.SharedPreferences;import android.hardware.usb.UsbManager;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.preference.PreferenceManager;import android.text.format.Time;

Page 44: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

import android.util.Log;import android.view.Menu;import android.view.View;import android.widget.Button;import android.widget.TextView;import android.widget.Toast;

public class ActiveBalancing extends Activity { PL2303Driver mSerial;

private Button btn_Refresh; private TextView txt_Voltage; private int mDisplayType = DISP_CHAR; private int mReadLinefeedCode = LINEFEED_CODE_LF; private PL2303Driver.BaudRate mBaudrate = PL2303Driver.BaudRate.B9600; private PL2303Driver.DataBits mDataBits = PL2303Driver.DataBits.D8; private PL2303Driver.Parity mParity = PL2303Driver.Parity.NONE; private PL2303Driver.StopBits mStopBits = PL2303Driver.StopBits.S1; private PL2303Driver.FlowControl mFlowControl = PL2303Driver.FlowControl.OFF; private static final String ACTION_USB_PERMISSION = "com.prolific.pl2303hxdsimpletest.USB_PERMISSION";

public int PL2303HXD_BaudRate; public String PL2303HXD_BaudRate_str="B4800";

private String strStr; @Override public void onCreate(Bundle savedInstanceState) { Log.d(TAG, "Enter onCreate"); super.onCreate(savedInstanceState); setContentView(R.layout.activity_pl2303_hxdsimple_test); Button mButton01 = (Button)findViewById(R.id.button1);

mButton01.setOnClickListener(new Button.OnClickListener() {

public void onClick(View v) {openUsbSerial();

}});

mSerial = new PL2303Driver((UsbManager) getSystemService(Context.USB_SERVICE), this, ACTION_USB_PERMISSION); if (!mSerial.PL2303USBFeatureSupported()) {

Page 45: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

Toast.makeText(this, "No Support USB host API", Toast.LENGTH_SHORT) .show();

Log.d(TAG, "No Support USB host API");

mSerial = null;

} Log.d(TAG, "Leave onCreate"); }//onCreate

protected void onStop() { Log.d(TAG, "Enter onStop"); super.onStop(); Log.d(TAG, "Leave onStop"); } @Override protected void onDestroy() { Log.d(TAG, "Enter onDestroy"); if(mSerial!=null) { mSerial.end(); mSerial = null; } super.onDestroy(); Log.d(TAG, "Leave onDestroy"); }

public void onStart() { Log.d(TAG, "Enter onStart"); super.onStart(); Log.d(TAG, "Leave onStart"); } public void onResume() { Log.d(TAG, "Enter onResume"); super.onResume(); String action = getIntent().getAction(); Log.d(TAG, "onResume:"+action); //if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) if(!mSerial.isConnected()) { if (SHOW_DEBUG) { Log.d(TAG, "New instance : " + mSerial); } if( !mSerial.enumerate() ) { Toast.makeText(this, "no more devices found", Toast.LENGTH_SHORT).show(); return;

Page 46: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

} else { Log.d(TAG, "onResume:enumerate succeeded!"); } }//if isConnected

Toast.makeText(this, "attached", Toast.LENGTH_SHORT).show(); Log.d(TAG, "Leave onResume"); } private void openUsbSerial() { Log.d(TAG, "Enter openUsbSerial");

if(null==mSerial) return;

if (mSerial.isConnected()) { if (SHOW_DEBUG) { Log.d(TAG, "openUsbSerial : isConnected "); } String str = PL2303HXD_BaudRate_spinner.getSelectedItem().toString(); int baudRate= Integer.parseInt(str);

switch (baudRate) { case 9600: mBaudrate = PL2303Driver.BaudRate.B9600; break; case 19200: mBaudrate =PL2303Driver.BaudRate.B19200; break; case 115200: mBaudrate =PL2303Driver.BaudRate.B115200; break; default: mBaudrate =PL2303Driver.BaudRate.B9600; break; }

Log.d(TAG, "baudRate:"+baudRate); // if (!mSerial.InitByBaudRate(mBaudrate)) {

if (!mSerial.InitByBaudRate(mBaudrate,700)) { if(!mSerial.PL2303Device_IsHasPermission()) {

Toast.makeText(this, "cannot open, maybe no permission", Toast.LENGTH_SHORT).show();

}

if(mSerial.PL2303Device_IsHasPermission() && (!mSerial.PL2303Device_IsSupportChip())) {

Toast.makeText(this, "cannot open, maybe this chip has no support, please use PL2303HXD / RA / EA chip.", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(this, "connected", Toast.LENGTH_SHORT).show(); } }//isConnected

Page 47: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

Log.d(TAG, "Leave openUsbSerial"); }//openUsbSerial private void readDataFromSerial() {

int len; byte[] rbuf = new byte[4096]; StringBuffer sbHex=new StringBuffer(); Log.d(TAG, "Enter readDataFromSerial");

if(null==mSerial)return;

if(!mSerial.isConnected()) return; len = mSerial.read(rbuf); if(len<0) { Log.d(TAG, "Fail to bulkTransfer(read data)"); return; }

if (len > 0) { if (SHOW_DEBUG) { Log.d(TAG, "read len : " + len); } for (int j = 0; j < len; j++) {

sbHex.append((char) (rbuf[j]&0x000000FF)); } txt_Voltage.setText(sbHex.toString()); Toast.makeText(this, "len="+len, Toast.LENGTH_SHORT).show(); } else { etRead.setText("empty"); return; }

try { Thread.sleep(50); } catch (InterruptedException e) { e.printStackTrace(); }

Log.d(TAG, "Leave readDataFromSerial"); }//readDataFromSerial

References:

Page 48: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

[1] S.T. Huang, D. C. Hopkins, C.R. Mosling, “Extension of battery life via charge

equalization control”, IEEE Trans. Ind. Electron., vol.40, no.1, February 1993.

[2] S. Wen, “Cell Balancing buys extra run time and battery life”, Analog Applications

Journal, Texas Instruments Incorporated, March 2009.

[3] J. Cao, N. Schofield, A. Emadi, “Battery balancing methods: A comprehensive

review”, Proc, IEEE Ven. Power Propulsion Conf., Harbin, China, September 2008.

[4] J. Lonzano, E. Cadaral, M.I. Montero, M. Asmartinez, “Battery Equalization active

methods”, Journal of Power Sources, Vol. 246, January 2014.

[5] Y.N. Chang, Y.S. Shen, H.L. Cheng, S.Y. Chan, “Design of active balance circuit

for lithium battery pack”, Future Energy Electronics Conference, November 2013.

[6] Y. S. Lee, M. W. Cheng, "Intelligent Control Battery Equalization for Series

Connected Lithium Ion Battery Strings", IEEE Trans. on Industrial Electronics, Oct.

2005.

[7] D. Mohamed, A. Mailier, O. Noshin, P. Van den Bossche, J. Van Mierlo, “Single

switched Capacitor Battery Balancing System Enhancements”, energies, Vol. 6, April

2013.

[8] A.C. Baughman, M. Ferdowsi, “Double-Tiered switched-capacitor battery charge

equalization technique”, Industrial Electronics, IEEE transaction, Volume 55, June 2008.

[9] Y.J. Rong, C.Y. Hua, W.B. Tang, “Charging and Discharging Equalization with

Improved switching Matrix for Series-Connected Battery Pack in EV”, Applied

Page 49: Design and Implementation of an Automated Battery Balancing Module in Electric Car Battery Management System Using Alternating Capacitor Connection (1)

Mechanics and Materials, Vol. 260-261, December 2012.

[10] M. Daowd, N. Omar, P. Van Den Bossche, J. Van Mierlo, “Passive and active

battery balancing comparison based on MATLAB simulation”, Vehicle Power and

Propulsion Conference (UPPC), September 2011.

[11] M. Preindl, C. Danielson, F. Burrelli, “Performance evaluation of battery balancing

hardware”, Control Conference (ECC), July 2013.

[12] K. Hettrich, “Transportation’s Battery Bottleneck: Context, Challenges, and Path

Forward”, Stanford energy club, Issue 3, June 2013.