Skip to content

Commit aaa8ec4

Browse files
committed
Preparation for multi probe setups and shared implementation for temperature probes (RTD and TC)
1 parent 07b3f95 commit aaa8ec4

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

src/utility/THERMOCOUPLE/MAX31855.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,48 +85,48 @@ double MAX31855Class::polynomial(double value, int tableEntries, coefftable cons
8585
return NAN;
8686
}
8787

88-
double MAX31855Class::coldTempTomv(int type, double temp) {
88+
double MAX31855Class::coldTempTomv(double temp) {
8989
coefftable const (*table);
9090
int tableEntries;
9191
double voltage;
9292

93-
switch (type) {
94-
case PROBE_J:
93+
switch (_current_probe_type) {
94+
case PROBE_TC_J:
9595
table = CoeffJ;
9696
tableEntries = sizeof(CoeffJ) / sizeof(coefftable);
97-
break;
98-
case PROBE_K:
97+
break;
98+
case PROBE_TC_K:
9999
table = CoeffK;
100100
tableEntries = sizeof(CoeffK) / sizeof(coefftable);
101101
break;
102102
}
103103
voltage = polynomial(temp, tableEntries, table);
104104
// special case... for K probes in temperature range 0-1372 we need
105105
// to add an extra term
106-
if (type == PROBE_K && temp > 0) {
106+
if (_current_probe_type == PROBE_TC_K && temp>0) {
107107
voltage += 0.118597600000E+00 * exp(-0.118343200000E-03 * pow(temp - 0.126968600000E+03, 2));
108108
}
109109
return voltage;
110110
}
111111

112-
double MAX31855Class::mvtoTemp(int type, double voltage) {
112+
double MAX31855Class::mvtoTemp(double voltage) {
113113
coefftable const (*table);
114114
int tableEntries;
115115

116-
switch (type) {
117-
case PROBE_J:
116+
switch (_current_probe_type) {
117+
case PROBE_TC_J:
118118
table = InvCoeffJ;
119119
tableEntries = sizeof(InvCoeffJ) / sizeof(coefftable);
120120
break;
121-
case PROBE_K:
121+
case PROBE_TC_K:
122122
table = InvCoeffK;
123123
tableEntries = sizeof(InvCoeffJ) / sizeof(coefftable);
124124
break;
125125
}
126126
return polynomial(voltage, tableEntries, table);
127127
}
128128

129-
float MAX31855Class::readTemperature(int type) {
129+
float MAX31855Class::readTCTemperature() {
130130
uint32_t rawword;
131131
int32_t measuredTempInt;
132132
int32_t measuredColdInt;
@@ -177,14 +177,15 @@ float MAX31855Class::readTemperature(int type) {
177177
// this way we calculate the voltage we would have measured if cold junction
178178
// was at 0 degrees celsius
179179

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

182182
// finally from the cold junction compensated voltage we calculate the temperature
183183
// using NIST polynomial approximation for the thermocouple type we are using
184-
return mvtoTemp(type, measuredVolt);
184+
return mvtoTemp(measuredVolt);
185185
}
186186

187-
float MAX31855Class::readReferenceTemperature(int type) {
187+
float MAX31855Class::readReferenceTemperature() {
188+
//TODO. Actually use TC _current_probe_type and _coldOffset
188189
uint32_t rawword;
189190
float ref;
190191

@@ -211,3 +212,7 @@ void MAX31855Class::setColdOffset(float offset) {
211212
_coldOffset = offset;
212213
}
213214

215+
216+
void MAX31855Class::setTCType(uint8_t type) {
217+
_current_probe_type = type;
218+
}

src/utility/THERMOCOUPLE/MAX31855.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
#include <SPI.h>
77
#include "pins_mc.h"
88

9-
#define PROBE_K 0
10-
#define PROBE_J 1
9+
#define PROBE_TC_K 0
10+
#define PROBE_TC_J 1
11+
12+
#define PROBE_K PROBE_TC_K
13+
#define PROBE_J PROBE_TC_J
1114

1215
class MAX31855Class {
1316
public:
@@ -16,13 +19,15 @@ class MAX31855Class {
1619
bool begin();
1720
void end();
1821

19-
float readTemperature(int type = PROBE_K);
20-
float readReferenceTemperature(int type = PROBE_K);
22+
float readTCTemperature();
23+
float readReferenceTemperature();
2124
void setColdOffset(float offset);
25+
void setTCType(uint8_t type);
2226

2327
private:
2428
uint32_t readSensor();
2529
float _coldOffset;
30+
uint8_t _current_probe_type;
2631
PinName _cs;
2732
SPIClass* _spi;
2833
SPISettings _spiSettings;
@@ -74,10 +79,10 @@ class MAX31855Class {
7479
{sizeof(InvK500_1372) / sizeof(double), 54.886f, &InvK500_1372[0]},
7580
};
7681

77-
double mvtoTemp(int type, double voltage);
78-
double coldTempTomv(int type, double temp);
82+
double mvtoTemp(double voltage);
83+
double coldTempTomv(double temp);
7984
double polynomial(double value, int tableEntries, coefftable const (*table));
80-
};
8185

86+
};
8287

8388
#endif

0 commit comments

Comments
 (0)