public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Osipenko <digetx@gmail.com>
To: Linus Walleij <linus.walleij@linaro.org>,
	Lars-Peter Clausen <lars@metafoo.de>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>,
	Jonathan Cameron <jic23@kernel.org>,
	"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Svyatoslav Ryhel <clamor95@gmail.com>,
	Nathan Royer <nroyer@invensense.com>,
	Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
Subject: Re: BUG: iio: mpu3050: Wrong temperature scale
Date: Thu, 22 Apr 2021 02:10:23 +0300	[thread overview]
Message-ID: <4c204f77-d560-43d3-c5d2-eced7a1124dc@gmail.com> (raw)
In-Reply-To: <CACRpkdborNeVNQEq9vf9N_CCkKqpBN-0g0FE-oJws4zTrxnXvQ@mail.gmail.com>

22.04.2021 02:02, Linus Walleij пишет:
> On Wed, Apr 21, 2021 at 10:00 PM Lars-Peter Clausen <lars@metafoo.de> wrote:
>> On 4/21/21 9:41 PM, Andy Shevchenko wrote:
>>> On Wed, Apr 21, 2021 at 10:05 PM Andy Shevchenko
>>> <andy.shevchenko@gmail.com> wrote:
>>>> On Wed, Apr 21, 2021 at 1:14 PM Linus Walleij <linus.walleij@linaro.org> wrote:
>>>>> On Tue, Apr 20, 2021 at 11:26 PM Dmitry Osipenko <digetx@gmail.com> wrote:
>>>>>
>>>>>> I found a non-kernel example
>>>>>> which uses a similar equation [1], but in a different form. The main
>>>>>> difference is that the Arduino code interprets a raw temperature value
>>>>>> as a signed integer, while upstream assumes it's unsigned.
>>>>>>
>>>>>> [1]
>>>>>> https://github.com/blaisejarrett/Arduino-Lib.MPU3050/blob/master/MPU3050lib.cpp#L111
>>>>> Oh that's nice. Room temperature as mentioned is 20 deg C
>>>>> I think?
>>>>>
>>>>> The divide by 280 part seems coherent in all examples.
>>>>>
>>>>>> Still, even if assume that the raw temperature is a signed s16 value, it
>>>>>> gives us ~35C in a result, which should be off by ~10C.
>>>> Actually here [1] it says in chapter 3.1 that room temperature is 35°C.
>>>>
>>>> Range: -30°C .. +85°C
>>>> Sensitivity: 280 LSB/°C
>>>> Room temperature offset: 35°C = -13200 LSB
>>>>
>>>> [1]: https://www.cdiweb.com/datasheets/invensense/mpu-3000a.pdf
> 
> Oh nice find!
> 
>>> So, if I'm reading this and the register description right the value
>>> is in the range
>>> -32768..32767.
>>> -13200 defines 35°C
>>>
>>> 50000 as mentioned by Dmitry is actually -15536. So, it means that the
>>> more negative a value is the higher temperature is shown.
>>>
>>> Since it's linearized scale, now we can see that
>>>
>>> (13200 -15536)/280 + 35 gives us 26.66.
>>>
>>> Does it make sense?
>> (13200 + x)/280 + 35 = (23000 + x)/280, which is what is in the driver.
>> So the only bit missing is the cast to s16.
> 
> Yup there is the bug. (I am guilty.)
> 
> Dmitry will you test & send a patch?


I'll send the patch. Thank you all for yours help!

      reply	other threads:[~2021-04-21 23:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-19  6:06 BUG: iio: mpu3050: Wrong temperature scale Dmitry Osipenko
2021-04-19 10:07 ` Linus Walleij
2021-04-20 21:26   ` Dmitry Osipenko
2021-04-21  9:54     ` Linus Walleij
2021-04-21 19:05       ` Andy Shevchenko
2021-04-21 19:41         ` Andy Shevchenko
2021-04-21 20:00           ` Lars-Peter Clausen
2021-04-21 20:02             ` Andy Shevchenko
2021-04-21 20:04               ` Andy Shevchenko
2021-04-21 20:58                 ` Dmitry Osipenko
2021-04-21 20:11             ` Andy Shevchenko
2021-04-21 23:02             ` Linus Walleij
2021-04-21 23:10               ` Dmitry Osipenko [this message]

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=4c204f77-d560-43d3-c5d2-eced7a1124dc@gmail.com \
    --to=digetx@gmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=clamor95@gmail.com \
    --cc=jic23@kernel.org \
    --cc=jmaneyrol@invensense.com \
    --cc=lars@metafoo.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nroyer@invensense.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox