[Desire Android Development] St4hli:
I have read a lot about the calibration and the issues with it, and summarized a few sources to ONE BIG TUTORIAL (if you find mistakes, write me pls):

Advanced Battery Calibration for HTC Desire and Nexus One on NON-SENSE KERNELS

Intro:

This will actually calibrate your battery, unlike other methods out there. After calibration, empty will be at 0% not some arbitrary value like 18%. After the real calibration, step 4 is really important, because somehow the phone resets a value when you charge it while it’s turned off, so don’t forget this!

Be careful!:

When entering the values for the battery registers, pay particular attention that the entered values are the correct ones which are shown below. Failure to enter these values correctly could result in your battery being permanently bricked. You have been warned! I take no responsibility for any damage!

Pre-requisites:

• compatible kernel installed (Cyanogenmod, Oxygen, and probably more) - Sense Kernels need a bit more tweaking, what you can read here: http://xdaforums.com/showthread.php?t=1534892

• Patience

• Jon Richards’ “Nexus One Battery Calibrator” application a.k.a. NOBCAP (available on google play), installed

• An almost dead battery (that is mis-reporting its capacity) with what you think is about ~2% remaining – i.e. if your battery dies at 18%, get ready at about 20%

• AC battery charger at the ready

Process:

0. Run NOBCAP

a. If General tab displays fields but no values, kernel is wrong, see pre-requisites

b. If General tab displays fields filled with values, kernel is right, enable airplane mode on the phone

1. Use the battery calibrator app v.1.3.0 to do the following:

a. Open the app and go to menu>settings and check all boxes. Auto-on airplane mode is optional

b. set your age to 100 using the battery app under the Learn Prep tab and press Save

c. set your full40 to 1452mAh in the same tab if using the stock capacity OEM battery and press Save

NOTE: set your full40 to 1650mAh or higher if using an aftermarket battery and save

2. In the Learn Prep tab:

a.set your aEvolts to 3201 (type on each line: Register:0x 66 Value: a4 and press save)

b. set your stop charging current to <20mA (Register:0x 65 Value: 06 and press save)

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

3. Achieving Learn Mode with the app:

a. turn learn mode on in Learn Mode tab

NOTE: to hit learn mode you must keep your current mA above -200mA draw at the empty point! The app will automatically enable GPS polling to keep you above the required minimum current draw. Hint: Set screen brightness to maximum!

b. wait for mV to drop to 3201mV (the learn mode pop-up box will appear & learnf button will light up)

c. insert charger IMMEDIATELY! (You will see a pop-up message saying Learn Mode is active.)

d. turn off and close any open apps you have running, but leave Battery Calibrator open.

e. put phone into airplane mode so that you don’t get unexpected current draw near the full point.

f. set SetCPU profile to disable overclocking. (set min/max to the same value, ie. 998\998max)

g. charge for a full 4 hrs with stock battery and screen off, 5 hrs for larger capacity batterys. (When charging completes, the CHGTF flag will be lit, Battery Status Register 0x81 displayed, your battery calibrated.)

NOTE: if you want to, you can actually use your phone until the charge reaches 80-90%, then use airplane mode and DO NOT touch the phone, peek, turn on the screen....DO NOTHING but walk away til time is up.

h. unplug and reboot, your new age should be set automatically. Learn is now complete and your phone should now charge to 100% and die at 0-1%. Also, some have reported having to manually power down/power up with the new app to have age reset by the application. If age isn’t change upon reboot, try power off/power on.

4.) Make the calibration permanent (thx to user "theGanymedes"):

Since the battery age value is somehow rewritten to 94% when you charge your phone whilst turned 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:

Code:

REAL Capacity = "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):

Code:

"Fake" Full40 = Real Capacity / 0.94

First, we're setting the age back to 94% - it's because the phone does this when charged off anyway. Then write this new “fake” 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.

5.) Didn’t work?:

Phone dies to early?:

That might be because some kernels do use a different power supply drivers, and these drivers don't update values so often as chip does. Try writing manually the value of "04" to register 0x10 when your battery reaches to 10% or so.

Learn Failure:

If your new age shows 94% upon rebooting, then learn mode failed and you need to do it again, paying close attention as charging nears 80% and above. This is where learn mode can be lost by rogue apps, auto-updates, calls, etc pulling the current down below the minimum prematurely.

Note1: As current gets close to <50-60mA don't touch the phone or you may artifically increase the current draw pulling it below 20mA and it will end the learn cycle prematurely. Airplane mode helps prevent that.

Note2: Learn mode cannot be achieve with the phone off. Leave the phone on until learn is complete and the battery status register shows 0x81. Done!

Sources:

http://xdaforums.com/showpost.php?p=7850480&postcount=3

http://xdaforums.com/showthread.php?t=765609&highlight=0x10&page=212

http://xdaforums.com/showthread.php?t=765609&highlight=0x10&page=213

http://forum.oxygen.im/viewtopic.php?id=723

http://xdaforums.com/showthread.php?t=1534892

https://github.com/dvgrhl/BatteryCalibrator

http://jonrichards.net/

See page 25 of 43 at http://datasheets.maxim-ic.com/en/ds/DS2784.pdf for flag explanations.

See page 30 of 43 at http://datasheets.maxim-ic.com/en/ds/DS2784.pdf for register explanations.