Skip to content

Library code appears to process negative thermocouple values incorrectly #3

fwfreak opened this Issue Jan 3, 2013 · 1 comment

2 participants

fwfreak commented Jan 3, 2013

I posted a comment in the Adafruit forum on sensors regarding issues with the MAX31855 library code. The routine that reads the thermocouple value (not the internal value) does not properly convert negative values. The issue lies with the use of >> for negative numbers. Sign-extension by >> is compiler specific. The gcc-avr compiler, which I use, does NOT sign extend. I don't know if the Arduino compiler does.

Regardless, the sign bit is tested and only recorded in the variable temp, which is then not used again. The conversion of v (int) to centigrade (double) does not include sign info if >> does not sign-extend.

I have written my own version of these routines in ANSI C for use with the gcc-avr compiler. You can find them at: Please feel free to add them to github if you think that is appropriate.

Karl Lunt

@tdicola tdicola closed this in 0b62e16 Aug 8, 2014
tdicola commented Aug 8, 2014

Thanks for raising the issue and apologies it wasn't reviewed earlier. I just submitted a fix that explicitly extends the sign bit for negative values so it should handle this case a little better. Thanks again for raising the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.