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...