Thread (12 messages) 12 messages, 4 authors, 2017-04-11

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

From: Pavel Machek <hidden>
Date: 2016-02-21 21:13:01

Hi!
it could be something similar to (I might have made a mistake when applying scaling):

/* calculate remaining fuel level (in %) of a LiIon battery assuming
* a standard chemistry model
*    http://cseweb.ucsd.edu/~trosing/lectures/battery.pdf
*
* @mV: voltage measured outside the battery
* @mA: current flowing out of the battery
* @mOhm: assumed series resitance of the battery
*
* returns value between 0 and 100
*/

static inline int fuel_level_LiIon(int mV, int mA, int mOhm) {
	int u;
	/* internal battery voltage is higher than measured */
add " when discharging".
	mV += (mOhm * mA) /1000;

	/* apply formula */
 	u = 3870000 - (14523 * (37835 - 10 * mV));
	/* linear approximation between 3.756V */
	if (u < 0)
		return ((mV - 3300) * ((3756 - 3300) * 1966)) / 100000;
	return (1966 + sqrt(u))/100;
}
Thanks,
									Pavel

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help