From: Pavel Machek <pavel@ucw.cz>
To: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: Linus Walleij <linus.walleij@stericsson.com>,
cbou@mail.ru, dwmw2@infradead.org,
LKML <linux-kernel@vger.kernel.org>,
linux-embedded@vger.kernel.org,
Brian Swetland <swetland@google.com>,
rpurdie@rpsys.net, lenz@cs.wisc.edu, Dirk@Opfer-Online.de,
arminlitzel@web.de, Cyril Hrubis <metan@ucw.cz>,
thommycheck@gmail.com,
linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
dbaryshkov@gmail.com, omegamoon@gmail.com, eric.y.miao@gmail.com,
utx@penguin.cz, zaurus-devel@lists.linuxtogo.org
Subject: Re: [POWER] battery calibration parameters from sysfs
Date: Sun, 13 Dec 2009 14:24:14 +0100 [thread overview]
Message-ID: <20091213132413.GB1437@ucw.cz> (raw)
In-Reply-To: <20091207165628.GA24981@rakim.wolfsonmicro.main>
Hi!
> > If you browse down to line 275 you can see it parse the sysfs
> > attribute "capacity", then this propagates up to the battery
> > status indicator on *all* Android phones out there. So if
> > you want to run Android unmodified, this is what you need to
> > provide. They are effectively using the power sysfs as
> > their hardware abstraction layer in this case.
>
> Oh dear. Using the power sysfs as the hardware abstraction seems
> perfectly reasonable but assuming that a given battery driver is going
> to have this level of information doesn't match up with an awful lot of
> actual charger hardware. My main concern here is that battery
> performance monitoring has no pressing need to be in kernel and that
> pushing it into the kernel creates a barrier to implementing more
> advanced schemes in userspace, which is especially serious given how
> involved this needs to be in order to be accurate.
Well, kernel provides /proc/apm emulation and many systems still rely
on it. So it would be nice to provide something halfway-decent there.
Plus you need to shutdown/suspend machine on battery critical. That
has to be in kernel and already needs those tricky parts.
(Sharp got it wrong in collie kernel, and you get 5hours instead of 10
with old battery :-(().
> I'm not sure how familiar you are with the issues surrounding trying to
> do a voltage to charge mapping for a battery but it's much more complex
> than a simple table if you want to get it accurate. There's a lot
> of
Well... current zaurus kernels use _huge_ table that maps voltage to
battery %... and that table is linear function :-(.
Do you have some papers on that?
> dependence on particular operating conditions and things do change as
> the batteries age. There are systems out there that do the work
> required to gather the information in hardware and it's definitely good
> to report the information from them but that doesn't mean it's a good
> idea to try to synthesise the information for other systems.
So... on zaurus I plan to:
1) provide better voltage -- %age map
2) estimate current
3) estimate internal battery resistance as constant
4) estimate internal battery volltage using ohm's law and base %age
estmate on that.
Now... I realize that internal resistance depends on charge left. Nasty
but probably can be ignored. Then it depends on temperature. Does
anyone have better idea how?
Then... I need a way to measure internal resistance. I know it is in
200mOhm to 400mOhm range, on my device. Is there easy way to measure
it more accurately?
Pavel
#!/bin/bash
#
# Copyright 2009 Pavel Machek <pavel@ucw.cz>, GPLv2
#
getval() {
SETTLETIME=5
echo Run this on idle, unplugged system, with expansion cards
echo removed and backlight enabled
echo
echo 1 > /sys/class/backlight/corgi?bl/brightness
echo Backlight 1, waiting for power to settle
sleep $SETTLETIME
VBMIN=`cat /sys/class/power*/*battery/voltage_now`
VBMIN=$[$VBMIN/1000]
echo Voltage = $VBMIN mV
echo
echo 47 > /sys/class/backlight/corgi?bl/brightness
echo Backlight 47, waiting for power to settle
sleep $SETTLETIME
VBMAX=`cat /sys/class/power*/*battery/voltage_now`
VBMAX=$[$VBMAX/1000]
echo Voltage = $VBMAX mV
echo 1 > /sys/class/backlight/corgi?bl/brightness
}
fake1() {
# Very old 1000mAh battery from collie: 703 mOhm
VBMIN=3638
VBMAX=3543
}
fake2() {
# Old 2000mAh battery, nearly charged, 4C: 274 mOhm
VBMIN=3732
VBMAX=3695
}
fake3() {
# Same old 2000mAh battery, nearly charged, 4C: 140 mOhm
# temp: 155.
VBMIN=3714
VBMAX=3695
# Next try: temp 151 -- little warmer: 422 mOhm.
# Next try: temp 151 -- little warmer: 1266 mOhm.
# Next try: temp 148 -- getting warmer: 281 mOhm.
# Next try: temp 148 -- getting warmer, full load: 422 mOhm.
# Next try: temp 148 -- getting warmer, full load: 140 mOhm.
# Next try: temp 148 -- getting warmer, full load: 422 mOhm.
# Next try: temp 138 -- getting warmer, full load: 422 mOhm.
# Next try: temp 139 -- getting warmer, full load: 422 mOhm.
# Next try: temp 136 -- getting warmer, full load: 562 mOhm.
# Next try: temp 132 -- getting warmer, full load: 703 mOhm.
# Next try: temp 132 -- getting warmer, full load: 281 mOhm.
# Next try: temp 134 -- getting warmer, full load: 281 mOhm.
# Next try: temp 134 -- getting warmer, full load: 562 mOhm.
# Next try: temp 129 -- getting warmer, full load: 562 mOhm.
# hugh, I''m getting n*140, wtf?
# ...voltmeters have sensitivity limits...
# temp 118 -- metro, venku zima -- full load: 281 mOhm.
# temp 118 -- metro, venku zima, baterie poloprazdna -- full load: 281 mOhm.
# temp 120 -- metro, venku zima, baterie poloprazdna -- full load: 281 mOhm.
# temp 120 -- metro, venku zima, baterie poloprazdna -- full load: 281 mOhm.
# temp 120 -- metro, venku zima, baterie poloprazdna -- full load: 414 mOhm.
# temp 120 -- metro, venku zima, baterie poloprazdna -- full load: 555 mOhm.
# temp 120 -- metro, venku zima, baterie poloprazdna -- full load: 422 mOhm.
# temp 124 -- metro, venku zima, baterie poloprazdna -- full load: 422 mOhm.
# temp 127 -- metro, venku zima, baterie poloprazdna -- full load: 422 mOhm.
}
getval
#fake1
BLDIFF=135
echo Assuming $BLDIFF mA difference
echo $VBMIN $VBMAX $BLDIFF
# With RESIST in mOhm
# VINSIDE = VBMIN + RESIST * BASECURRENT / 1000
# VINSIDE = VBMAX + RESIST * (BASECURRENT + BLDIFF) / 1000
# Therefore
# RESIST = 1000*(VBMIN-VBMAX)/BLDIFF
RESIST=$[(1000*($VBMIN-$VBMAX))/$BLDIFF]
echo Resistance is $RESIST mOhm
BASECURRENT=280
echo This should be equal:
echo During low backlight $[$VBMIN + ($RESIST * $BASECURRENT) / 1000] mV
echo During high backlight $[$VBMAX + ($RESIST * ($BASECURRENT + $BLDIFF)) / 1000] mV
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
next prev parent reply other threads:[~2009-12-13 13:24 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-04 10:42 [POWER] battery calibration parameters from sysfs Linus Walleij
2009-12-04 10:49 ` Mark Brown
2009-12-04 14:17 ` Mark Brown
2009-12-05 13:08 ` Linus Walleij
2009-12-05 17:45 ` Mark Brown
2009-12-07 11:48 ` Mark Brown
2009-12-07 14:07 ` Linus Walleij
2009-12-07 16:56 ` Mark Brown
2009-12-08 5:27 ` Brian Swetland
2009-12-08 10:28 ` Mark Brown
2009-12-13 13:24 ` Pavel Machek [this message]
2009-12-14 12:12 ` Mark Brown
2009-12-14 21:22 ` Pavel Machek
2009-12-14 23:43 ` Aras Vaichas
2009-12-15 3:02 ` Bill Gatliff
2009-12-15 22:58 ` Aras Vaichas
2009-12-15 23:32 ` Stanislav Brabec
2009-12-16 9:40 ` Andy Green
[not found] ` <4B28AAFC.5010108-/Zus8d0mwwtBDgjK7y7TUQ@public.gmane.org>
2009-12-18 8:48 ` Pavel Machek
[not found] ` <20091214121247.GB22388-HF5t3jzXg/6ND3a5+9QAFujbO/Zr0HzV@public.gmane.org>
2009-12-16 22:53 ` Pavel Machek
2009-12-13 13:19 ` Pavel Machek
2009-12-14 11:50 ` Mark Brown
2009-12-14 11:58 ` Pavel Machek
2009-12-14 12:14 ` Mark Brown
2009-12-04 11:34 ` Alexander Clouter
2009-12-06 20:52 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20091213132413.GB1437@ucw.cz \
--to=pavel@ucw.cz \
--cc=Dirk@Opfer-Online.de \
--cc=arminlitzel@web.de \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=cbou@mail.ru \
--cc=dbaryshkov@gmail.com \
--cc=dwmw2@infradead.org \
--cc=eric.y.miao@gmail.com \
--cc=lenz@cs.wisc.edu \
--cc=linus.walleij@stericsson.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-embedded@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=metan@ucw.cz \
--cc=omegamoon@gmail.com \
--cc=rpurdie@rpsys.net \
--cc=swetland@google.com \
--cc=thommycheck@gmail.com \
--cc=utx@penguin.cz \
--cc=zaurus-devel@lists.linuxtogo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).