Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1507156 > unrolled thread

Re: generic-adc-battery volatge-to-percent formula

Started byPavel Machek <pavel@ucw.cz>
First post2016-10-24 14:40 +0200
Last post2016-10-24 15:10 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: generic-adc-battery volatge-to-percent formula Pavel Machek <pavel@ucw.cz> - 2016-10-24 14:40 +0200
    Re: generic-adc-battery volatge-to-percent formula "H. Nikolaus Schaller" <hns@goldelico.com> - 2016-10-24 15:10 +0200

#1507156 — Re: generic-adc-battery volatge-to-percent formula

FromPavel Machek <pavel@ucw.cz>
Date2016-10-24 14:40 +0200
SubjectRe: generic-adc-battery volatge-to-percent formula
Message-ID<svMHM-7B9-33@gated-at.bofh.it>

[Multipart message — attachments visible in raw view] — view raw

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?

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

[toc] | [next] | [standalone]


#1507177

From"H. Nikolaus Schaller" <hns@goldelico.com>
Date2016-10-24 15:10 +0200
Message-ID<svNaN-80A-13@gated-at.bofh.it>
In reply to#1507156

[Multipart message — attachments visible in raw view] — view raw

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.

BR,
Nikolaus

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web