All of lore.kernel.org
 help / color / mirror / Atom feed
* [lm-sensors] Andigilog asc7621 driver: Temperature scaling
@ 2010-03-07  2:13 Ken Milmore
  2010-03-07  7:53 ` Jean Delvare
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Ken Milmore @ 2010-03-07  2:13 UTC (permalink / raw)
  To: lm-sensors

Hi George et al,

Its great to see the aSC7621 driver being resurrected, but I notice in 
the patches flying about recently (see LKML 22 Feb 2010 in particular) 
that the voltage calculation is a bit off, as I already pointed out in a 
previous review.  To get the correct results, it is much easier to use 
the 3/4 scale values given in the data sheet, and also be careful to do 
the multiplication before the division to avoid loss of precision (Hint: 
The BSD version of the driver does it correctly!).

See below:


static int asc7621_in_scaling[] = {
     2500, 2250, 3300, 5000, 12000
};


For the 10-bit voltage registers, do something like this:

long regval      (data->reg[param->msb[0]] << 8) |
     (data->reg[param->lsb[0]]);
regval = (regval >> 6) * asc7621_in_scaling[index] / (192 << 2);


And for the 8-bit registers:

long regval = data->reg[param->msb[0]];
regval = regval * asc7621_in_scaling[index] / 192;


I've not yet checked the code thoroughly to look for any of the other 
fixes which were put in during our previous discussions, but I suspect 
that some of the other minor fixes which were discussed on the mailing 
list may have been left out.

This was a very ambitious driver in that it included all the fancy 
thermal management features of the aSC7621, and a complete review and 
testing of everything in the driver was a lot more than I had the 
stomach for.  I'm glad to see others have now picked it up though!

Best wishes,

Ken.


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [lm-sensors] Andigilog asc7621 driver: Temperature scaling
  2010-03-07  2:13 [lm-sensors] Andigilog asc7621 driver: Temperature scaling Ken Milmore
@ 2010-03-07  7:53 ` Jean Delvare
  2010-03-07 10:20 ` Ken Milmore
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Jean Delvare @ 2010-03-07  7:53 UTC (permalink / raw)
  To: lm-sensors

Hi Ken,

On Sun, 07 Mar 2010 02:13:07 +0000, Ken Milmore wrote:
> Hi George et al,
> 
> Its great to see the aSC7621 driver being resurrected, but I notice in 
> the patches flying about recently (see LKML 22 Feb 2010 in particular) 
> that the voltage calculation is a bit off, as I already pointed out in a 
> previous review.  To get the correct results, it is much easier to use 
> the 3/4 scale values given in the data sheet, and also be careful to do 
> the multiplication before the division to avoid loss of precision (Hint: 
> The BSD version of the driver does it correctly!).

The patch is already committed upstream:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;hÕ8de038728221f780e11d50b32aa40d420c1150
Any further change must be provided as an incremental patch on top of
that.

> 
> See below:
> 
> 
> static int asc7621_in_scaling[] = {
>      2500, 2250, 3300, 5000, 12000
> };
> 
> 
> For the 10-bit voltage registers, do something like this:
> 
> long regval >      (data->reg[param->msb[0]] << 8) |
>      (data->reg[param->lsb[0]]);
> regval = (regval >> 6) * asc7621_in_scaling[index] / (192 << 2);
> 
> 
> And for the 8-bit registers:
> 
> long regval = data->reg[param->msb[0]];
> regval = regval * asc7621_in_scaling[index] / 192;

Looking at the current code, show_in8() looks OK to me. Multiplication
happens before division. It uses a 256 scaling factor instead of 192
but that shouldn't make a difference because the per-channel scale
values have been adjusted meanwhile.

show_in10(), OTOH, indeed suffers from the problem you describe: the
divisions happens before the multiplication, leading to loss of
accuracy.

Care to send a patch fixing this issue?

> I've not yet checked the code thoroughly to look for any of the other 
> fixes which were put in during our previous discussions, but I suspect 
> that some of the other minor fixes which were discussed on the mailing 
> list may have been left out.

Feel free to send patches fixing them.

> This was a very ambitious driver in that it included all the fancy 
> thermal management features of the aSC7621, and a complete review and 
> testing of everything in the driver was a lot more than I had the 
> stomach for.  I'm glad to see others have now picked it up though!

-- 
Jean Delvare

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [lm-sensors] Andigilog asc7621 driver: Temperature scaling
  2010-03-07  2:13 [lm-sensors] Andigilog asc7621 driver: Temperature scaling Ken Milmore
  2010-03-07  7:53 ` Jean Delvare
@ 2010-03-07 10:20 ` Ken Milmore
  2010-03-07 10:44 ` Jean Delvare
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Ken Milmore @ 2010-03-07 10:20 UTC (permalink / raw)
  To: lm-sensors

Hello Jean,

Regarding the scale factors, I think you'll find that those given for 
the 2.5V, 3.3V and 5V ranges are far enough wrong introduce a 2-bit 
error in the 10-bit values.  The driver goes to some trouble to get the 
full 10 bit precision by combining both the MSB and LSB registers, then 
throws that precision away in the calculations!

You really do need to use the 3/4 scale voltage values, or some 
equivalent rational scaling, to get the right answers here.  That's why 
Andigilog provide them in the data sheet! :-)

I will try and get a patch together as soon as time permits.

Regards,

Ken.


On 07/03/10 07:53, Jean Delvare wrote:
> Hi Ken,
>
> On Sun, 07 Mar 2010 02:13:07 +0000, Ken Milmore wrote:
>> Hi George et al,
>>
>> Its great to see the aSC7621 driver being resurrected, but I notice in
>> the patches flying about recently (see LKML 22 Feb 2010 in particular)
>> that the voltage calculation is a bit off, as I already pointed out in a
>> previous review.  To get the correct results, it is much easier to use
>> the 3/4 scale values given in the data sheet, and also be careful to do
>> the multiplication before the division to avoid loss of precision (Hint:
>> The BSD version of the driver does it correctly!).
>
> The patch is already committed upstream:
> http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;hÕ8de038728221f780e11d50b32aa40d420c1150
> Any further change must be provided as an incremental patch on top of
> that.
>
>>
>> See below:
>>
>>
>> static int asc7621_in_scaling[] = {
>>       2500, 2250, 3300, 5000, 12000
>> };
>>
>>
>> For the 10-bit voltage registers, do something like this:
>>
>> long regval >>       (data->reg[param->msb[0]]<<  8) |
>>       (data->reg[param->lsb[0]]);
>> regval = (regval>>  6) * asc7621_in_scaling[index] / (192<<  2);
>>
>>
>> And for the 8-bit registers:
>>
>> long regval = data->reg[param->msb[0]];
>> regval = regval * asc7621_in_scaling[index] / 192;
>
> Looking at the current code, show_in8() looks OK to me. Multiplication
> happens before division. It uses a 256 scaling factor instead of 192
> but that shouldn't make a difference because the per-channel scale
> values have been adjusted meanwhile.
>
> show_in10(), OTOH, indeed suffers from the problem you describe: the
> divisions happens before the multiplication, leading to loss of
> accuracy.
>
> Care to send a patch fixing this issue?
>
>> I've not yet checked the code thoroughly to look for any of the other
>> fixes which were put in during our previous discussions, but I suspect
>> that some of the other minor fixes which were discussed on the mailing
>> list may have been left out.
>
> Feel free to send patches fixing them.
>
>> This was a very ambitious driver in that it included all the fancy
>> thermal management features of the aSC7621, and a complete review and
>> testing of everything in the driver was a lot more than I had the
>> stomach for.  I'm glad to see others have now picked it up though!
>

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [lm-sensors] Andigilog asc7621 driver: Temperature scaling
  2010-03-07  2:13 [lm-sensors] Andigilog asc7621 driver: Temperature scaling Ken Milmore
  2010-03-07  7:53 ` Jean Delvare
  2010-03-07 10:20 ` Ken Milmore
@ 2010-03-07 10:44 ` Jean Delvare
  2010-03-07 11:30 ` Ken Milmore
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Jean Delvare @ 2010-03-07 10:44 UTC (permalink / raw)
  To: lm-sensors

On Sun, 07 Mar 2010 10:20:13 +0000, Ken Milmore wrote:
> Regarding the scale factors, I think you'll find that those given for 
> the 2.5V, 3.3V and 5V ranges are far enough wrong introduce a 2-bit 
> error in the 10-bit values.  The driver goes to some trouble to get the 
> full 10 bit precision by combining both the MSB and LSB registers, then 
> throws that precision away in the calculations!
> 
> You really do need to use the 3/4 scale voltage values, or some 
> equivalent rational scaling, to get the right answers here.  That's why 
> Andigilog provide them in the data sheet! :-)

Whether you use the full scale or 3/4 scale voltage values as the base
for the calculation doesn't matter, both can work as long as the
calculation is consistent. What really matters is to multiply before
you divide.

> I will try and get a patch together as soon as time permits.

Great, thanks.

-- 
Jean Delvare

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [lm-sensors] Andigilog asc7621 driver: Temperature scaling
  2010-03-07  2:13 [lm-sensors] Andigilog asc7621 driver: Temperature scaling Ken Milmore
                   ` (2 preceding siblings ...)
  2010-03-07 10:44 ` Jean Delvare
@ 2010-03-07 11:30 ` Ken Milmore
  2010-03-07 12:10 ` Jean Delvare
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Ken Milmore @ 2010-03-07 11:30 UTC (permalink / raw)
  To: lm-sensors


Example:

The 5V sensor with an input of precisely 5V should give an input MSB 
register value of 192.

Using the "full scale" ratios:

    192 * 6640 / 256 = 4980

Using the 3/4 scale ratios:

    192 * 5000 / 192 = 5000

Error calculation:

    (5000 - 4980) / 5000 = 0.4%

This corresponds to a 1-bit error in the 8 bit voltages, or a 3-bit 
error in the 10 bit voltages, effectively giving only 7-bit accuracy in 
the calculated values.  An unnecessary error I think you'll agree.

Although the full scale values could probably be "tweaked" to make them 
slightly better, the rounding issues inherent with integer arithmetic 
make it difficult to get right on the button near the nominal voltages, 
where highest accuracy is appropriate.  This is easily avoided by using 
the simple 3/4 scale ratios given in the data sheet.


On 07/03/10 10:44, Jean Delvare wrote:
> On Sun, 07 Mar 2010 10:20:13 +0000, Ken Milmore wrote:
>> Regarding the scale factors, I think you'll find that those given for
>> the 2.5V, 3.3V and 5V ranges are far enough wrong introduce a 2-bit
>> error in the 10-bit values.  The driver goes to some trouble to get the
>> full 10 bit precision by combining both the MSB and LSB registers, then
>> throws that precision away in the calculations!
>>
>> You really do need to use the 3/4 scale voltage values, or some
>> equivalent rational scaling, to get the right answers here.  That's why
>> Andigilog provide them in the data sheet! :-)
>
> Whether you use the full scale or 3/4 scale voltage values as the base
> for the calculation doesn't matter, both can work as long as the
> calculation is consistent. What really matters is to multiply before
> you divide.
>
>> I will try and get a patch together as soon as time permits.
>
> Great, thanks.
>

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [lm-sensors] Andigilog asc7621 driver: Temperature scaling
  2010-03-07  2:13 [lm-sensors] Andigilog asc7621 driver: Temperature scaling Ken Milmore
                   ` (3 preceding siblings ...)
  2010-03-07 11:30 ` Ken Milmore
@ 2010-03-07 12:10 ` Jean Delvare
  2010-03-07 14:57 ` Ken Milmore
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Jean Delvare @ 2010-03-07 12:10 UTC (permalink / raw)
  To: lm-sensors

Hi Ken,

On Sun, 07 Mar 2010 11:30:13 +0000, Ken Milmore wrote:
> 
> Example:
> 
> The 5V sensor with an input of precisely 5V should give an input MSB 
> register value of 192.
> 
> Using the "full scale" ratios:
> 
>     192 * 6640 / 256 = 4980
> 
> Using the 3/4 scale ratios:
> 
>     192 * 5000 / 192 = 5000
> 
> Error calculation:
> 
>     (5000 - 4980) / 5000 = 0.4%
> 
> This corresponds to a 1-bit error in the 8 bit voltages, or a 3-bit 
> error in the 10 bit voltages, effectively giving only 7-bit accuracy in 
> the calculated values.  An unnecessary error I think you'll agree.
> 
> Although the full scale values could probably be "tweaked" to make them 
> slightly better, the rounding issues inherent with integer arithmetic 
> make it difficult to get right on the button near the nominal voltages, 
> where highest accuracy is appropriate.  This is easily avoided by using 
> the simple 3/4 scale ratios given in the data sheet.

No, you're off track, sorry. The only problem in the driver's formula is
that 6640 was computed as 5000 * 255 / 192, but the formula divides by
256 instead of 255. This is the inconsistency that leads to the 0.4%
error (1/256 = 0.4%). Just use consistent numbers and it will work
fine. The rounding issues inherent to integer arithmetic induce much
smaller errors, down to a level you won't notice them. In the case
above, the max error would be 0.5/6640 = 0.0075%... Way below the
resolution and accuracy of the sensors.

Now, if you insist on using the 3/4 scale values as a basis, really, I
don't care. All I'm saying is this this design change is not _required_
to make the driver return correct values.

-- 
Jean Delvare

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [lm-sensors] Andigilog asc7621 driver: Temperature scaling
  2010-03-07  2:13 [lm-sensors] Andigilog asc7621 driver: Temperature scaling Ken Milmore
                   ` (4 preceding siblings ...)
  2010-03-07 12:10 ` Jean Delvare
@ 2010-03-07 14:57 ` Ken Milmore
  2010-03-17  7:39 ` Jean Delvare
  2010-04-28 12:32 ` Jean Delvare
  7 siblings, 0 replies; 9+ messages in thread
From: Ken Milmore @ 2010-03-07 14:57 UTC (permalink / raw)
  To: lm-sensors


Agreed.  We may be slightly at cross-purposes here.

Sticking with a divisor of 256, I make the nearest consistent set of 
scale factors to be as follows:

static int asc7621_in_scaling[] = {
        3333, 3000, 4400, 6667, 16000
};

These would do pretty well and as you say, the rounding errors would be 
far too small to cause a problem.  I suppose its a matter of taste and 
sticking with the data sheet that makes me prefer the 3/4 scale ratios.

My apologies for what has turned into a slightly pedantic digression!

Not sure why I called this thread "Temperature scaling" either... ;-)

Regards,

Ken.


On 07/03/10 12:10, Jean Delvare wrote:
> Hi Ken,
>
> On Sun, 07 Mar 2010 11:30:13 +0000, Ken Milmore wrote:
>>
>> Example:
>>
>> The 5V sensor with an input of precisely 5V should give an input MSB
>> register value of 192.
>>
>> Using the "full scale" ratios:
>>
>>      192 * 6640 / 256 = 4980
>>
>> Using the 3/4 scale ratios:
>>
>>      192 * 5000 / 192 = 5000
>>
>> Error calculation:
>>
>>      (5000 - 4980) / 5000 = 0.4%
>>
>> This corresponds to a 1-bit error in the 8 bit voltages, or a 3-bit
>> error in the 10 bit voltages, effectively giving only 7-bit accuracy in
>> the calculated values.  An unnecessary error I think you'll agree.
>>
>> Although the full scale values could probably be "tweaked" to make them
>> slightly better, the rounding issues inherent with integer arithmetic
>> make it difficult to get right on the button near the nominal voltages,
>> where highest accuracy is appropriate.  This is easily avoided by using
>> the simple 3/4 scale ratios given in the data sheet.
>
> No, you're off track, sorry. The only problem in the driver's formula is
> that 6640 was computed as 5000 * 255 / 192, but the formula divides by
> 256 instead of 255. This is the inconsistency that leads to the 0.4%
> error (1/256 = 0.4%). Just use consistent numbers and it will work
> fine. The rounding issues inherent to integer arithmetic induce much
> smaller errors, down to a level you won't notice them. In the case
> above, the max error would be 0.5/6640 = 0.0075%... Way below the
> resolution and accuracy of the sensors.
>
> Now, if you insist on using the 3/4 scale values as a basis, really, I
> don't care. All I'm saying is this this design change is not _required_
> to make the driver return correct values.
>

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [lm-sensors] Andigilog asc7621 driver: Temperature scaling
  2010-03-07  2:13 [lm-sensors] Andigilog asc7621 driver: Temperature scaling Ken Milmore
                   ` (5 preceding siblings ...)
  2010-03-07 14:57 ` Ken Milmore
@ 2010-03-17  7:39 ` Jean Delvare
  2010-04-28 12:32 ` Jean Delvare
  7 siblings, 0 replies; 9+ messages in thread
From: Jean Delvare @ 2010-03-17  7:39 UTC (permalink / raw)
  To: lm-sensors

Hi Ken,

On Sun, 07 Mar 2010 10:20:13 +0000, Ken Milmore wrote:
> I will try and get a patch together as soon as time permits.

Do you have a patch by now?

-- 
Jean Delvare

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [lm-sensors] Andigilog asc7621 driver: Temperature scaling
  2010-03-07  2:13 [lm-sensors] Andigilog asc7621 driver: Temperature scaling Ken Milmore
                   ` (6 preceding siblings ...)
  2010-03-17  7:39 ` Jean Delvare
@ 2010-04-28 12:32 ` Jean Delvare
  7 siblings, 0 replies; 9+ messages in thread
From: Jean Delvare @ 2010-04-28 12:32 UTC (permalink / raw)
  To: lm-sensors

On Wed, 17 Mar 2010 08:39:17 +0100, Jean Delvare wrote:
> Hi Ken,
> 
> On Sun, 07 Mar 2010 10:20:13 +0000, Ken Milmore wrote:
> > I will try and get a patch together as soon as time permits.
> 
> Do you have a patch by now?

Ping Ken. Would be nice to have a patch ready soon so that it can make
it into kernel 2.6.35.

-- 
Jean Delvare

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-04-28 12:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-07  2:13 [lm-sensors] Andigilog asc7621 driver: Temperature scaling Ken Milmore
2010-03-07  7:53 ` Jean Delvare
2010-03-07 10:20 ` Ken Milmore
2010-03-07 10:44 ` Jean Delvare
2010-03-07 11:30 ` Ken Milmore
2010-03-07 12:10 ` Jean Delvare
2010-03-07 14:57 ` Ken Milmore
2010-03-17  7:39 ` Jean Delvare
2010-04-28 12:32 ` Jean Delvare

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.