Fix voltage roundings.

git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@2458 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Jean Delvare committed 2004-04-20 17:12:55 +00:00
1 parent 621de3361a
commit 48e0e22aea
1 file changed
+17 -25
+17 -25
View File
@@ -125,48 +125,40 @@ static const u8 reghyst[] = { 0x3a, 0x3e, 0x1e };
// regVal = (volts/factor-133)/25
// (These conversions were contributed by Jonathan Teh Soon Yew
// <j.teh@iname.com>)
//
// These get us close, but they don't completely agree with what my BIOS
// says- they are all a bit low. But, it all we have to go on...
static inline u8 IN_TO_REG(long val, int inNum)
{
// to avoid floating point, we multiply everything by 100.
// val is guaranteed to be positive, so we can achieve the effect of
// rounding by (...*10+5)/10. Note that the *10 is hidden in the
// /250 (which should really be /2500).
// At the end, we need to /100 because we *100 everything and we need
// to /10 because of the rounding thing, so we /1000.
/* To avoid floating point, we multiply constants by 10 (100 for +12V).
Rounding is done (1205000 is actually 1330000 - 125000).
Remember that val is expressed in 0.01V/bit, which is why we divide
by an additional 1000 (10000 for +12V): 100 for val and 10 (100)
for the constants. */
if (inNum <= 1)
return (u8)
SENSORS_LIMIT(((val * 210240 - 13300) / 250 + 5) / 1000,
0, 255);
SENSORS_LIMIT((val * 21024 - 1205000) / 250000, 0, 255);
else if (inNum == 2)
return (u8)
SENSORS_LIMIT(((val * 157370 - 13300) / 250 + 5) / 1000,
0, 255);
SENSORS_LIMIT((val * 15737 - 1205000) / 250000, 0, 255);
else if (inNum == 3)
return (u8)
SENSORS_LIMIT(((val * 101080 - 13300) / 250 + 5) / 1000,
0, 255);
SENSORS_LIMIT((val * 10108 - 1205000) / 250000, 0, 255);
else
return (u8) SENSORS_LIMIT(((val * 41714 - 13300) / 250 + 5)
/ 1000, 0, 255);
return (u8)
SENSORS_LIMIT((val * 41714 - 12050000) / 2500000, 0, 255);
}
static inline long IN_FROM_REG(u8 val, int inNum)
{
// to avoid floating point, we multiply everything by 100.
// val is guaranteed to be positive, so we can achieve the effect of
// rounding by adding 0.5. Or, to avoid fp math, we do (...*10+5)/10.
// We need to scale with *100 anyway, so no need to /100 at the end.
/* To avoid floating point, we multiply constants by 10 (100 for +12V).
We also multiply them by 100 because we want 0.01V/bit for the
output value. Rounding is done. */
if (inNum <= 1)
return (long) (((250000 * val + 13300) / 210240 * 10 + 5) /10);
return (long) ((25000 * val + 133000 + 21024 / 2) / 21024);
else if (inNum == 2)
return (long) (((250000 * val + 13300) / 157370 * 10 + 5) /10);
return (long) ((25000 * val + 133000 + 15737 / 2) / 15737);
else if (inNum == 3)
return (long) (((250000 * val + 13300) / 101080 * 10 + 5) /10);
return (long) ((25000 * val + 133000 + 10108 / 2) / 10108);
else
return (long) (((250000 * val + 13300) / 41714 * 10 + 5) /10);
return (long) ((250000 * val + 1330000 + 41714 / 2) / 41714);
}
/********* FAN RPM CONVERSIONS ********/