Programming a Lithium-ion Battery Charger Using a Finite State Machine With Arduino.

by RobertoF43 in Circuits > Arduino

1180 Views, 11 Favorites, 0 Comments

Programming a Lithium-ion Battery Charger Using a Finite State Machine With Arduino.

20230421_084344.jpg
20230421_084456.jpg
20230421_084508.jpg
20230421_084522.jpg
20230421_084630.jpg

I have been working on this solution for a long time, the objective of this work was to achieve the highest possible precision in the constant current and constant voltage parameters necessary for the efficient charging of lithium-Ion batteries, currently widely used in all areas of our lives. On the other hand, it was very important to achieve a circuit capable of working in a wide range, both for small capacity batteries and for medium capacity batteries such as 18650.

System Conception

Charging Curve.png

Lithium-Ion batteries are charged first with constant current and then with constant voltage. The charge of Lithium-Ion batteries has a dilemma, the first is that if they are fully charged their useful life decreases but they give more working time and the second is that if they are not fully charged, they have a longer life but they do not give energy for as long as they could. According to sources familiar with these issues like Battery University, Lithium-Ion batteries, which are 3.6V, are charged at 1C or less, let's say 0.5C, until they reach a voltage equal to 4.1V and then they are charged with constant voltage at 4.2V until the current drops to 3% of its maximum capacity, that is, C. If we want the battery not to charge to the maximum we can vary the percentage to 5%, 10% of C and that's how it lasts more time but the battery effective working time decreases.

To facilitate the conception and design of the system, a State Diagram was created. This includes 4 states with their transitions. The states of the diagram are: OFF, CC (constant current), CV (constant voltage) and STOP (end of charge). The arrows indicating the transitions include the Boolean condition that trigger the change of state in the form of logical expressions.

Hardware

The hardware is mainly composed of an Arduino UNO, a high side current source, a voltage follower, two Digital Analog Converters DAC (MCP4725) and an Analog to Digital Converter ADC (ADS1115). The battery charger algorithm is as follows. The DACs receive from the Arduino UNO the information by I2C of the voltage that they must generate, one ADC is used for the high side current source and the other DAC, for the voltage follower, since the events are exclusive, one ADC works and the other does not, one in the constant current phase and the other in the constant voltage phase. The transfer functions of both circuits were obtained from measurements and regressions of order 4 (as it appears in the main program). In this way, more precise control can be carried out. The current measurement is done using two voltage dividers connected to both sides of the current sensor RS3. Voltage dividers are used because at those points there may be voltages greater than 5V that would destroy the ADC inputs and because ICs used for sensing current are not linear specifically for currents less than 100mA.

In some photos you can see that a circuit with soldered components was used. From a certain complexity and size of the circuit, I prefer to use soldered circuits to avoid false contacts, noise and heat when using breadboards. On the other hand, this allows you to connect directly to the Arduino using pin headers.

Downloads

Software

The software is composed of 5 programs:

1.- BatteryChargerMainProgram.ino

2.- CC.ino

3.- CV.ino

4.- RxNumber.ino

5.- parametersCalculation.ino


The first program complies with the State Diagram using the switch statement. The second program, CC.ino, is intended to control the constant current of the first stage of charge. The third program CV.ino contains the statements where the state of charge with constant voltage is controlled. The fourth RxNumber.ino program is intended to add a UI to the system in the future. The fifth program is where the voltage of the dividers made up of R8, R9, R10 and R13, R16 and R18 is read and where Ibattm is calculated. In this fifth program, the corrections to the readings of the ADC ADS1115 are introduced to obtain the real voltage values on both sides of the resistor RS3. All voltages and currents are given in millivolts and milliamperes..

The constant current used to charge the 18650 batteries was 0.1C because it did not have the appropriate heat sinks for the transistors. The capacity of the batteries is entered into the function setAh() manually, which is found in RxNumber.ino.

The control method used was the Proportional since the transference function of the system is known.

There was a problem with the constant voltage step. In this case, we have 2 voltage sources connected in parallel so that the resulting voltage is the difference between the voltages of both voltage sources, for example, if the battery voltage is Vbatt and the voltage of the voltage follower is Vb, then the resulting voltage, Vres = Vb - Vbatt. In this way, if you want a constant voltage of Vres = 4.2V, it is necessary that it varies according to the variation of Vbatt to keep Vres constant. For this case, the setpoint is not constant, it moves and therefore the control is different from the control used in the first stage of constant current, where the setpoint is set equal to the desired current and the circuit and the program simply try to maintain that value.

Conclusions

The next step is to create a User Interface that allows to vary the charging current, the charging time, the charging voltage in order to be able to use the charger, not only for Lithium batteries, but also for NiMH batteries. On the other hand, SofC and Internal Resistance measurements will be performed.

Comments

Add your comment.