Hi, I have a K Type Thermocouple connected to a Arduino Portenta Machine Control and when temperature is at negative, the lcd connected does not display the exact negative value.
It only display negative value of -1 and -2 at most and does not go below that.
I am using the basic code to read temperature.
Edit: my original code is too long so I just copied paste the example but I am using exactly the same code just that the serial is changed to lcd for my application
I have tried this new library however I faced some issue with the reading of the temperature and is giving NAN everytime, I have reached out to the arduino support team and they have adviced to use the old library while waiting for new updates to the new library
float MAX31855Class::readTemperature(int type)
{
uint32_t rawword;
int32_t measuredTempInt;
int32_t measuredColdInt;
double measuredTemp;
double measuredCold;
double measuredVolt;
rawword = readSensor();
// Check for reading error
if (rawword & 0x7) {
return NAN;
}
// The cold junction temperature is stored in the last 14 word's bits
// whereas the ttermocouple temperature (non linearized) is in the topmost 18 bits
// sent by the Thermocouple-to-Digital Converter
// sign extend thermocouple value
if (rawword & 0x80000000) {
// Negative value, drop the lower 18 bits and explicitly extend sign bits.
measuredTempInt = 0xFFFC0000 | ((rawword >> 18) & 0x00003FFFF);
} else {
// Positive value, just drop the lower 18 bits.
measuredTempInt = rawword>>18;
}
// convert it to degrees
measuredTemp = measuredTempInt * 0.25f;
// sign extend cold junction temperature
measuredColdInt = (rawword>>4)&0xfff;
if (measuredColdInt&0x800) {
// Negative value, sign extend
measuredColdInt |= 0xfffff000;
}
// convert it to degrees
measuredCold = (measuredColdInt/16.0f);
// now the tricky part... since MAX31855K is considering a linear response
// and is trimemd for K thermocouples, we have to convert the reading back
// to mV and then use NIST polynomial approximation to determine temperature
// we know that reading from chip is calculated as:
// temp = chip_temperature + thermocouple_voltage/0.041276f
//
// convert temperature to mV is accomplished converting the chip temperature
// to mV using NIST polynomial and then by adding the measured voltage
// calculated inverting the function above
// this way we calculate the voltage we would have measured if cold junction
// was at 0 degrees celsius
measuredVolt = coldTempTomv(type, measuredCold - _coldOffset)+(measuredTemp - measuredCold) * 0.041276f;
// finally from the cold junction compensated voltage we calculate the temperature
// using NIST polynomial approximation for the thermocouple type we are using
return mvtoTemp(type,measuredVolt);
}
Type K thermocouples have a general temperature range of -200 to 1260°C (-326 to 2300°F), however there are some caveats to this:
If used for temperatures below 0°C special material is needed in order to meet the specified accuracies. Also, Special Limits of Error are not specified for temperatures below 0°C.
What is the Voltage of Type K Thermocouples?
The following is a selection of output values for Type K Thermocouples at selected temperatures. Note: The following output is based on a reference Junction at 0°C/32°F:
Temperature
Output
0°C
0.000 mV
100°C
4.096 mV
200°C
8.138 mV
how do you create negative temperature? industrial freezer?
rawword = rawword & 0x7FF; << here data shorted to 11 bit but
// check sign bit and convert to negative value.
if (rawword & 0x800) { << but here is asked if bit 12 is present, which shows the value is negative