sriharshaarangi / BatteryChargeLimit

GNU General Public License v3.0
381 stars 103 forks source link

Limit charge by voltage #12

Open vovodroid opened 7 years ago

vovodroid commented 7 years ago

Is there possibility to limit charge by real voltage, not by percents? It seems that percent indicator readings have no straightforward dependence with real battery voltage. I would like to keep voltage about 3.8V, but it's difficult to say what percentage to choose.

milux commented 7 years ago

The problem here is that the voltage will change significantly when the battery is charged. There is no straight-forward way to determine the "idle" voltage of the battery while it is charging. Thus, implementing this requires some heuristic to approach the desired voltage as precisely as possible. Furthermore, the user must also provide a "recharge threshold voltage", which will certainly overstrain non-expert users. Let's consider it a possible enhancement for an "expert mode" in a future version.

vovodroid commented 7 years ago

the voltage will change significantly when the battery is charged.

The simplest way is just to calculate moving average.

milux commented 7 years ago

Maybe, but there's another problem: The voltage also depends on the charging current, and currently I don't see any reliable way to read the latter for most devices. The higher the charging current, the higher the voltage gap. Everything will get even worse when a fast-charging technology like QuickCharge is used. (With the final saturation phase of normal charging also having completely different rules on its own...) In the end, building this feature in a meaningful way might just not be worth the trouble, if it's possible at all. Therefore, I decided to drop it some weeks ago when I thought about such a feature myself.

vovodroid commented 7 years ago

Can you at least just to add voltage indicator to application? It will help anyway ))

milux commented 7 years ago

That should be easy, as the voltage is part of the information provided by the battery intents. Can you open a new issue for this, just for the sake of it? 😉

milux commented 7 years ago

The information is now displayed. If somebody is able to come up with a really good idea (or even a proof-of-concept app) for obtaining the idle voltage of a battery in a reliable manner, we can continue our discussion.

anonymouspetdo commented 7 years ago

I found a way to limit charge by voltage on Nexus 6P 7.1.2 (N2G48B, Jul 2017). The control file is "/sys/class/power_supply/battery/voltage_max" The value in this file will specify the maximum voltage of the battery in mV [default value: 4400] (Yeah, whatever the tech they use to make Li-ion go to 4.4V, battery longevity is out of the window if you leave you phone on the charger for extended time. I lost ~600mAh out of 3400mAh by just leaving the phone on charger all the time for 2 months)

By changing this value, the charging process never goes above the specified value.

For example, the value is set to 4100. Charging process will fast charge until the battery reach 4.1V and reduce the current to maintain battery voltage at 4.1V. Eventually, it becomes trickle charge as if the battery is full. Fully charge at 4.1V give battery level 80%

In my testing, there are some circumstances need to be noted.

This method doesn't work on Samsung Galaxy S4 touchwiz 5.0.1. It has different set of control files and I couldn't find anything related to max voltage.

milux commented 7 years ago

I observed a 4400 limit in some file on my device a longer time ago. It's pretty clear that 4.4 V is not the (idle) battery voltage! 4400 mV is the measured voltage at the end of the charging cycle, and typically 100 - 200 mV above the idle voltage of the battery. When you restrict the value of your file to 4200, I expect your battery to end up with a "real" voltage of something around 4050 mV, which would be around 70-75 % or so... While such files are an interesting option to restrict the observable battery capacity for particular devices (please open another issue if you want this to be evaluated further), it doesn't help with the original problem discussed here, which is: Find some reliable way to measure the battery idle voltage in relation to the observed voltage while charging. I thought about some heuristics for doing this, but so far I don't have the resources for time-consuming research.

vovodroid commented 7 years ago

Though this limit is not idle, but end of charge volume is there chance that if keep battery constantly at this voltage it will end up with idle voltage close to this?

milux commented 7 years ago

I think no, because I assume that's not how things work. ^^ When modifying the file in this way, this will set a new 100% mark for the charging logic of the device, however this is implemented. What the device will likely do then is something like this:

This is nothing different from that what we have already, just another technical approach. This approach could be more reliable or more efficient on some devices, as we don't have to mess with the charging ourselves iff it works. ^^ But again, this improvement is not related to this issue, please open a new one if you want to discuss this!

anonymouspetdo commented 7 years ago

May I ask what kind of phone you have? What you said is not what I observed on my Nexus 6P.

Charging cycle consists of 2 phases; constant current (CC) and constant voltage (CV)

The precise relationship of these voltages is: V_charging = V_idle + (I_c)*(R_int), where I_c is the charging current and R_int is the internal resistance of the battery.

So, the answer to this thread is: No, you cannot determine V_idle as long as charging current is greater than zero. To determine V_idle, you HAVE TO STOP charging, wait 10s, and query the voltage(it's the time required for the system to update measured voltage without charging).

On my Nexus 6P, Charging voltage reaches max voltage 4.4V at around 80% (that's when phase 2 starts. If you disconnect charging cable your V_idle<4.4V). If I leave it on charging long enough (~30-50min) for it to finish phase2 (100%), after disconnect charging cable, V_idle is actually 4.4V (With some loads it will drop to 4.37V).

For modified V_max to 4.1V, Charging voltage reach 4.1V at around 60%. If I leave it on phase 2 long enough (~30min) the charging current will eventually reach 0 (end of phase 2) and battery is at 80%. At this point, battery voltage will be 4.1V even if the charging cable is disconnected.

The point is voltage reported during charging is not the voltage of the battery unless the charging current is very low (end of phase2).

milux commented 7 years ago

@anonymouspetdo Interesting, thanks for that explanation. So if I understood you correctly, when we do this modification, the CV phase will already kick in at a lower voltage? That's a surprise to me, I expected that the point of change from CC to CV was completely hardware-/voltage-driven...

milux commented 7 years ago

@anonymouspetdo One more question: "V_charging = V_idle + (I_c)*(R_int)" is perfectly logical. We could use this information, given 2 things:

The latter might be a problem. My assumption is that R_int changes with battery temperature, which in turn changes because of environmental influence and/or charging current. Have you done any experiments to measure the stability of R_int on your device?

anonymouspetdo commented 7 years ago

My suggestion is to run the service on the background (battery test mode) and monitor battery voltage during light discharge (<200mA) to determine battery voltage at different battery level percentage. That would be quite accurate for a few ten cycles.

Reed97123 commented 6 years ago

I would love to adjust the default value of the voltage_max file. If this could be modified in the ROM I'm using then it wouldn't require any additional programming to limit the charging. I also wouldn't need to root the device for the limit to function.

Where does the default 4400 get set?

Noitarud commented 9 months ago

I'd think it's a good idea, capacitors explode because of voltage, why has this issue been ignored fo so long? Plus voltage is not uniform across the battery when it is getting dis/charged.

You could use a circuitry clamp to burn the energy, if physically opening was a better option than rooting… Another observation I got with a phone i began reusing, two years used, four years disused, is, in about a year it began to radically decline in capacity, and i thought it was because i had left it on the charger for a while after full, which was not something i was doing when i began using again.

Someones forked the app and added the feature. …Limiter