yashsingh1/xdaforums huggingface dataset:
[Nexus One Android Development] Dr Byte:
Second calibration run on new battery

Just completed a second calibration run on the "new" genuine HTC battery, and I'm more than a little disappointed.

It only has about 40-50 cycles on it at most, but the capacity is down to 91% (1310mAh) already :( That's about the same as my nearly 2yo battery.

For the first time ever (and about the fourth time including #1 battery) the App started the calibration on the first attempt. As above, I pushed "10" into register 10 to make absolutely sure it didn't shut down from "0mAh" before the voltage hit AEV.

The voltage swung up normally for a USB charge, but the capacity topped out at 1310mAh. I'm even thinking of throwing it back at HTC for a replacement. However, I plan to get a Galaxy Nexus or equivalent pretty soon anyway, so I guess it's pretty moot.

Once again, pushing a value of <10 into register 10 didn't work. No effect.

Once again, maintaining a perfect record, the age at the end was 100% :( - out of 30-40 attempts on two batteries, I have never seen the age set :(

I find when I set the "age" on my batteries <100, I get less "useful" capacity from a charge - so I guess I just have to live with knowing that my batteries will die at 11% and 9% for the 2yo and 4mo respectively! With light usage, the new one will go 3-4 days easily, but I have tuned the power usage to within an atto-erg of its optimum :)
[Nexus One Android Development] boardlord:
I got my replacement battery, and this one gives normal data in the app fortunately. However there is something strange going on. As I burn the battery so that the learn cycle can begin, when the capacity falls to around 160 mAh, the current jumps to -2200 mA, and after that the capacity jumps up to 250 mAh. This repeats 3 times, and only after this will the battery go down to zero. After two calibration runs the age stays 100%.

However, it still discharges quicker than my 2-year-old orig Nexus battery... I need to wait a few charge cycles until I see a better performance that my old battery? Thanks
[Nexus One Android Development] trschober:
as per the first post, that is completely normal, the app will raise the capacity automatically:

c. if Capacity/mAh drops to near empty prior to 3201mV being reached, the app will automatically raise capacity by 200mAh so phone doesn't auto-shutdown prior to reaching 3201mV
[Nexus One Android Development] boardlord:
*facepalm* :) thanks!

Now the only question is why does the new battery discharge faster than the old one? The calibration affirms that its new, since the age is 100%...
[Nexus One Android Development] freddylam:
I have problem with the capacity test.

Not original battery.

So at the start of the calibration, I set the full40 at 1650 (orginally 1452)

after finishing calibration the batt age was 94%, but the battery starts at 100%, dies at 0%, so I think it's calibrated.

Then I proceeded to capacity test and I noticed that the battery jumped from 72% directly to 100%.

At 100%

Capacity continue to go up with >300 current (See attached image)

It plateau at 1985mAh but didn't drop back to the set full40 (1650)

What actually going on?

Thanks!!
[Nexus One Android Development] falconyx:
Guys, I'm really sorry if this has been asked, but thread is really huge and I dont have that much time: when trying to drain my stock battery and waiting for learn mode to activate I always get my battery to 10-11% and then it jumps back to 17%. Now I read through guide quite a few times and realize that this is probably normal but I don't really know how to proceed...should I just keep waiting?

Also, what is the best way to drain battery so that I can quickly enough see that learn mode is achieved and immediately plug in charger? I figured maybe watching youtube in portrait view since then I can also see my battery %. Thanks for any tips!

P.S. I've set all values in the learn prep tab correctly, that I double checked!
[Nexus One Android Development] hchao:
[Q] battery showing 1% but well above 3600mV

My Desire HD always shows battery to be well above 3600mV when the battery meter is at 1%..0%.

When fully charged, the battery is at 4211mV.

Is this normal?

I read from this thread and the instructions for the Battery calibration tool that the battery should go down to 3201mV to be at 0%. 3600mV to 3201mV is a quite wide range, so I'm wondering if a large portion of the battery capacity is wasted and not used.

I have tried various calibration methods, but it's still the same.

The "[UTILITY] Battery calibration tools" downloaded from Market does not work on my DHD. The tool is for batteries with the ds2784 chip, but my DHD is showing it has a ds2746 chip--from the driver directory.

I have tried to let the battery reach 0% and have a forced shutdown, and after that, I boot into recovery and let it stand for more than 10 minutes. And then after a reboot, the battery would be at below 3400mV. I could repeat the same procedure again, but I was afraid of deep discharging the battery to below 3201mV and damaging it.

Is there any way to calibrate the battery so that it's below 3300mV when the battery meter shows 1% (short of using the tool offered in this thread)?

Thanks.
[Nexus One Android Development] theloginwithnoname:
I'd be amazed if there were vast differences between them - there's no reason why you couldn't work out the registers for your battery and add in the various functions (as we did) into the kernel code that return the values in those registers, which would make it compatible with (and therefore you could use) this tool.

What kernel are you running BTW?
[Nexus One Android Development] RogerPodacter:
Yes i looked at drivers for the ds2746, but these tools wont work unless you modify the driver. Also look at the ds2746 data sheet cause its a little different than the ds2784. Would be a great project.

Howdy noname, yeah i'm trying to remember details but its been so long. Remember all those pdfs we found? Well some of those were for ds2746 showing all the registers and calculations. So its def possible. A DHD owner would need to edit their driver and test on their device. Then we could even update the app in this thread to work for both drivers. All the code is still up on github for anyone to use. This was a great project.
[Nexus One Android Development] hchao:
Hi, thanks for answering my quest. Very true that there should be no reason to not be able to make a tool work with the battery on DHD, given the info. and source code available here. But I'm no kernel hacker, and the last time I touched anything UNIX/Linux related was over 10 years ago. It's just natural laziness to ask first in the hope that something might be available already. :p

I'm running an older (3.4) version of Leedroid kernel, and I've switched between 3.4 and 4.0. 3.4 seems to be a little more power conserving: I normally get -1ma with standby in flight mode.

---------- Post added at 01:09 AM ---------- Previous post was at 01:07 AM ----------

Thank you for answering my quest as well.

I don't know how to edit the driver. If you want to make this tool work with ds2746, and I can get help to jump-start the kernel and battery driver side, I'd be more than happy to work with you and test on DHD.

---------------------

Yesterday I experienced something very strange: my DHD was on standby for 7+hours, and the power stayed at 8% (3723mv) for that entire period. Normally with an already very power-saving Leedroid kernel, it would consume ~1% every two hours or so on standby. After I resumed the DHD and used it for over an hour, it finally shut down itself. But when I recharged it, it's almost full and reached 4209mv when the battery meter showed the battery was 80% full, and it then jumped to 100% (4211mv) in 10 minutes. This happened after I booted into recovery and let the device shut down by itself after it had automatically shut down on 0% battery on a regular run, and then I plug in the cable for a full charge. (I did check the battery, and it was about 3500mv when it rebooted from the discharge in recovery.) But when it's fully charged again, I didn't do a battery stats wipe. Looks like I managed to lower the lower boundary (used to be well above 3600mv at 0%), but the higher boundary/percentage got messed up (now 4209mv for 80%).

I don't know if it's just an aged battery or I really need a battery calibration tool like the one this thread offers. I'll do another full charge+battery stats wipe to see how it goes.
[Nexus One Android Development] theloginwithnoname:
I was exactly the same prior to doing this dev work! Jump on in, the water's lovely... ;)
[Nexus One Android Development] chowlala:
Neither am I. My only qualifications are being a pro gamer. Lol.
[Nexus One Android Development] theGanymedes:
Well, after reading a few posts (and complaining about my Desire dying at 15% - so annoying!); I tried to test this myself too. It's really sensitive process, especially when the battery nears full charge; but that can be done.

Since the calibrator application uses sysfs entries to communicate with the driver, and actually even stock battery driver can change registers; I tried to move the sysfs-interface functions from the modded kernel to a Sense kernel. Couldn't try it yet, since my device is still at learning mode, but will let you know if it does work.

For me, the only saddening part for this way was to format my Desire and install some CM ROM (since I use Sense ROMs); just to calibrate the battery. Hopefully, with the sysfs interface implemented, we can use our own ROM's to make the calibration with Sense ROMs too.

Hopefully my problems will diminish. Thanx for all these opportunities guys, you really rock! ;)
[Nexus One Android Development] RogerPodacter:
Nice work do you have your modded desire driver with the added sysfs code? I'd be curious just to check it out.

And for the DHD owners, we'd have to basically do the same thing. Need the dhd driver code which i havent seen, and add those functions. But also first confirm the DHD does in fact use the ds2784.
[Nexus One Android Development] 7_michel:
If you refer to to Maxim DS2784 data sheet, you may read ( bottom of page 24) that this IC include a ''learning function''. I wonder how to activate this process, it seems that the battery should be able to activate it by itself.....

If you record with BMW the full charging cycle and copy the battery_history file in an Excel sheet , you will be able to calculate by yourself the actual battery capacity. It is what I have done with my HTC desire batteries ( same model as Nexus one battery); results are here http://78michel.unblog.fr/?p=164. I have found that my one year old HTC battery has now a reduced capacity down to 1150mAh , very close to what you found on yours........

For your information , I bought a new HTC battery but its properties are very strange http://78michel.unblog.fr/htc-desire-battery-shutdown-analysis/
[Nexus One Android Development] theGanymedes:
Well, apparently that's the same case of mine: I've read that turned-off charging erases the battery age part, which is causing 15% turn-offs to reappear.

I'm actually waiting for the battery to deplete enough, to buy a 2600mAh gold battery, but I think I'll go until this one is not enough for one-day of operation -- currently it goes nearly one and a half, so...
[Nexus One Android Development] RogerPodacter:
Ummm did you actually read this thread? It has one purpose which is activating the learning function in the ds2784 chip described on page 24. Thats what this app does! :)
[Nexus One Android Development] theGanymedes:
I think he thought we do something different.. :)

Well, while I'm performing another learning right now, I was reading the DS2784 document and I've seen this:

Well, as I can see from the registers (address 60h), my device is allowed to go into the Sleep mode, and the application (also the register states in address 00h) says that the chip IS in sleep mode - which is why it doesn't estimate the battery age.

Around here somewhere, someone was complaining that why our devices doesn't calibrate themselves - this might be (and I think highly) the reason.

Thanks to the calibrator app, we can turn the Sleep mode off, but I don't know what effects this might introduce (battery consumption, perhaps?). I'm not much of a electronic guy, but can someone guide me on this Sleep Mode/Active Mode difference better? The document says in the active mode:

So, the device puts the DS2784 to Sleep mode, beacuse we're sure that the battery won't do anything unsafe, so we don't do these calculations?
[Nexus One Android Development] 7_michel:
Yes it clear for me.

My dream is to avoid to change anything in the stock Kernel and to find a way to activate the LEARNF with specific drainning conditions

According to DS2784 data sheet it is possible to activate the learning process when both IAE et VAE are reached. It seems very difficult to get in this condition with stock battery settings.

Have you been able to read which IAE and VAE values are usually set in stock batteries? Do you think that these values are almost impossible to reach to activate the LEARNF?
[Nexus One Android Development] RogerPodacter:
Ok i see. First if you guys want to check any register setting not displayed in the app, it will be in the dumpreg file with the others like setreg and emptyvolt. But they will be hex values which you will have to convert. I can help if needed. An older version of the app did have dumpreg in it. Is it still there perhaps in the menu? Anyway the stock values for IAE is 200 and VAE is 3.416, but many people changed their VAE to 3201 to increase capacity a little.

As for your question doing this all stock without mod of the driver, here is my findings. YES it may technically be possible, but its damn hard. Before modding this driver and app dev, i tried over and over about 200 times by draining to near zero right before shut down, and using os monitor viewing the dmesg log filtered for "batt". Only ONE time did i get lucky and flipped the status reg to learnf active. And i lost it after 1 minute. I struck gold and tried forever to do it again but never could. Constant shut down then boot up looking for that learnf on the status reg. Finally i just never got it again, so we had to write the app to read the registers at a faster rate, which unfortunately included modding the driver to read statusreg at a faster rate. The problem doing it stock is the driver only updates every 50 seconds but learnf often only lasts 10 seconds before shut down. So you have to be lucky and the timing must work out, which is pure luck and nearly impossible.

About power saving mode, i read about it but didnt try much with it honestly. I thought it was not controllable.

Anyway if this is about trying to mod the desire kernel or something do we have the stock driver code? I can try if we do.

Edit: and to add, you can change your IAE and VAE values to anything you want. I did many times during testing. It makes learnf easier to hit. In fact, my story above that i described, i dont think i was aware of IAE being set to 200 at the time i did that test. So i'd bet you COULD easily hit learnf with a complete stock setup. You just have to keep current above 200 mA right at shut down/empty point. I'm almost positive that will work. Just plug in the instant shut down message appears, while simultaneously pushing the device hard with gps or web browser scrolling etc.
[Nexus One Android Development] 7_michel:
O.K. Many thanks for these informations, I will try a calbration accordingly
[Nexus One Android Development] theGanymedes:
Well, after learned (and verified) that all the calibration is lost when you charge phone-off; I tried to devise a solution so that the calibration is more permanent.

First, I tried changing Full40 value accordingly: This does work on AOSP Kernels, since that modified driver doesn't change acr value itself; whilst the "stock" driver does - this is completely insane, right!? Check what it does (line 1166):

if ((htc_batt_info.rep.level != 100) &&
(htc_batt_info.rep.guage_status_reg & 0x80) &&
(htc_batt_info.rep.batt_current <= 80) &&
(htc_batt_info.rep.full_acr == 0)) {
acr[0] = 0x0d;
acr[1] = 0x87;
w1_ds2784_write(di->w1_dev, acr, DS2784_REG_ACCUMULATE_CURR_MSB, 2);
htc_batt_info.rep.full_acr = 1;
pr_info("[HTC_BATT] Current Full ACR = %x %x\n", acr[0], acr[1]);
pr_info("[HTC_BATT] Recharging should set ACR to 100 percent\n");
}

This idiot driver clearly resets the ACR value to 1442mAh - which is approximate to a brand new one! What if I do have an aged battery? Then you're screwed, because your device will always shut down at higher percentages (w.r.t its age). And also, since you're depleting your battery with that, you're actually accelerating the rate your battery dies. Congratulations, really... This is the most redneck-style code I've ever seen, about something such crucial like a battery in a PDA..

Another funny thing is: DS2784 chip specification clearly states that ACR value is rewritten with Full value (at the temperature) if the CHGTF (charge full) status is reached with current is below charging current (we set that 20 mA during calibration); so, why does driver set this again, (to a wrong value for an aged battery) anyway?!?!

I think that we really need to evaluate the battery driver again - if it has problems like the one I described here, well, I've one thing to say:

Justin Lin - thank you for helping killing our batteries even more.

ADDENDUM:

Since the battery age value is somehow rewritten to 94% when you charge your phone off, I recommend editing the full40 value accordingly. In order to do that, first start and successfully complete a learning cycle; and then reboot (or power on/off). After this, you shall see the age value of your battery (say XX%).

Now, you should calculate "real" mAh value using this:

[B]REAL Capacity[/B] = "Real" Full40 Value (1452 in Stock etc.) x Age Percentage (0.XX)

Now, we must recalculate the "fake" Full40 value and write it to EEPROM, so that our battery will be always calibrated (even charged off):

[B]"Fake" Full40[/B] = Real Capacity / 0.94

Write this value to Full40 assignment area in the Learn Prep app in the application, press Save and you're done.. Congrulatulations, you just calibrated your battery, even when it's charged off.

NOTE: Since some internal calculations also use Full40 value, I recommend you to write rounded to next value, rather than truncated.
[Nexus One Android Development] theGanymedes:
Latest findings: the phone doesn't heed the Full40 value when charged phone-off!

Today, I charged my device from 1% whilst it was on, and it did really charge to the aged capacity (I did know it was 1180 in my case). After this, I let it discharge a little to about 89%. Then turned the device off, to see if the Capacity will be set correctly.

I charged the phone till it's green led; then turned the device back on and checked the remaining current: it was showing 1393 mA - which is a wrong value. Apparently, charging device off doesn't only change Age Scalar value, but also the "remaining charge" value wrongly.

Since the only 1393 value was Aged Capacity value (AC register), I tried changing it to 1180 and then retested. It DID work! Device was showing that it has 1180 mA - which was the correct value!

Weird thing is, the DS2784 spec. sheet is saying that AC register value is used to determine the Age Scalar (AS) value only - which doesn't seem to reflect the truth much. Apparently, AC register value is also used by the device to reinitialize ACR value (Accumulated current register - which is showing the capacity currently available).

So far what I know is:

1- When the device on, ACR value is updated only when CHGTF bit is set (charge is complete - that is voltage is above min. charge voltage (4099 in my case) and current drawn is positive and smaller than 20 mA) - and it's set to Full40*AgeScalar value (with the units etc. calculated of course)

2- When the device is off, and the battery is full, ACR value is written the value in AC register. (At this level, AgeScalar value might also be altered accordingly to AC / Full40 - I'm going to test this next)

3- When the battery is not full, the ACR value is never reinitialized, only updated (incremented or decremented); so this explains why the battery doesn't shut itself down at 15% when it's charged to (say) 50% after a complete discharge - As long as we charge less then aged capacity, the 15% shutdown event doesn't happen.

So, shortly, in order to make calibration permanent, we need to re-evaluate and set the AC register as well. The value in AC register can be obtained by this formula:

[B]Capacity (to set)[/B] * 15 (Rsns value) / 6.25 (constant) = AC register value

Convert this AC register value to HEX and then write to the registers 62 and 63.

Found out that the Full40 value is actually saved after one charge/discharge cycle, so this steps are unnecessary (just the steps at the quoted zone is enough).
[Nexus One Android Development] theGanymedes:
UPDATE: Setting Full40 value to the Stock Full value whilst AC register keeps the aged value doesn't update the AS value, thus making the DS2784 chip think that the battery is never charged to full.

From what I obtained, I think the charge algorithm works this way (when the device is off):

1- Check if the input voltage is higher than Charge Voltage (4099mV) and Ampere value is positive and lower than the Charge Ampere Min Value (20mA). If it is, set ACR value to AC value and set CHGTF flag to true. -> This makes our little green friend on.

The difference of this algorithm from the device-on charging is; ACR value is not assigned Full Value * Age -- instead assigned from the AC value, which is not documented this way!

Ergo, if Full40 value is 1452; since age is always reset to 94%; your battery will think it has 1393 mA (default value in AC) in it, even though it's actually less (in aged battery). If your Full40 value is consistent with the actual data (full * 0,94 == actual cap.); but your AC value is high, your battery will again think that it has more than it actually have.

So, after a successful calibration, in order to make calibration work even under phone-off charge, you should update your full40 value (written how to do that above) and AC value (also written above).

Right now I've did all those things and charging the phone off. If it lights the green light; and the data becomes consistent on boot; I'll let you know that this is the steps for permanent calibration.

Keep up!

ADDENDUM: My theory was correct! Charged the device off, till it's green light; and after the boot, I could still see the "actual" capacity at the capacity level, with the right percentages. Soon, I'll publish the patch I made in the kernel, which makes the process available under Sense ROM's, along with the fix of blunt that HTC did ;)
[Nexus One Android Development] seanyzf:
So ideally, the mV should be 3200.00 and mAh @ 0 when it dies at 0%? Y does the batt aged to 83% from 100% after a reboot? Does this mean that the batt can now only hold 83% of the total capacity?
[Nexus One Android Development] theGanymedes:
Precisely.

Well, your battery lost it's capacity, so the learning phase found out the actual capacity. Your age level should have dropped - this is normal - if it's not a a brand new battery. It's actually the whole point of battery calibration.

Ideally (old or new) the battery shows 3200 mV when empty and 4180 (sometimes 4200) mV when it's full. This never changes - it's why Li-Ion batteries are told "never to suffer from memory effect". The thing is, cells get older in time and even though they always yield the same voltages, they might not last the same (mAh value gets lower). Age value shows this change.

Now, you have calibrated your battery, and as long as you don't charge it phone-off, or switch to a Sense ROM (normally, changing ROM doesn't broke calibration of battery, but I've found a bug in Sense Kernels which does that, see above); your battery will not let you down - that's it won't shut down at weird percentages.