All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean Delvare <jdelvare@suse.de>
To: lm-sensors@vger.kernel.org
Subject: Re: [lm-sensors] How to compute a voltage that may be positive or negative
Date: Tue, 02 Sep 2014 08:34:33 +0000	[thread overview]
Message-ID: <20140902103433.2afb4971@endymion.delvare> (raw)
In-Reply-To: <CAF_O4Js3aRF7iofSey0w+F8azTGbawX5vEe9cmHqybk9Qj=yvg@mail.gmail.com>

Hi Christopher,

On Fri, 22 Aug 2014 18:31:22 -0400, Christopher Cordahi wrote:
> I'm wondering if this is a valid use case.  I need to perform both a
> multiplication and a subtraction to compute an original voltage.
> 
> lm sensors 3.2.0 is working fine on Linux 2.6.39.4 reading an ADS1115 ADC
> chip that measures a voltage from 0 V to about 2 V.
> 
> # uname -srmo
> Linux 2.6.39.4 armv5tejl GNU/Linux
> # sensors --version
> sensors version 3.2.0 with libsensors version 3.2.0
> # sensors --bus-list ads1115-i2c-2-4a
> bus "i2c-2" "i2c-1-mux (chan_id 0)"
> bus "i2c-1" "DaVinci I2C adapter"
> # sensors --no-adapter ads1115-i2c-2-4a
> ads1115-i2c-2-4a
> in4:         +1.14 V
> in5:         +1.14 V
> in6:         +1.14 V
> 
> My problem is that I'd like for the sensor utility to convert the ADC
> voltages to the original voltage which are in the range from about -10 V to
> about +10 V.
> 
> If I modify the sensor configuration as follows, it appears to work
> correctly.
> 
> root@centaur-3_0009:~# tail -2 /etc/sensors3.conf
> chip "ads1115-*"
>     compute in4 @*10-10 , (@+10)*10
> root@centaur-3_0009:~# sensors --no-adapter ads1115-i2c-2-4a
> ads1115-i2c-2-4a
> in4:         +1.41 V
> in5:         +1.14 V
> in6:         +1.14 V
> 
> Unfortunately when I adjust the values to their more accurate values, it no
> longer converts and reports the original ADC value instead.

I tried but could not reproduce the bug here. I also looked at the
source code and there is no arbitrary limit to the number of digits.

> root@centaur-3_0009:~# tail -2 /etc/sensors3.conf
> chip "ads1115-*"
>      compute in4 @*9.72340425532-9.95823902214 ,
> (@+9958.23902214)/9.72340425532

Note that you have a wrong factor in the second half here, even though
that's not related to your problem.

> root@centaur-3_0009:~# sensors --no-adapter ads1115-i2c-2-4a
> ads1115-i2c-2-4a
> in4:         +1.14 V
> in5:         +1.14 V
> in6:         +1.14 V

Well, 1.142 * 9.72340425532 - 9.95823902214 is 1.145. So I think the
value is properly scaled, just it happens that for your specific value,
the scaled value is almost the same as the original value, and that
confused you.

The limited resolution of "sensors" admittedly does not help here, try
"sensors -u" to see the 3rd digit.

-- 
Jean Delvare
http://jdelvare.nerim.net/wishlist.html

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

  parent reply	other threads:[~2014-09-02  8:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-22 22:31 [lm-sensors] How to compute a voltage that may be positive or negative Christopher Cordahi
2014-08-23 19:11 ` Guenter Roeck
2014-09-02  8:34 ` Jean Delvare [this message]
2014-09-04  2:19 ` Christopher Cordahi
2014-09-04  3:19 ` Christopher Cordahi
2014-09-04  8:08 ` Jean Delvare

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=20140902103433.2afb4971@endymion.delvare \
    --to=jdelvare@suse.de \
    --cc=lm-sensors@vger.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.