Question on MAX31855 code

Breakout boards, sensors, Drawdio, Game of Life, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Question on MAX31855 code

Postby fwfreak » Tue Jan 01, 2013 2:19 pm

I am using one of the MAX31855 breakout boards on a oven controller I'm building and went to the github site for the Adafruit code. I found a number of issues with the existing code, to the point that I rewrote it and posted the revised code on my website: http://www.seanet.com/~karllunt/max31855.html

Note that my code is C, not C++. If you are heavily into Arduino, this is going to look very different from the sketches you're used to.

One question I had with the code is it doesn't appear to handle negative thermocouple values correctly in gcc-avr. It does seem to handle negative reference values properly, but that doesn't help you with the thermocouple.

Specifically, this code in Adafruit_MAX31855::readCelsius(void) seems wrong:
==========================
// get rid of internal temp data, and any fault bits
v >>= 18; <-- this does not sign-extend in the gcc-avr compiler
//Serial.println(v, HEX);

// pull the bottom 13 bits off <-- actually, the bottom 13 bits plus 1 sign bit
int16_t temp = v & 0x3FFF;

// check sign bit
if (v & 0x2000)
temp |= 0xC000;
//Serial.println(temp);

double centigrade = v; <-- again, sign is not extended (in gcc-avr) so centigrade is always positive

// LSB = 0.25 degrees C
centigrade *= 0.25;
return centigrade;
==============================

Notice that the true sign bit of the data value is tested and recorded in temp but is never subsequently used.

There is a println() immediately after the right-shift of v, so this code was tested under at least some conditions; was it tested with negative temperature values generated by the device? Does the Arduino compiler do sign-extension on right-shift? (I don't use that toolset so can't test.)

fwfreak
fwfreak
 
Posts: 1
Joined: Tue Jan 01, 2013 1:32 pm

Re: Question on MAX31855 code

Postby adafruit_support_bill » Wed Jan 02, 2013 6:51 am

Thanks for the analysis. Can you post this as an issue to Github? That will make sure it gets on our schedule of fixes.
User avatar
adafruit_support_bill
 
Posts: 16078
Joined: Sat Feb 07, 2009 9:11 am


Return to Other Adafruit products

Who is online

Users browsing this forum: No registered users and 6 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [108]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[31]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[34]
LCDs & Displays[48]
Components & Parts[70]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[111]
 
Wireless[14]
Cables[62]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]