Skip to content

Commit e221e15

Browse files
committed
Apply calibration settings to MAX31855 temps
1 parent 217281c commit e221e15

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

src/sensor.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,22 @@ void Sensor_DoConversion(void) {
101101
// Assume no CJ sensor
102102
cjsensorpresent = 0;
103103
if (tcpresent[0] && tcpresent[1]) {
104-
avgtemp = (tctemp[0] + tctemp[1]) / 2.0f;
105-
temperature[0] = tctemp[0];
106-
temperature[1] = tctemp[1];
104+
// Adjust values with calibration settings
105+
float t0 = tctemp[0] * adcgainadj[0] + adcoffsetadj[0];
106+
float t1 = tctemp[1] * adcgainadj[1] + adcoffsetadj[1];
107+
avgtemp = (t0 + t1) / 2.0f;
108+
temperature[0] = t0;
109+
temperature[1] = t1;
107110
tempvalid |= 0x03;
108111
coldjunction = (tccj[0] + tccj[1]) / 2.0f;
109112
cjsensorpresent = 1;
110113
} else if (tcpresent[2] && tcpresent[3]) {
111-
avgtemp = (tctemp[2] + tctemp[3]) / 2.0f;
112-
temperature[0] = tctemp[2];
113-
temperature[1] = tctemp[3];
114+
// Adjust values with calibration settings
115+
float t0 = tctemp[2] * adcgainadj[0] + adcoffsetadj[0];
116+
float t1 = tctemp[3] * adcgainadj[1] + adcoffsetadj[1];
117+
avgtemp = (t0 + t1) / 2.0f;
118+
temperature[0] = t0;
119+
temperature[1] = t1;
114120
tempvalid |= 0x03;
115121
tempvalid &= ~0x0C;
116122
coldjunction = (tccj[2] + tccj[3]) / 2.0f;

0 commit comments

Comments
 (0)