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

Commit

Permalink
Merge pull request #93 from Rocketct/master
Browse files Browse the repository at this point in the history
Added setColdOffset() to MAX31855
  • Loading branch information
pnndra authored Jul 7, 2022
2 parents 475746d + 018064f commit 6331d2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
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

0 comments on commit 6331d2c

Please sign in to comment.