sekdiy / CoreSensors

An interface to the Arduino's internal temperature (diode reference) and supply voltage (bandgap reference).
MIT License
5 stars 1 forks source link

DegC value multiplied x4? #4

Closed isync closed 5 years ago

isync commented 5 years ago

On an Arduino Nano clone, I get readings in the 80 degrees celcius area while the board is on room temperature. I know that the internal chip temp is measured, thus it's quite inaccurate when the board is running, but still....

I read the ATMega has an internal temperature protection that kicks in @ ~ 80. So the values seems off.

And other chips, for example the DS3231 RTC, produces temperature readings multiplied by 4 (compare this blog post. Could this be the case here?

sekdiy commented 5 years ago

I've had a look at the linked article, it's a description of Jack Christensen's well known DS3232RTC library. That one is different from Atmel controllers in Arduinos, although I haven't checked its temperature sensor behaviour.

Did you try the simple example from this library?

What does it say for Fahrenheit while reading 80 degrees Celsius?

Also, what microcontroller exactly are you using to test this?

isync commented 5 years ago

Yes, I'm running the example right now. On a Nano V3.0 by HIMALAYA (ATMega 328P). Example serial output snippet:

18:17:25.531 -> 72.85 degC, 163.13 degF, 4.83 V 18:17:26.625 -> 72.85 degC, 163.13 degF, 4.88 V 18:17:27.720 -> 73.85 degC, 164.93 degF, 4.86 V 18:17:28.786 -> 73.85 degC, 164.93 degF, 4.79 V

when I put my finger on the ATMega chip, it slowly rises (I omitted some samples below, for brevity, see timestamps):

18:19:43.095 -> 73.85 degC, 164.93 degF, 4.90 V 18:19:44.156 -> 74.85 degC, 166.73 degF, 4.90 V 18:20:02.747 -> 75.85 degC, 168.53 degF, 4.88 V 18:20:03.841 -> 74.85 degC, 166.73 degF, 4.88 V 18:20:09.275 -> 75.85 degC, 168.53 degF, 4.83 V 18:20:10.369 -> 75.85 degC, 168.53 degF, 4.88 V 18:20:22.397 -> 76.85 degC, 170.33 degF, 4.88 V 18:20:23.491 -> 75.85 degC, 168.53 degF, 4.79 V 18:20:24.584 -> 76.85 degC, 170.33 degF, 4.79 V 18:20:25.645 -> 75.85 degC, 168.53 degF, 4.90 V 18:20:26.771 -> 75.85 degC, 168.53 degF, 4.92 V 18:20:27.865 -> 75.85 degC, 168.53 degF, 4.90 V 18:20:28.925 -> 76.85 degC, 170.33 degF, 4.90 V 18:20:30.019 -> 76.85 degC, 170.33 degF, 4.81 V 18:20:31.112 -> 76.85 degC, 170.33 degF, 4.83 V

and then goes back once I lift the finger off.

The following samples are from a no-name 3.3V Arduino Pro Mini clone with an ATMega168 (no P, no A, no PA) and 8Mhz clock speed.

18:28:06.565 -> 80.85 degC, 177.53 degF, 3.49 V 18:28:07.658 -> 81.85 degC, 179.33 degF, 3.50 V 18:28:08.751 -> 81.85 degC, 179.33 degF, 3.50 V 18:28:09.844 -> 81.85 degC, 179.33 degF, 3.50 V 18:28:10.938 -> 82.85 degC, 181.13 degF, 3.50 V 18:28:12.032 -> 82.85 degC, 181.13 degF, 3.51 V 18:28:13.125 -> 82.85 degC, 181.13 degF, 3.51 V 18:28:14.218 -> 81.85 degC, 179.33 degF, 3.50 V

So, it still looks like a factor of 4. Room temperature is about 20 DegC.

sekdiy commented 5 years ago

Okay, thanks for the data.

You mention the HIMALAYA Nano, so I'm assuming those are legit Atmel chips, correct?

From the fact that the measured voltage is off by as much as 6%, I can tell that you run the measurements uncalibrated (as is default behaviour in the library and the minimal example).

Did you try calibrating the unit, i.e. as mentioned in https://github.com/sekdiy/CoreSensors#calibration ?

I'll set up a test unit and report back, maybe it's a bug that creeped into the code somehow. ;)

isync commented 5 years ago

Dunno how legit these HIMALAYAs are, AFAIK these Arduino clones can be built on knock-off PCBs but they still employ genuine Atmel 328 chips, at least I've read it on the package a few times. No, I haven't calibrated the units. Actually I was already proud of myself of investing time to produce above data, but to be honest I'd like to put this issue to rest as I haven't got the time to investigate it further. Sorry. Feel free to do the same. Let's wait until someone else stumbles over this issue and contributes additional data or knowledge. Thank you for the effort and your code! Runs in multiple of my projects (for voltage).

sekdiy commented 5 years ago

I've fixed a bug and made some other changes.

No, I haven't calibrated the units.

This just might be the explanation.

I've had a chance to revisit this issue and do some tests with a small assortment of (ATMega) devices.

Then it dawned on me that your temperatures in the 75°C to 85°C range perfectly align with something I measured during development.

So the error might not actually be multiplied x4, but rather offset by 50K+ or so...

Since this value seems to be specific to all 328P, I've applied this permanent offset to the library. So you shouldn't have to deal with it any more.

Actually I was already proud of myself of investing time to produce above data

You did good! :)

I haven't got the time to investigate

Should you still feel like testing some more, please feel free to give the updated library and examples another go.

I've updated the library to better reflect the difference between the ATMega models (and found a bug with the ATMega32U4 along the way!).

My recent tests showed that all (four) devices under test measured within +/-10 °C (as specified by Atmel) while most (three) measured well within +/-3 °C (before calibration).

Thank you for the effort and your code!

Thanks for the feedback, always appreciated.

isync commented 5 years ago

Cool. Cool. Cool. Next time I pick up one of my Arduino projects, I'll update the lib and check out the changes. Thanks again for your invested work in this lib! (I hope it's ok to declare this issue "closed")