Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,730,130 Members 53,836 Now Online
XDA Developers Android and Mobile Development Forum

[UTILITY] Battery calibration tools

Tip us?
 
theloginwithnoname
Old
(Last edited by theloginwithnoname; 5th December 2010 at 10:27 AM.)
#1  
Senior Member - OP
Thanks Meter 32
Posts: 593
Join Date: Mar 2010
Default [UTILITY] Battery calibration tools

This thread is for those following the battery calibration thread that would like to help build tools to read and set some advanced battery values, and ultimately recalibrate in learning mode.

It takes its inspiration from this forum thread over at precentral :

http://forums.precentral.net/palm-pr...r-battery.html

See HOW-TO in post 3 below, or in-thread post from mtw4991, for instructions on using app to calibrate
Samsung Galaxy Note running OmniROM 4.4.x (one of the latest nightlies)
disclaimer: any info, code, or software I provide is used or installed at your own risk; I accept no responsibility for anything that may happen as a result of using them and, by temporarily or permanently doing so on your device, you are agreeing to these terms.
last updated: 21dec13
The Following 4 Users Say Thank You to theloginwithnoname For This Useful Post: [ Click to Expand ]
 
theloginwithnoname
Old
(Last edited by theloginwithnoname; 7th February 2011 at 07:35 PM.)
#2  
Senior Member - OP
Thanks Meter 32
Posts: 593
Join Date: Mar 2010
Default reference material

battery manufacturer technical info
  1. DS2784 data sheet - http://datasheets.maxim-ic.com/en/ds/DS2784.pdf
  2. Storing Fuel Gauge Parameters in the DS2784 - http://pdfserv.maxim-ic.com/en/an/AN4043.pdf
  3. Lithium-Ion Cell Fuel Gauging with Maxim Battery Monitor ICs - http://pdfserv.maxim-ic.com/en/an/AN131.pdf
code

app availability

reference info

related apps

specific code references
(with reference to the manufacturer battery info above)
  • 1 - CONTROL REGISTER FORMAT - page 12 - UVEN—Undervoltage Enable
  • 1 - CAPACITY ESTIMATION ALGORITHM - page 21 - Figure 3: Top-Level Algorithm Diagram
  • 1 - page 24
    • from Active Empty Voltage (VAE) - includes Aging Capacity (AC) and Age Scalar (AS)
    • CAPACITY ESTIMATION OPERATION - Learn Function ("A continuous charge from empty to full results in a learn cycle." then "First, the active empty point must be detected."!!)
  • 1 - page 25 - STATUS REGISTER FORMAT
  • (to be completed)


with thanks to RogerPodacter for his help in compiling this list
Samsung Galaxy Note running OmniROM 4.4.x (one of the latest nightlies)
disclaimer: any info, code, or software I provide is used or installed at your own risk; I accept no responsibility for anything that may happen as a result of using them and, by temporarily or permanently doing so on your device, you are agreeing to these terms.
last updated: 21dec13
The Following 6 Users Say Thank You to theloginwithnoname For This Useful Post: [ Click to Expand ]
 
theloginwithnoname
Old
(Last edited by theloginwithnoname; 11th April 2012 at 08:05 AM.) Reason: added another HOW-TO
#3  
Senior Member - OP
Thanks Meter 32
Posts: 593
Join Date: Mar 2010
Default progress status and useable findings

status

we have made mods to the kernel code (based on 2.6.35.x) to
  • make any register writable
  • make the following registers readable: AGE, Vae (ACTIVE_EMPTY_VOLT), and Status Reg (STS)
  • allow read/write of these registers via virtual files
  • remove pseudo-extended battery charging
  • edit 2010/11/17: created a "dumpreg" file to show all registers and their current values
edit 2010/11/17:
work is being done on a GUI app with the following initial functionality:
  • show when learn mode is hit
  • save age when learn mode is complete
the following functionality may be in:
  • option to restore age when app launched


HOW-TO

Quote:
Originally Posted by mtw4991
How to calibrate your battery using the Battery Calibrator App....
(original text: http://forum.xda-developers.com/show...&postcount=340)

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

How to perform a Capacity Test for your battery. Credit goes to the infamous Temasek!

Prepare for another learn cycle
This time we will do what I call a capacity test.
Perform another learn cycle.
Once cycle completed do not reboot. Check your battery log using an app like OS Monitor. See your highest achieved capacity at 99-100% before it completed its charge. The capacity should drop below your full40. Read the log properly. The highest achieved capacity before it drop below your full40 will be your new full40 value.
With your new full40 value, perform yet another learn cycle.
Enjoy your new calibrated battery!
HOW-TO2:
http://forum.xda-developers.com/show...&postcount=284 (as requested by St4hli)
The Following 13 Users Say Thank You to theloginwithnoname For This Useful Post: [ Click to Expand ]
 
theloginwithnoname
Old
(Last edited by theloginwithnoname; 26th August 2010 at 12:25 PM.) Reason: tidy up formatting
#4  
Senior Member - OP
Thanks Meter 32
Posts: 593
Join Date: Mar 2010
Default Initial investigation and analysis

OK, so I'm going to try and use the following repositories in github and in this order:

AOSP > pershoot > CyanogenMod > others

as I'd like it as generic as possible and ideally integrate any patches at the highest level.

Not being an expert in github, you'll have to excuse any obvious noobness! I couldn't see any of the 2784 battery stuff in AOSP so I'm guessing the CM team used the Desire kernel source from developer.htc.com to integrate the files. Actual code here:

http://member.america.htc.com/downlo...4b7033a.tar.gz

------

At:

http://github.com/CyanogenMod/cm-ker...2784_battery.c

we see device info struct as:

Code:
    char raw[DS2784_DATA_SIZE]; /* raw DS2784 data */

    struct battery_status status;

    struct power_supply bat;
    struct workqueue_struct *monitor_wqueue;
    struct work_struct monitor_work;
    struct alarm alarm;
    struct wake_lock work_wake_lock;
with battery_status struct as:

Code:
    u8 percentage; /* battery percentage */
    u8 charge_source;
    u8 status_reg;
    u8 battery_full; /* battery full (don't charge) */
i.e. not many properties.

However, from the corresponding include file at:

http://github.com/CyanogenMod/cm-ker...er/w1_ds2784.h

there are lots of defined registers, including several AGE and FULL_40.


Our 2784 code has both read and write functions (w1_ds2784_read/write), which are used in function ds2784_battery_read_status.


** Objective 1**

title:
to read some additional values such as AGE and FULL_40 and output them.

suggested implementation:
add in some other properties corresponding to AGE and FULL_40 values, populate these in the read function, parse them in the parse_data function, then output them at line 325 of the ds2784_battery.c file. Yes there will be lots of repetition, but the code is easily and quick to modify.

ideal implementation:
write a new app that outputs these but also outputs the status_reg value too. We can then use this to determine if and when our batteries go into "learning" mode. More below.

code-level:
1) modify struct battery_status, adding:

Code:
u16 age;
u16 full_40;
etc, with any other interesting ones too. Might as well grab all of them and output so we can hand-pick the ones that are useful.

2) from line 244 in parse_data, add something like:

Code:
s->age = raw[DS2784_REG_AGE_SCALAR];
etc
may have to convert from hex.


*****************
THEN I opened the HTC ds2784_battery.c and was amazed at what I saw!
*****************

*their* battery_info struct contains:

Code:
    u8 level;        /* formula */
    u8 level_last;
    u32 full_bat;        /* Full capacity of battery (mAh) */
    u32 full_level;        /* Full level for battery control */
    u8  guage_status_reg;/* guage status*/
    u32 acr;
    u32 active_empty;
their ds2784_device_info struct:

Code:
    int guage_status_reg;    /* battery status register offset=01h*/
    int full_mah;            /* battery full mah */
    long full_charge_count;  /* Full charge counter */
    int acr;
    int active_empty;
    int full_level;        /* Full level for battery control */
OK nothing earthshattering so far, BUT their Calculate_Full_mAh function uses the FULL_40 stuff.


** Objective 2 **

title: write values to registers

implementation: to be discussed once we have the values from Objective 1 and we still need it (i.e. learning mode does not exist or work to recalibrate).



Wrap-up:

The HTC charging code (from line 854) uses the following logic:

Code:
percent < 95, batt full = false

if status_reg = full and current <= 80 and percent = 100
then *IF IT HAS BEEN ONE HOUR OR MORE ON FULL CHARGE*!!!
  then stop charging
WOW.
Samsung Galaxy Note running OmniROM 4.4.x (one of the latest nightlies)
disclaimer: any info, code, or software I provide is used or installed at your own risk; I accept no responsibility for anything that may happen as a result of using them and, by temporarily or permanently doing so on your device, you are agreeing to these terms.
last updated: 21dec13
 
dvgrhl
Old
#5  
dvgrhl's Avatar
Senior Member
Thanks Meter 36
Posts: 258
Join Date: Apr 2010
Location: Seattle
Nice thread. I'll give you a hand with this. Do you still need help getting your kernel compiling set up?
 
theloginwithnoname
Old
#6  
Senior Member - OP
Thanks Meter 32
Posts: 593
Join Date: Mar 2010
Quote:
Originally Posted by dvgrhl View Post
Nice thread. I'll give you a hand with this. Do you still need help getting your kernel compiling set up?
yeah - how best to do this? what about gtalk? <mylogin>@gmail.com if you are OK with that. Will be online in two mins
Samsung Galaxy Note running OmniROM 4.4.x (one of the latest nightlies)
disclaimer: any info, code, or software I provide is used or installed at your own risk; I accept no responsibility for anything that may happen as a result of using them and, by temporarily or permanently doing so on your device, you are agreeing to these terms.
last updated: 21dec13
 
RogerPodacter
Old
#7  
Senior Member
Thanks Meter 393
Posts: 5,574
Join Date: Apr 2010
Location: Los Angeles, CA
loginwithnoname, very nice summary and overview. the HTC driver is what most interests me. i guess there would be zero chance of using the HTC code and logic, since it seems they A) use the better values of full_capacity, etc rather than the nexus "conservative" estimation. and B) theirs looks a little more straight forward than the nexus one.

where did you find the HTC driver? i cant seem to find it.

nice work!
Past projects
Github
My N1 Battery Project

Phone: Nexus 5
ROM: stock rooted
Recovery: CWM Touch
 
RogerPodacter
Old
(Last edited by RogerPodacter; 26th August 2010 at 06:01 PM.)
#8  
Senior Member
Thanks Meter 393
Posts: 5,574
Join Date: Apr 2010
Location: Los Angeles, CA
just in case you still interested, here is the AOSP source code that pershoot used. well he used his code, then he posted this link in the other thread and said this is his current source he's using.

EDIT: sorry i meant this link
EDIT2: geez, still was cm code. i'll find it real quick.
finally:
http://android.git.kernel.org/?p=ker...msm-2.6.35-wip
Past projects
Github
My N1 Battery Project

Phone: Nexus 5
ROM: stock rooted
Recovery: CWM Touch
 
theloginwithnoname
Old
#9  
Senior Member - OP
Thanks Meter 32
Posts: 593
Join Date: Mar 2010
Quote:
Originally Posted by RogerPodacter View Post
the HTC driver is what most interests me. i guess there would be zero chance of using the HTC code and logic, since it seems they A) use the better values of full_capacity, etc rather than the nexus "conservative" estimation. and B) theirs looks a little more straight forward than the nexus one.
I think their code is old-hat given what we've done in the other thread, apart from the fact they wait an hour before deeming the battery "fully charged". I don't think as techies/devs we need that though.

Quote:
Originally Posted by thelogin
I couldn't see any of the 2784 battery stuff in AOSP so I'm guessing the CM team used the Desire kernel source from developer.htc.com to integrate the files. Actual code here:

http://member.america.htc.com/downlo...4b7033a.tar.gz

Quote:
where did you find the HTC driver? i cant seem to find it.
aw, come on Rog! that'll be http://developer.htc.com then click the download button for HTC Desire kernel source code
Samsung Galaxy Note running OmniROM 4.4.x (one of the latest nightlies)
disclaimer: any info, code, or software I provide is used or installed at your own risk; I accept no responsibility for anything that may happen as a result of using them and, by temporarily or permanently doing so on your device, you are agreeing to these terms.
last updated: 21dec13
 
RogerPodacter
Old
(Last edited by RogerPodacter; 26th August 2010 at 06:35 PM.)
#10  
Senior Member
Thanks Meter 393
Posts: 5,574
Join Date: Apr 2010
Location: Los Angeles, CA
Quote:
Originally Posted by theloginwithnoname View Post
I think their code is old-hat given what we've done in the other thread, apart from the fact they wait an hour before deeming the battery "fully charged". I don't think as techies/devs we need that though.

aw, come on Rog! that'll be http://developer.htc.com then click the download button for HTC Desire kernel source code
ha i found the HTC developer site, and grabbed the 74mb source kernel for the desire, but i'm at my work computer which i have no admin rights to do anything. how could i view that code? i was hoping for online repositories like github.
Past projects
Github
My N1 Battery Project

Phone: Nexus 5
ROM: stock rooted
Recovery: CWM Touch

Tags
battery, calibration, capacity, learn
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes