yashsingh1/xdaforums huggingface dataset:
[Nexus One Android Development] RogerPodacter:
i cant believe you get up that high, especially when its only a 1400mah rated battery. wouldnt that be impossible?

anyway i forgot the other thing i changed yesterday was setting back to gsm auto PRL. i get better battery life with that setting, but i guess i forgot to change it when i flashed cyan 6 last week. so i changed it back yesterday. but that still doesnt account for why my charge went up to 1400mah last night.

the theory i have is that the charger has different stages based on how empty the battery is when you place it on the charger. usually i charge at around 70%. but last night it was at 30% when i plugged it in. so i think it uses a higher charge when the battery is low enough, hence it is able to pump more juice into it thus reaching 1400.
[Nexus One Android Development] ram130:
I always make my battery go down to less than 10% and die. That's what it's made for you know, I just see why I should limit my self in those ways. Always try to get the maximum life before a charge.

As for my "impossible" 1500. What I did was charge all the way to 100% while the phone is on, plug out, turn off, plug in until it reaches green, plug out, then turn on..let the battery go down to 90% or just about to change to 89%(important i believe, still testing) then while at 90%, turn off, plug in, monitor it until it turns green, as soon as you see green, plug out and turn on the phone. Then your good to go..good luck. Some times it works, I guess mainly because I was late to see when it had turn green(timing!)..

lately I have done this with success also..

Just charge the phone to 100%..then let the battery go down to 90% or just about to change to 89%(important i believe, still testing) then while at 90%, turn off, plug in, monitor it until it turns green, as soon as you see green, plug out and turn on the phone.

Still testing other ways tho..:rolleyes:..let me know how it goes. If your successful your phone will be on 100% for a couple of hours even with moderate usage. And yes after it goes down to 99% it will discharge like normal.
[Nexus One Android Development] ardatdat:
Please follow my tips here:

h ttp://xdaforums.com/showthread.php?t=743227

and check to see if it helps to increase battery life.

Basically, I follow the HTC battery tips but I do not let the phone charge to green when the phone is off. I notice that the battery is max. charged *just* before the light turns green.

Let's share your experience ^.^
[Nexus One Android Development] ram130:
is the battery drain worst if you set it to GSM ONLY?
[Nexus One Android Development] Marine6680:
Guys, I have been messing with wiping battery stats and I believe I know why some people have there phone die when the battery % is still around 5-10%. The phone will boot into recovery and stay running for quite some time after the phone shuts down. If you let it run in the bootloader or recovery for too long after the phone shuts down from low battery then wipe stats, the battery is at a lower than normal voltage, and the phone reads that as the new 0% voltage.

I noticed that when the phone shuts off with the battery reading higher than 0%, it does a hard shutdown, because I never get the "shutting down" dialog as the phone turns itself off. (IE the phone just dies, like I pulled the battery) Basically the phone is reaching its minimum operating voltage and instantly losing its ability to run, even though it thinks the battery still has some power left. I would bet that the bootloader and recovery modes can run at a bit lower voltages because not all the components are online. (IE GPU, DSP, and radio cores)

When I get my own dedicated Li-ion charger I may try charging up my battery with it and testing its true mAh ratings. I can use the charger to discharge the battery and count the mAh as it does. (I will need to set 3.5v as the min voltage though) My buddy had a charger but it isn't designed to work with battery terminals of this type and I didn't want to mod his stuff.
[Nexus One Android Development] ram130:
Right on point. I have two batteries that I had got from HTC and third from china which dies real quick. When my first battery died(phone shut down), it was at 8%....then I decided to boot into recovery and kill the rest. After I was sure it was almost dead, I wipe the stats and put the battery somewhere. Then I insert my second battery, this one died at 0% with a long, timely vibrate unlike the usual short vibrate when shutting down. Also I was able to answer a call and play with the phone while on 1%.

This is how the batteries should behave, you never know when you might need that 1%, maybe for 911 call. Right now, I am charging the battery and when it's done I'm gonna put back the first one, wipe the stats and charge it then use it. Do you think I should not wipe the stats but just charge it? or the phone reads the two batteries differently?
[Nexus One Android Development] Marine6680:
Every battery is different, hence the very cautious on-power charge the phone does. You would need wipe every time you changed batteries if you want accuracy; pointless if your using two batteries daily, but if you use one battery for a few weeks at a time then swap to give them a rest, go for it.
[Nexus One Android Development] RogerPodacter:
Well gsm auto PRL still has the phone stay on 3g all the time. It just tells the phone the roaming list. But no, forcing my phone to gsm does not drain battery worse, it greatly improves battery life. It close to doubles battery life without breaking a sweat. But I prefer to use 3g all times.
[Nexus One Android Development] ram130:
Same here if t-mobile 3G coverage wasn't so terrible...why can't t-mobile get that coverage is more important than speed?

Thanks for the info. I only use the second battery when I am on the road and my phone died too quickly..But I will try to hold off longer..thanks again
[Nexus One Android Development] muggs786:
my battery lasts till 1% i can do light use at that percentage, when it shuts off itself then i cant even turn it on again, have to plug in the charger, i dont need to calibrate it right?

htc hero btw
[Nexus One Android Development] ram130:
hell no.. i wish it was that case for one of my 3 batteries..
[Nexus One Android Development] theloginwithnoname:
blimey I just got 1464mAh! retracing my charging steps...
[Nexus One Android Development] RogerPodacter:
good luck. i still cant figure out anything i do differently when it goes that high. also check your dmesg log and make sure that it actually remained that high after the charger shut off. you should export your log pretty quickly otherwise you lose the info.

6 of 7 nights mine will hit 1361mah and stay flat. the 7th night it will go up to 1430mah, but the instant the charger shuts off, it drops right down to 1361mah.

once in a great while it will actually stay at 1430mah and hold there for hours, which is when the battery life shoots up. if only we could figure this out...
[Nexus One Android Development] chowlala:
If you use plenty of data, 3G is the way to go. The power required for EDGE might be low, but it causes ur phone to be active for much longer periods of time to download data.
[Nexus One Android Development] chowlala:
Most of the time, mine reaches 1417. If I wanna make it hit the top, I have to turn off the phone. Otherwise, the trickle charge just isn't enough.

The phone is in a constant state of activity, hence, it's burning power.

The trickle state, gives you enough to kind of hover at the 95% level, but the phone reads that state as 100%. So every time the phone runs, using data or if you turn on the screen or if you get a message, etc, the phone burns off battery power.

So, the only way to EVER reach a maximum charge, is for the phone to be switched off and therefore, not be able to burn any power and only receive.
[Nexus One Android Development] RogerPodacter:
Yeah but if you leave your phone on and charge it all night then export your dmesg log, it shows just the opposite. I can't figure it out.
[Nexus One Android Development] RogerPodacter:
If you read the post, gsm auto (prl) does use 3g, all the time. It's not edge at all.
[Nexus One Android Development] chowlala:
No. I don't think so. It does switch to EDGE if your signal drops sufficiently. Of course if you're in a strong 3G area, it'll stick to 3G.

GSM Auto PRL is very much like WCDMA Preferred. The difference is that WCDMA Pref requires a much lower 3G signal before switching to EDGE.

All in all, whenever you're on 3G, it still draws the same amount of power. Trust me, I've tested this extensively for weeks.

And I just stick to WCDMA Only. Since I'm usually in a strong 3G signal area. But if I ever go to a low 3G or fluctuating 3G signal spot, I tend to notice the battery drops rapidly because the phone is ramping up power to monitor the signal and to keep it connected.

That's when I'll swap to GSM Only.
[Nexus One Android Development] RogerPodacter:
i never ended up responding to this post. but yes i have done the charging with the phone turned off, and my mAh reading goes all the way up to 1420 mAh every time. have we ever figured out why the OS limits the charging to only 1361 mAh?

also, when i do the "bump" charge, then wipe the batterystats file with the phone topped off at 1420mah. the next time i charge it still stops at 1361 mah. i would think that wiping the stats with the new top end reading would adjust the battery meter accordingly. but nope, the phone still does its own thing. this makes me think that the OS has its own hard-coded battery profile which cannot be altered, and the batterstats.bin file simply is used for the "battery use" section in our settings.

also, when i did the bump charging, all it really did was shift my entire battery meter by 15%. so from 100% to empty it died at 15%. then i recharged it, and when it hit 85% it then skipped right to 100%. so it was offset by 15% both at the bottom end and the top end. so i'm not sure what's really happening here. couldnt be more confused...:confused:

posted screenshot in the other thread already, but here it is again.
[Nexus One Android Development] theloginwithnoname:
1470 after powering on from: Full off-charge overnight, powered on this morning, read emails, twitter. Powered back off, started an off-charge (red light came up) until 30 mins after green light.

Next battery message was down 5 mAh. Offed it again, off-charged (red light) til green + 10 mins. Back down to 1353. pah.
[Nexus One Android Development] RogerPodacter:
That's crazy it got that high. How exactly is the real time mAh number being measured by the phone? I assume its using P = I * V and V = I * R? It must be some real measurable parameter, not just software guessing.
[Nexus One Android Development] theloginwithnoname:
Rog, I have *no* idea but, as you say, it is crazy high.

There must be some software element to the device reporting the level, otherwise how would it get to such a high value *off-charging* then get off-charged some more and come out with a *lower* value?

As I've aluded to before, I think wiping stats may be better done at the lowest value, however...

I pondered the same in post 110 and have come to a similar conclusion.

...which is nuts but again, same conclusion I came to.

Guess we need someone technical enough to disect the stats file, diff it for changes after: normal usage, a charge, a wipe - can't see any of the Android "big boys" being that interested though!
[Nexus One Android Development] RogerPodacter:
i downloaded a hex editor last night and was able to open the batterystats.bin file, and it contains nothing about battery except what we see in the "battery use" section of our settings. so we may have been wiping the wrong file all this time.

however i did find another file in root explorer under d/battery_log and i opened that and it actually contained all the voltage, mAh, %, info for my battery. what i mean it my battery happened to be at 44% and that file went from 100% down to 44%, and the numbers matched exactly what we see in the dmesg log.

there was one extra number which we dont see in dmesg and it was labeled dC which could be discharge rate, or like 0.5C but the number changed each new line of info. i couldnt figure it out.

so i think we've been wiping the wrong battery file all this time.
[Nexus One Android Development] chowlala:
That would make crazy a lot of sense, because I honestly don't find much difference wiping the battery stats. Haha.

Now that we know where this file is, what are the potential dangers could we face modifying it? Lol.

XDA Battery adventures begins! Lol!
[Nexus One Android Development] RogerPodacter:
i'm still not sure it is giving our battery any direction, it may just be a log or something.

anyway here's some plots i did and posted in the other thread if anyone cares.

obviously our phone determines our battery percentage based on the mAh number. its scary how straight that line is, and it intersects exactly at [0,0]. the voltage graph is more vague, and it actually was taken from 2 cycles, one full charge, and one partial discharge.
[Nexus One Android Development] SubyWill:
mine shuts off at around 10% sometimes :-/

what can i do?
[Nexus One Android Development] RogerPodacter:
That's what I'm trying to figure out with the graphs I'm doing. My battery always shuts off at 8%, 10%, and the other day 15%. Deleting the battery stats file changes nothing. We need an android expert to help up find where the phone stores or reads battery info.

Batterystats.bin contains nothing but what app has used your battery, so that's not the right file. And I found another file in d/battery_log which contains voltage, mAh, %, etc but its from your current charge cycle, not historical info collected over time.

So I'm back to my theory that the OS is pre loaded with non changing battery profile which it uses to estimate battery stats, and this is not changeable. And this matches what we know for people who use extended batteries. If the phone kept some kind of moving average file, then the extended battery would be re-calibrated over time the more they use the larger battery. But that doesn't happen. The phone still stays at 100% until it hits default value of 1361 mAh and then starts to drop. Not sure what other proof we need, that pretty much seals the deal if you think about it.

The only option is if someone can find where the battery numbers are, we could re build a ROM from source with altered battery numbers.
[Nexus One Android Development] RogerPodacter:
i compared one day of numbers and added in the next day's numbers in a few chunks to see how they line up. its dead on perfect.
[Nexus One Android Development] theloginwithnoname:
Like your thinking Rog, but I suspect that the %age is worked out as ( ( current-mAh / 1361) * 100 ), so the %age will always match!
[Nexus One Android Development] RogerPodacter:
That's very likely, but the end result is still the same: what file tells the phone to use 1361 for that equation?

I found a lot more files in sys/devices/platform/ds2784-battery. A bunch of files reside here like current_now, voltage_now, and many more. I can copy them all to my mem card except one called driver. I'd like to look inside this, anyone know how to do this? Seems root explorer can't copy this one, but all those others do.

More generally, does HTC make it impossible to open their driver files like this one? Anyone help me out since I'm clueless with this stuff.

Anyway my thinking was we could alter the value from 1361 to 1400.

BTW I bump charged tonight and hit 1518 mAh. Immediately wiped battery stats, reboot, and that number flipped back to 1363 with one exception. Now it discharges very slowly as if it was reading the higher mAh value. I've had screen on for 55 min and still at 92%which I've never been able before. I wiped with clock work then flashed amon and wiped with that which seemed to make the difference. Tomorrow will test to see if it holds or not.

Edit: I played around and no numbers fit that equation, or any variations of it I could think of. Went back to my excel numbers and really looks its all about the mAh number. I just wanna know what tells the phone this info!

Edit 2: Damn actually that was right. ((1361 - mAh) / 1361) x 100 sure enough gives right perc.
[Nexus One Android Development] ram130:
See I told you guys I was not lying! Thats what I've been getting and it takes long to discharge like regular...Now you guys believe me :rolleyes:
[Nexus One Android Development] theloginwithnoname:
What an excellent piece of analysis and spot RogerP.

Might be worth creating a new thread in the N1 dev section, and ask advice as to how to proceed/incorporate into a custom ROM, prefereably CM6 - or even AOSP?! I think there are two initial options:

- raise it as an issue (enhancement) in AOSP and/or CM, or

- I think you can modify the file and send a pull request? sorry, my github is a bit hazy.

Building CM for N1 instructions: http://wiki.cyanogenmod.com/index.php?title=Building_from_source#Building_for_Passion.2FNexus_One Not sure how up-to-date it is.

Let me know the URL if you decide to create a new post.

Again, nice work.
[Nexus One Android Development] chowlala:
Awesome find guys! Guess the brainstorming finally paid off! I tweeted Cyan to take a look at the thread. Hopefully he can help us figure this out and hopefully add this into CM as well. That'll be awesome if we could add these changes to the mod that'll allow us to maximize battery. Heh. =)
[Nexus One Android Development] ram130:
+1 .
[Nexus One Android Development] RogerPodacter:
here's some more interesting info from the spec sheet on our phone's battery, it has its own internal ds2784 battery Fule Gauge IC (click me). all the battery reporting is given to the phone from the battery's integrated circuit, like mAh and percentage. this is why there is no "battery calculation" code anywhere, and why we get the same exact percentage to mAh results everytime.

i have opened up the batterystats.bin file and it does not contain battery info we think it does. in fact i now wonder if recovery we use even wipes the correct battery info at all.

and when you look thru that ds2784_battery.c file driver on the AOSP, you can see the code actually pulls raw battery data from this EEPROM register or whatever, and it does a print file to the screen (i.e. what is seen when we run a dmesg log).

anyway, check out what the guys over at pre forums have done. turns out the pre has this same IC fuel gauge on that battery. i ran into all this info searching around and came across this thread.

http://forums.precentral.net/palm-pre/256967-find-out-how-good-bad-your-battery-6.html#post2582809

they are actually going into the the IC register and seeing the values. since we are rooted i wonder if someone could do the same on android? that would be sweet.
[Nexus One Android Development] RogerPodacter:
I've been reading about it and building a ROM from source is very involved and over my capabilities unless I did some learning. And I don't even have a mac or Linux system, only xp. I really need someone who's already setup to just make the edit and build just the single file. But I'm not even sure android works that way. It might need to be built with the entire ROM. I have no idea. I wish some expert could provide some insight.

Actually the cyanogen version of the file would need to be used since I'm running r c 3. I don't even know if it would be possible to do a simple push the file to the phone. I want to change the value to 10 mA and try it.
[Nexus One Android Development] RogerPodacter:
i've hit a snag. first of all, someone was nice enough to compile the change for me. i made a thread:

http://xdaforums.com/showthread.php?p=7795819#post7795819

the problem is the new file from cyanogen source code is slightly different, and it does not contain the same line of code. in fact that entire function is different it seems, and i cannot decipher what its doing.

here's the new file:

http://github.com/CyanogenMod/cm-kernel/blob/android-msm-2.6.34/drivers/power/ds2784_battery.c

here's the good (or strange) part, the phone still performs as if the code is cut off at 80 mA. so it seems that somehow things were changed to give the same functionality, just written in a different way. but i'm not that good so i'm having a hard time finding it. i've looked thru as much as i could but didnt see anything. the closest is this:

if (di->status.current_uA > 1024)

but i have no idea what 1024 stands for. it seems like an address or memory size, not a parameter. we need an expert:(

if (di->status.current_uA > 1024)
di->last_charge_seen = di->last_poll;
else if (di->last_charge_mode != CHARGE_OFF &&
check_timeout(di->last_poll, di->last_charge_seen, 60 * 60)) {
if (di->last_charge_mode == CHARGE_BATT_DISABLE) {
/* The charger is only powering the phone. Toggle the
* enable line periodically to prevent auto shutdown.
*/
di->last_charge_seen = di->last_poll;
pr_info("batt: charging POKE CHARGER\n");
di->charge(0, 0);
udelay(10);
di->charge(1, source == CHARGE_FAST);
} else {
/* The charger has probably stopped charging. Turn it
* off until the next sample period.
*/
charge_timeout = true;
charge_mode = CHARGE_OFF;
}
[Nexus One Android Development] dictionary:
I would say the section right about the one you quoted, 0x80, for status.status, but I'm a total nub, lol. Why don't we email: MODULE_AUTHOR("Justin Lin <Justin_lin@htc.com>? I'm just throwing anything/everything out there, as I would really love for this to be resolved.
[Nexus One Android Development] dvgrhl:
I don't think that part means anything relating to what you are looking for. As to the change in the Cyanogen source, I also found this change here: http://android.git.kernel.org/?p=ke....c;h=584c59ed1a9dd4236daa2e2b3ee0226b9364c7ea. Note that I don't really note much about git or what /blob means, but at least we see that change isn't unique to CM6 R3.

As to the original code, I think your analysis is a little off. Let's take a look specifically at lines 377-379:

372 /* shut off charger when full:

373 * - CHGTF flag is set

374 * - battery drawing less than 80mA

375 * - battery at 100% capacity

376 */

377 if ((di->status.status_reg & 0x80) &&

378 (di->status.current_uA <= 80000) &&

379 (di->status.percentage == 100)) {

380 di->status.battery_full = 1;

381 charge_mode = CHARGE_OFF;

382 } else {

383 /* We don't move from full to not-full until

384 * we drop below 99%, to avoid confusing the

385 * user while we're maintaining a full charge

386 * (slowly draining to 99 and charging back

387 * to 100)

388 */

389 if (di->status.percentage < 99)

390 di->status.battery_full = 0;

391 }

What this is saying is if the CHGTF (charge to full) flag is set AND if the battery is drawing less than or equal to 80mA AND if the battery is at 100% capacity only then stop charging. If any of those conditions fail, then the battery keeps charging as long as the battery percent is less than 99 as seen on line 389.

So even if you lower the di->status.current_uA <= 80000 to something like di->status.current_uA <= 20000, if di->status.percentage is reporting 100 or 99 then you still won't charge any more. And if the battery wasn't at 100 or 99% already, then it would fail the first if statement regardless of what di->status.current_uA is set to and would continue to charge. Correct me if I've made any errors in my analysis.

As to the current CM6 R3 code:

445 /* shut off charger when full:
446 * - CHGTF flag is set
447 */
448 if (di->status.status_reg & 0x80) {
449 di->status.battery_full = 1;
450 charge_mode = CHARGE_BATT_DISABLE;
451 } else
452 di->status.battery_full = 0;

it's only checking if the charge to full flag is set, and if not it continues to charge the battery. So that's ignoring all together what the battery is currently drawing, 80 mA or 20 mA, or any value. It wouldn't matter.