# How can I improve the algorithm for switching between lithium ion batteries with different voltages?

I have made a device which switches between 2 different lithium-ion batteries with different voltages and only puts them in parallel when their voltages are the same. Lithium-ion batteries' voltage dips and decreases in an abrupt manner which is respective to the user using them as batteries whose voltage would be 36v at rest and while under load may reduce to 34v but then climb back up to 36v after a couple of seconds of not using it. the algorithm I wrote for my device tries to switch between the batteries while this dip in the voltage has occurred so I was brainstorming ways to improve my algorithm but I cannot think of any which would be better than the one I have now. The problem is that if I have 2 batteries whose voltages are 36v and 35v so the algorithm would decide to choose the 36v battery to be connected to the output and that's fine until the battery starts to get used and becomes under load and only then the voltage will start to dip on it to near 34v~ then at that moment the algorithm will switch the battery back to the 35v battery. Then the 36v battery voltage would recover back to near 36v and this cycle would repeat forever which is not ideal. Of course, delays could be added but that will slow down the operation of the device and not help solve the problem.

I tried using this flow diagram but it experienced the same problem listed above.

I also tried thinking about letting the device measure the voltage of an un-loaded battery and then measure the voltage while the battery is under load so that the device knows when the battery is loaded however this can be done but it comes with its own set of problems such as the natural voltage decay that the battery will experience while under load...

• While waiting for algorithm improvement suggestions, read up on battery switches. May 27 at 7:01
• Hi @greybeard i did look at all the available options before going this route, I'm looking for something specific which would be able to be controlled without any human input and can withstand 200vdc and possibly around peaks of 40A May 27 at 23:24
• There’s no magic - if I give you two random batteries, how would you know which one was the better choice in terms of charge? You could apply a test load and measure the voltage drop. Assuming you know the size and type of battery you might be able to estimate if it is good or bad. Bottom line - without prior knowlege, it is a lottery. In terms of your algorithm, you need to incorporate time into it - I tested this battery within the last 10minutes and it was bad - don’t try it again. You need a form of hysteresis so you don’t get stuck in a cycle. Also have a ‘dead band’ with your values. May 28 at 2:37
• You left out half of the conceivable switch functionality: Does it do undervoltage protection? If battery A has got a higher cut-off voltage than battery 1, battery A needs to be disconnected from the load sooner. Of course, battery 1 may be disconnected at the same time. May 28 at 5:15

## 1 Answer

Do not go from one battery connected, only to other battery connected, only for difference in battery voltage, but for cut-off voltage reached, only.
Go from both batteries connected to one battery connected, only if the current through the other battery seems to be reversed.

Course of events I'd expect:

1. batteries B1 & B2 disconnected, at V1 & V2
2. battery with higher voltage gets connected
3. as soon as there is significant load current, the voltage drops low enough to connect the other one.
4. current through just one of the batteries gets reversed next to never
– say, recuperative braking or very light load
5. there may be times to signal battery low
6. battery with lower cut-off gets cut off
7. other battery gets cut off

You don't need to bother about reverse current in one of multiple paralleled batteries if
a) preventing reverse current (("ideal") diodes)
b) load always is high enough reverse current never happens.