[solved] CPU temperature readings wrong at cold temperatures

Having issues with your DietPi installation, or, found a bug? Post it here.
Gord_W
Posts: 134
Joined: Sat Oct 24, 2015 6:30 pm

[solved] CPU temperature readings wrong at cold temperatures

Post by Gord_W »

There is a problem with Nanopi Neo temperature readings at colder temperatures. (Currently in freezer at -18 deg. C :)

root@DietPi:~# cat /sys/class/thermal/thermal_zone0/temp
-9341

Should this be -9.3 deg. C? That would be about right.


BUT ...

root@DietPi:~# cpu

─────────────────────────────────────────────────────
DietPi CPU Info
Use dietpi-config to change CPU / performance options
─────────────────────────────────────────────────────
Architecture | armv7l
Temp | -5343'c | Who put me in the freezer! :o That is one cold freezer!!!
Governor | ondemand
Throttle up | 50% CPU usage

Current Freq Min Freq Max Freq
CPU0 | 1008 MHz 120 MHz 1008 MHz
CPU1 | 1008 MHz 120 MHz 1008 MHz
CPU2 | 1008 MHz 120 MHz 1008 MHz
CPU3 | 1008 MHz 120 MHz 1008 MHz

Gordon Williams
Last edited by Gord_W on Wed Apr 19, 2017 9:01 pm, edited 1 time in total.
User avatar
Fourdee
Site Admin
Posts: 2788
Joined: Tue Feb 06, 2007 1:36 pm

Re: CPU temperature readings wrong at cold temperatures

Post by Fourdee »

Gord_W wrote: root@DietPi:~# cat /sys/class/thermal/thermal_zone0/temp
-9341

Should this be -9.3 deg. C? That would be about right.


Gordon Williams
You actually put this in a freezer? lmao, fair play :D

We run some math on the value to reduce to 1/2 digits. We only check for positive values in the calculations (eg: > 1000), i'll change that to absolute (bash doesn't support this, so another check for <= -1000) value.
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
User avatar
Fourdee
Site Admin
Posts: 2788
Joined: Tue Feb 06, 2007 1:36 pm

Re: CPU temperature readings wrong at cold temperatures

Post by Fourdee »

Hi Gordon,

Please try this updated script with support for negative values:

Code: Select all

wget https://raw.githubusercontent.com/Fourdee/DietPi/testing/dietpi/dietpi-cpuinfo -O /DietPi/dietpi/dietpi-cpuinfo
cpu
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
Gord_W
Posts: 134
Joined: Sat Oct 24, 2015 6:30 pm

Re: CPU temperature readings wrong at cold temperatures

Post by Gord_W »

What about temperatures between -0.999 and +0.999 deg.? Would these be calculated wrong?

I will try a test.

Back soon.

Gordon
Gord_W
Posts: 134
Joined: Sat Oct 24, 2015 6:30 pm

Re: CPU temperature readings wrong at cold temperatures

Post by Gord_W »

Yup, problem with those temps.

─────────────────────────────────────────────────────
DietPi CPU Info
Use dietpi-config to change CPU / performance options
─────────────────────────────────────────────────────
Architecture | armv7l
Temp | 1'c | Who put me in the freezer!
Governor | ondemand
Throttle up | 50% CPU usage

Current Freq Min Freq Max Freq
CPU0 | 480 MHz 120 MHz 1008 MHz
CPU1 | 480 MHz 120 MHz 1008 MHz
CPU2 | 480 MHz 120 MHz 1008 MHz
CPU3 | 1008 MHz 120 MHz 1008 MHz

root@DietPi:~# cpu

─────────────────────────────────────────────────────
DietPi CPU Info
Use dietpi-config to change CPU / performance options
─────────────────────────────────────────────────────
Architecture | armv7l
Temp | Warning: 716'c | Reducing the life of your device. :lol: Ouch that is HOT!
Governor | ondemand
Throttle up | 50% CPU usage

Current Freq Min Freq Max Freq
CPU0 | 1008 MHz 120 MHz 1008 MHz
CPU1 | 1008 MHz 120 MHz 1008 MHz
CPU2 | 1008 MHz 120 MHz 1008 MHz
CPU3 | 1008 MHz 120 MHz 1008 MHz

root@DietPi:~# cpu

─────────────────────────────────────────────────────
DietPi CPU Info
Use dietpi-config to change CPU / performance options
─────────────────────────────────────────────────────
Architecture | armv7l
Temp | Warning: 594'c | Reducing the life of your device.
Governor | ondemand
Throttle up | 50% CPU usage

Current Freq Min Freq Max Freq
CPU0 | 1008 MHz 120 MHz 1008 MHz
CPU1 | 1008 MHz 120 MHz 1008 MHz
CPU2 | 1008 MHz 120 MHz 1008 MHz
CPU3 | 1008 MHz 120 MHz 1008 MHz

root@DietPi:~# cpu

..... and then ......

─────────────────────────────────────────────────────
DietPi CPU Info
Use dietpi-config to change CPU / performance options
─────────────────────────────────────────────────────
Architecture | armv7l
Temp | -739'c | Who put me in the freezer! :lol: Running HOT and COLD!
Governor | ondemand
Throttle up | 50% CPU usage

Current Freq Min Freq Max Freq
CPU0 | 624 MHz 120 MHz 1008 MHz
CPU1 | 624 MHz 120 MHz 1008 MHz
CPU2 | 624 MHz 120 MHz 1008 MHz
CPU3 | 624 MHz 120 MHz 1008 MHz


root@DietPi:~# cpu

─────────────────────────────────────────────────────
DietPi CPU Info
Use dietpi-config to change CPU / performance options
─────────────────────────────────────────────────────
Architecture | armv7l
Temp | -133'c | Who put me in the freezer!
Governor | ondemand
Throttle up | 50% CPU usage

Current Freq Min Freq Max Freq
CPU0 | 1008 MHz 120 MHz 1008 MHz
CPU1 | 1008 MHz 120 MHz 1008 MHz
CPU2 | 1008 MHz 120 MHz 1008 MHz
CPU3 | 1008 MHz 120 MHz 1008 MHz

root@DietPi:~# cpu

─────────────────────────────────────────────────────
DietPi CPU Info
Use dietpi-config to change CPU / performance options
─────────────────────────────────────────────────────
Architecture | armv7l
Temp | -2'c | Who put me in the freezer!
Governor | ondemand
Throttle up | 50% CPU usage

Current Freq Min Freq Max Freq
CPU0 | 1008 MHz 120 MHz 1008 MHz
CPU1 | 1008 MHz 120 MHz 1008 MHz
CPU2 | 1008 MHz 120 MHz 1008 MHz
CPU3 | 1008 MHz 120 MHz 1008 MHz

Gordon Williams
User avatar
Fourdee
Site Admin
Posts: 2788
Joined: Tue Feb 06, 2007 1:36 pm

Re: CPU temperature readings wrong at cold temperatures

Post by Fourdee »

Gord_W wrote:Temp | Warning: 716'c
Thanks Gordon,

Strange. Not unless the CPU thermal sensor is giving invalid values for below <10'c?

If you get another chance, lets check the raw values of a freshly frozen (unpowered) NanoPi Neo (cant believe I just said that lol). Power on, then run this command to monitor temp every 2 seconds. If it breaks the device, let me know and i'll send you a Neo 2:

Code: Select all

watch cat /sys/class/thermal/thermal_zone0/temp
If the values come back valid, i'll be able to re-check the sourcecode and run further tests (valid being 4/5 digits long, with end result temp = value / 1000).
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
Gord_W
Posts: 134
Joined: Sat Oct 24, 2015 6:30 pm

Re: CPU temperature readings wrong at cold temperatures

Post by Gord_W »

No, there is no problem with the sensor. Just your math. :o

As I noted above the problem is -1 deg< temp< + 1 deg.

for example:

+.5 deg the sensor shows 500

You test for numbers between < -1000 and > +1000. Because 500 sensor reading doesn't meet the test, it doesn't get divided by 1000 like it should.

You need to refine your algorithm to decide what is a 2 digit temperature and a 4 digit temperature.

You could do this on a cpu basis.

A hack would be to test between -100 and 100. Therefore the errors would only occur between -0.09 and +0.09 degrees.
Gordon Williams
User avatar
Fourdee
Site Admin
Posts: 2788
Joined: Tue Feb 06, 2007 1:36 pm

Re: CPU temperature readings wrong at cold temperatures

Post by Fourdee »

Gord_W wrote:Just your math.
You test for numbers between < -1000 and > +1000. Because 500 sensor reading doesn't meet the test, it doesn't get divided by 1000 like it should.
You need to refine your algorithm to decide what is a 2 digit temperature and a 4 digit temperature.
Hi Gordon,

Yep spot on, not been doing much "real" programming lately (compiles, software additions, forum spammers), so my math is a little "off" lol :)
A hack would be to test between -100 and 100 Therefore the errors would only occur between -0.09 and +0.09 degrees.
Good solution, although relies on CPU temps not exceeding 100'c (looks at XU4). Another option is to provide two possible values from a 2/3 digit result?

Another solution is to find and pre-define which boards/results are 4/5 digits (NanoPi Neo), instead of 2 (pine). We could do that one pretty easy with $HW_MODEL index's, we just need to find which boards (including NR_ 4.x images that may be a switch of 3.x) have those figures.

All because the lady (Man) loves Cadburys milk tray (Freezers) :D lol
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
User avatar
Fourdee
Site Admin
Posts: 2788
Joined: Tue Feb 06, 2007 1:36 pm

Re: CPU temperature readings wrong at cold temperatures

Post by Fourdee »

Gordon,

SBC in a freezer? made my day :):
https://twitter.com/DietPi_/status/852588259779784704
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
Gord_W
Posts: 134
Joined: Sat Oct 24, 2015 6:30 pm

Re: CPU temperature readings wrong at cold temperatures

Post by Gord_W »

You've forgotten but we've discussed the freezer before :lol:
http://dietpi.com/phpbb/viewtopic.php?f ... r&start=10
But that was for rPi. Now trying out smaller NanoPi to test clock stability.

We could do that one pretty easy with $HW_MODEL index's
That would be the preferred way.

Thanks,
Gordon
Post Reply