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

Commit 6331d2c

Browse files
authored
Merge pull request #93 from Rocketct/master
Added setColdOffset() to MAX31855
2 parents 475746d + 018064f commit 6331d2c

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/utility/THERMOCOUPLE/MAX31855.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ const MAX31855Class::coefftable MAX31855Class::InvCoeffK[];
4141
MAX31855Class::MAX31855Class(int cs, SPIClass& spi) :
4242
_cs(cs),
4343
_spi(&spi),
44-
_spiSettings(4000000, MSBFIRST, SPI_MODE0)
44+
_spiSettings(4000000, MSBFIRST, SPI_MODE0),
45+
_coldOffset(2.10f)
4546
{
4647
}
4748

@@ -194,8 +195,7 @@ float MAX31855Class::readTemperature(int type)
194195
}
195196

196197
// convert it to degrees
197-
measuredCold = measuredColdInt/16.0f;
198-
198+
measuredCold = (measuredColdInt/16.0f);
199199
// now the tricky part... since MAX31855K is considering a linear response
200200
// and is trimemd for K thermocouples, we have to convert the reading back
201201
// to mV and then use NIST polynomial approximation to determine temperature
@@ -208,7 +208,7 @@ float MAX31855Class::readTemperature(int type)
208208
// this way we calculate the voltage we would have measured if cold junction
209209
// was at 0 degrees celsius
210210

211-
measuredVolt = coldTempTomv(type, measuredCold)+(measuredTemp-measuredCold) * 0.041276f;
211+
measuredVolt = coldTempTomv(type, measuredCold - _coldOffset)+(measuredTemp - measuredCold) * 0.041276f;
212212

213213
// finally from the cold junction compensated voltage we calculate the temperature
214214
// using NIST polynomial approximation for the thermocouple type we are using
@@ -239,4 +239,9 @@ float MAX31855Class::readReferenceTemperature(int type)
239239
return ref;
240240
}
241241

242+
void MAX31855Class::setColdOffset(float offset)
243+
{
244+
_coldOffset = offset;
245+
}
246+
242247
MAX31855Class THERM;

src/utility/THERMOCOUPLE/MAX31855.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ class MAX31855Class {
3636

3737
float readTemperature(int type = PROBE_K);
3838
float readReferenceTemperature(int type = PROBE_K);
39+
void setColdOffset(float offset);
3940

4041
private:
4142
uint32_t readSensor();
42-
43+
float _coldOffset;
4344
int _cs;
4445
SPIClass* _spi;
4546
SPISettings _spiSettings;

0 commit comments

Comments
 (0)