Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Added setColdOffset() to MAX31855 #93

Merged
merged 1 commit into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/utility/THERMOCOUPLE/MAX31855.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ const MAX31855Class::coefftable MAX31855Class::InvCoeffK[];
MAX31855Class::MAX31855Class(int cs, SPIClass& spi) :
_cs(cs),
_spi(&spi),
_spiSettings(4000000, MSBFIRST, SPI_MODE0)
_spiSettings(4000000, MSBFIRST, SPI_MODE0),
_coldOffset(2.10f)
{
}

Expand Down Expand Up @@ -194,8 +195,7 @@ float MAX31855Class::readTemperature(int type)
}

// convert it to degrees
measuredCold = measuredColdInt/16.0f;

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
Expand All @@ -208,7 +208,7 @@ float MAX31855Class::readTemperature(int type)
// this way we calculate the voltage we would have measured if cold junction
// was at 0 degrees celsius

measuredVolt = coldTempTomv(type, measuredCold)+(measuredTemp-measuredCold) * 0.041276f;
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
Expand Down Expand Up @@ -239,4 +239,9 @@ float MAX31855Class::readReferenceTemperature(int type)
return ref;
}

void MAX31855Class::setColdOffset(float offset)
{
_coldOffset = offset;
}

MAX31855Class THERM;
3 changes: 2 additions & 1 deletion src/utility/THERMOCOUPLE/MAX31855.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ class MAX31855Class {

float readTemperature(int type = PROBE_K);
float readReferenceTemperature(int type = PROBE_K);
void setColdOffset(float offset);

private:
uint32_t readSensor();

float _coldOffset;
int _cs;
SPIClass* _spi;
SPISettings _spiSettings;
Expand Down