ControlConnection/MAX31855 — Issue #2: sign problem
Author: yvest
Created: 2012-01-26 03:58:07+00:00
State: open

There is an important issue with the current code. The MAX31855 is sending signed values

In MAX31855::readMAX31855, 'd' and 'v' needs to be declared as integers.

I added some print in MAX31855::readMAX31855 that outputs the value of v and d (in binary) and here's what the output looks like with the existing code when the temperature goes below 0 (I'm using celcius)

V = 101100111, D = 1010
2.50	22.44	000
V = 101100111, D = 1010
2.50	22.44	000
V = 101100111, D = 100
1.00	22.44	000
V = 101100111, D = 11111111111111111111111111111011
4094.75	22.44	000
V = 101100110, D = 11111111111111111111111111110111
4093.75	22.37	000

As you can see the MAX31855 returns a signed value. D15 being set indicate that it's a negative value, but because d is declared as a long, the first 16 MSB are still set to 0 and the compiler see that the value is a negative.

with d and v declared as integers:

7.5000	22.37	000
V = 101100110, D = 11100
7.0000	22.37	000
V = 101100111, D = 11111111111111111111111111111100
-1.0000	22.44	000
V = 101100110, D = 11111111111111111111111111111001
-1.7500	22.37	000

I haven't had the time to do a fork and submit a pull that correct this issue in all of the functions, yet.