All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Machek <pavel@ucw.cz>
To: "H. Nikolaus Schaller" <hns@goldelico.com>
Cc: Sebastian Reichel <sre@kernel.org>,
	pali.rohar@gmail.com, kernel list <linux-kernel@vger.kernel.org>,
	ivo.g.dimitrov.75@gmail.com, patrikbachan@gmail.com,
	serge@hallyn.com, abcloriens@gmail.com,
	Belisko Marek <marek.belisko@gmail.com>,
	Linux PM mailing list <linux-pm@vger.kernel.org>
Subject: Re: generic-adc-battery volatge-to-percent formula
Date: Tue, 11 Apr 2017 19:31:18 +0200	[thread overview]
Message-ID: <20170411173118.GA17251@amd> (raw)
In-Reply-To: <3F9199B6-233E-4260-9362-498FB1AA3FB7@goldelico.com>

[-- Attachment #1: Type: text/plain, Size: 2259 bytes --]

On Mon 2016-10-24 15:09:26, H. Nikolaus Schaller wrote:
> Hi Pavel,
> 
> > Am 24.10.2016 um 14:34 schrieb Pavel Machek <pavel@ucw.cz>:
> > 
> > Hi!
> > 
> >> On Mon, Feb 22, 2016 at 06:58:13AM +0100, H. Nikolaus Schaller wrote:
> >>>>> static inline int fuel_level_LiIon(int mV, int mA, int mOhm) {
> >>>>> ...
> >>>>> }
> >>> 
> >>> To which header file should this go?
> >> 
> >> I think it should get its own header file in include/linux/power/.
> >> Maybe something like "generic-fuel-gauge.h". I'm open to other
> >> solutions, though.
> > 
> > I'd like to use use this formula in my own code. Is it somewhere in
> > the kernel already?
> 
> Not that I am aware of. Marek is still working on the generic-adc-battery
> driver augmented by DT + iio-ADC + formula before publication.
> 
> Here is the latest draft so you can cherry-pick it into your work:
> 
> 	http://git.goldelico.com/?p=gta04-kernel.git;a=patch;h=22ab047ae296e998379c1aa29fe1210043cfa040
> 
> But beware: I think it is quite wrong using the sqrt() function above 19.66%
> and doing linear interpolation below.
> 
> By using the sqrt() function it has a steepness that goes to infinity when reaching
> 19.66% from above. This makes a quite non-realistic curve with a sharp bend at 19.66%
> (which is equivalent to 3.756 V).
> 
> No real battery I have seen and measured with a coulomb counter has such a strange
> bend at 3.756 V...
> 
> IMHO it would be a better approximation to adjust the factors so that e.g. a realistic
> voltage for "empty" (e.g. 3.3 V) is taken as the 0% point where steepness goes through
> the roof.
> 
> It should then be something like:
> 
> 	SOC = sqrt((Volt - 3.3 V) / (4.2 V - 3.3 V))
> 
> This goes more smoothly between 100% and 0%.
> 
> Or we could even use an exponential function with an exponent different from 1/2
> (1 being linear interpolation):
> 
> 	SOC = pow((Volt - 3.3 V) / (4.2 V - 3.3 V), factor)
> 
> But this would probably need floating point arithmetic in the kernel or some numeric
> approximation algorithm.

Thanks!
									Pavel



-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

      reply	other threads:[~2017-04-11 17:31 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-11 20:38 generic-adc-battery volatge-to-percent formula Belisko Marek
2016-02-12  8:51 ` Pavel Machek
2016-02-15  8:52   ` Belisko Marek
2016-02-15 11:53     ` Pavel Machek
2016-02-21 20:06       ` Sebastian Reichel
2016-02-21 20:36         ` H. Nikolaus Schaller
2016-02-21 21:12           ` Pavel Machek
2016-02-22  5:58             ` H. Nikolaus Schaller
2016-02-22 17:20               ` Sebastian Reichel
2016-10-24 12:34                 ` Pavel Machek
2016-10-24 13:09                   ` H. Nikolaus Schaller
2017-04-11 17:31                     ` Pavel Machek [this message]

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=20170411173118.GA17251@amd \
    --to=pavel@ucw.cz \
    --cc=abcloriens@gmail.com \
    --cc=hns@goldelico.com \
    --cc=ivo.g.dimitrov.75@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=marek.belisko@gmail.com \
    --cc=pali.rohar@gmail.com \
    --cc=patrikbachan@gmail.com \
    --cc=serge@hallyn.com \
    --cc=sre@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.