Refactor Temperature code, pulling the circuits out of the PT100 and Thermistor

This commit is contained in:
Rob Giseburt
2017-08-14 15:50:27 -05:00
parent f4e7beccbf
commit e9328503e8
4 changed files with 182 additions and 151 deletions

View File

@@ -67,10 +67,15 @@ struct MAX31865 final {
// Timer to keep track of when we need to do another periodic update
Motate::Timeout _check_timer;
// The resulting value is relative to the pullup resistance
// To return the correct resistance, we need the pullup value
float _pullup_resistance;
// Constructor - this is the only time we directly use the SBIBus
template <typename SPIBus_t, typename chipSelect_t>
MAX31865(SPIBus_t &spi_bus,
const chipSelect_t &_cs,
float pullup_resistance = 430, // 430 is the value used on the Adafruit breakout
bool is_three_pin = false,
bool fifty_hz = true
)
@@ -81,15 +86,18 @@ struct MAX31865 final {
400, // min_between_cs_delay_ns
400, // cs_to_sck_delay_ns
80 // between_word_delay_ns
)}
)},
_pullup_resistance{pullup_resistance}
{
init(is_three_pin, fifty_hz);
};
template <typename SPIBus_t, typename chipSelect_t>
MAX31865(std::function<void(void)> &&_interrupt,
MAX31865(const Motate::PinOptions_t options, // completely ignored, but for compatibility with ADCPin
std::function<void(void)> &&_interrupt,
SPIBus_t &spi_bus,
const chipSelect_t &_cs,
float pullup_resistance = 430, // 430 is the value used on the Adafruit breakout
bool is_three_pin = false,
bool fifty_hz = true
)
@@ -101,6 +109,7 @@ struct MAX31865 final {
400, // cs_to_sck_delay_ns
80 // between_word_delay_ns
)},
_pullup_resistance{pullup_resistance},
_interrupt_handler{std::move(_interrupt)}
{
init(is_three_pin, fifty_hz);
@@ -175,12 +184,12 @@ struct MAX31865 final {
uint8_t high;
uint8_t low;
} _rtd_value_raw;
float _rtd_value = -1;
int32_t _rtd_value = -1;
bool _rtd_value_needs_read = false;
void _postReadRTD() {
bool fault_detected = _rtd_value_raw.low & 0x01;
uint16_t rtd_value_int = (_rtd_value_raw.high << 7) | (_rtd_value_raw.low >> 1);
_rtd_value = (float)rtd_value_int / 32768.0;
_rtd_value = rtd_value_int;
if (fault_detected) {
_fault_status_needs_read = true;
}
@@ -387,13 +396,16 @@ struct MAX31865 final {
}
};
// getRaw is to return the last sampled value
int32_t getRaw() {
uint16_t rtd_value_int = (_rtd_value_raw.high << 7) | (_rtd_value_raw.low >> 1);
return rtd_value_int;
};
int32_t getValue() {
return _rtd_value;
};
// getValue is supposed to request a new value, block, and then return the result
// PUNT - return the same as getRaw()
int32_t getValue() {
return getRaw();
};
int32_t getBottom() {
return 0;
};
@@ -414,23 +426,10 @@ struct MAX31865 final {
{
_vref = vref;
// uint16_t min_expected_int = (uint16_t)((min_expected/vref) * 32767.0) << 1;
// fault_low.high = (min_expected_int >> 8) & 0xff;
// fault_low.low = min_expected_int & 0xff;
// fault_low_needs_written = true;
//
// if (max_expected > 0) {
// uint16_t max_expected_int = (uint16_t)((max_expected/vref) * 32767.0) << 1;
// fault_high.high = (max_expected_int >> 8) & 0xff;
// fault_high.low = max_expected_int & 0xff;
// fault_high_needs_written = true;
// }
// differential should always be false
// we can't control the resolution, so ignore ideal_steps too
// All of the rest are ignored, but here for compatibility of interface
};
float getVoltage() {
return _rtd_value * _vref;
return ((getRaw()*_pullup_resistance)/32768.0) * _vref;
};
operator float() { return getVoltage(); };

View File

@@ -307,37 +307,42 @@
//** Temperature Sensors **
//#include "device/max31865/max31865.h"
#include "device/max31865/max31865.h"
//#define USING_A_MAX31865 1
#define USING_A_MAX31865 1
#define HAS_TEMPERATURE_SENSOR_1 true
#if HAS_TEMPERATURE_SENSOR_1
// Must choose Thermistor or PT100
#if 1 // 1 if a Thermistor, 0 if a PT100
#define TEMPERATURE_SENSOR_1_TYPE Thermistor<ADCDifferentialPair<kADC1_Neg_PinNumber, kADC1_Pos_PinNumber>>
// #define TEMPERATURE_SENSOR_1_CIRCUIT_TYPE ADCCircuitSimplePullup
// #define TEMPERATURE_SENSOR_1_CIRCUIT_INIT { /*pullup_resistance:*/ 4700 }
// #define TEMPERATURE_SENSOR_1_TYPE Thermistor<kADC1_PinNumber>
// #define TEMPERATURE_SENSOR_1_INIT { \
// /*T1:*/ 20.0, /*T2:*/ 190.0, /*T3:*/ 255.0, \
// /*R1:*/ 144700.0, /*R2:*/ 5190.0, /*R3:*/ 4809.0, &temperature_sensor_1_circuit \
// }
#define TEMPERATURE_SENSOR_1_CIRCUIT_TYPE ADCCircuitRawResistance
#define TEMPERATURE_SENSOR_1_CIRCUIT_INIT { }
#define TEMPERATURE_SENSOR_1_TYPE Thermistor<MAX31865<SPIBus_used_t::SPIBusDevice>>
#define TEMPERATURE_SENSOR_1_INIT { \
/*T1:*/ 25.0, /*T2:*/ 190.0, /*T3:*/ 255.0, \
/*R1:*/ 99500.0, /*R2:*/ 5190.0, /*R3:*/ 4809.0, /*pullup_resistance:*/ 200 \
/*T1:*/ 20.0, /*T2:*/ 190.0, /*T3:*/ 255.0, \
/*R1:*/ 99500.0, /*R2:*/ 5190.0, /*R3:*/ 4809.0, /*pullup_resistance:*/ 10500.0 \
/*MAX31865 config*/ spiBus, spiCSPinMux.getCS(5), 150000 \
}
#else
// #define TEMPERATURE_SENSOR_1_TYPE PT100<ADCDifferentialPair<kADC1_Neg_PinNumber, kADC1_Pos_PinNumber>>
// #define TEMPERATURE_SENSOR_1_INIT {/*pullup_resistance:*/ 2000, /*inline_resistance*/0.0}
#define TEMPERATURE_SENSOR_1_TYPE PT100<MAX31865<SPIBus_used_t::SPIBusDevice>>
#define TEMPERATURE_SENSOR_1_INIT {/*pullup_resistance:*/ 430, /*inline_resistance*/0, spiBus, spiCSPinMux.getCS(5)}
#endif // 0 or 1
#endif // HAS_TEMPERATURE_SENSOR_1
#define EXTRUDER_1_OUTPUT_PIN kHeaterOutput1_PinNumber
#define EXTRUDER_1_FAN_PIN kOutput5_PinNumber
#define HAS_TEMPERATURE_SENSOR_2 false
#if HAS_TEMPERATURE_SENSOR_2
#if 1 // 1 if a Thermistor, 0 if a PT100
#define TEMPERATURE_SENSOR_2_TYPE Thermistor<ADCDifferentialPair<kADC2_Neg_PinNumber, kADC2_Pos_PinNumber>>
#define TEMPERATURE_SENSOR_2_INIT { \
/*T1:*/ 25.0, /*T2:*/ 190.0, /*T3:*/ 255.0, \
/*R1:*/ 99500.0, /*R2:*/ 5190.0, /*R3:*/ 4809.0, /*pullup_resistance:*/ 200 \
/*R1:*/ 99500.0, /*R2:*/ 5190.0, /*R3:*/ 4809.0, /*pullup_resistance:*/ 10500.0 \
}
#else
#define TEMPERATURE_SENSOR_2_TYPE PT100<ADCDifferentialPair<kADC2_Neg_PinNumber, kADC2_Pos_PinNumber>>
@@ -349,13 +354,14 @@
#define EXTRUDER_2_OUTPUT_PIN kHeaterOutput2_PinNumber
#define HAS_TEMPERATURE_SENSOR_3 true
#define HAS_TEMPERATURE_SENSOR_3 false
#if HAS_TEMPERATURE_SENSOR_3
#if 1 // 1 if a Thermistor, 0 if a PT100
#define TEMPERATURE_SENSOR_3_TYPE Thermistor<ADCDifferentialPair<kADC2_Neg_PinNumber, kADC2_Pos_PinNumber>>
#define TEMPERATURE_SENSOR_3_INIT { \
/*T1:*/ 20.0, /*T2:*/ 190.0, /*T3:*/ 255.0, \
/*R1:*/ 100000.0, /*R2:*/ 5190.0, /*R3:*/ 4809.0, /*pullup_resistance:*/ 200 \
/*R1:*/ 99500.0, /*R2:*/ 5190.0, /*R3:*/ 4809.0, /*pullup_resistance:*/ 10500.0 \
}
#else
// #define TEMPERATURE_SENSOR_3_TYPE PT100<ADCDifferentialPair<kADC3_Neg_PinNumber, kADC3_Pos_PinNumber>>

View File

@@ -135,7 +135,7 @@
#define M1_TMC2130_HEND 0 // 1hend
#define M1_TMC2130_HSTRT 0 // 1hsrt
#define M1_TMC2130_SMIN 5 // 1smin
#define M1_TMC2130_SMAX 5 // 1smax
#define M1_TMC2130_SMAX 5 // 1smax
#define M1_TMC2130_SUP 2 // 1sup
#define M1_TMC2130_SDN 1 // 1sdn
@@ -375,19 +375,15 @@ M100.1 ({{ajh:144000.0}})
#define HAS_TEMPERATURE_SENSOR_1 true
#if HAS_TEMPERATURE_SENSOR_1
// Must choose Thermistor or PT100
#if 0 // 1 if a Thermistor, 0 if a PT100
#define TEMPERATURE_SENSOR_1_TYPE Thermistor<kADC1_PinNumber>
#define TEMPERATURE_SENSOR_1_INIT { \
/*T1:*/ 20.0, /*T2:*/ 190.0, /*T3:*/ 255.0, \
/*R1:*/ 144700.0, /*R2:*/ 5190.0, /*R3:*/ 4809.0, /*pullup_resistance:*/ 4700 \
}
#else
// #define TEMPERATURE_SENSOR_1_CIRCUIT_TYPE ADCCircuitDifferentialPullup
// #define TEMPERATURE_SENSOR_1_CIRCUIT_INIT { /*pullup_resistance:*/ 4700 }
// #define TEMPERATURE_SENSOR_1_TYPE PT100<ADCDifferentialPair<kADC1_Neg_PinNumber, kADC1_Pos_PinNumber>>
// #define TEMPERATURE_SENSOR_1_INIT {/*pullup_resistance:*/ 2000, /*inline_resistance*/0.0}
#define TEMPERATURE_SENSOR_1_TYPE PT100<MAX31865<SPIBus_used_t::SPIBusDevice>>
#define TEMPERATURE_SENSOR_1_INIT {/*pullup_resistance:*/ 430, /*inline_resistance*/0, spiBus, spiCSPinMux.getCS(5)}
#endif // 0 or 1
// #define TEMPERATURE_SENSOR_1_INIT {/*pullup_resistance:*/ 2000, /*inline_resistance*/ 0.0, &temperature_sensor_1_circuit}
#define TEMPERATURE_SENSOR_1_CIRCUIT_TYPE ADCCircuitRawResistance
#define TEMPERATURE_SENSOR_1_CIRCUIT_INIT { /*pullup_resistance:*/ 430 }
#define TEMPERATURE_SENSOR_1_TYPE PT100<MAX31865<SPIBus_used_t::SPIBusDevice>>
#define TEMPERATURE_SENSOR_1_INIT {&temperature_sensor_1_circuit, spiBus, spiCSPinMux.getCS(5)}
#endif // HAS_TEMPERATURE_SENSOR_1
#define EXTRUDER_1_OUTPUT_PIN kHeaterOutput1_PinNumber
@@ -395,37 +391,27 @@ M100.1 ({{ajh:144000.0}})
#define HAS_TEMPERATURE_SENSOR_2 false
#if HAS_TEMPERATURE_SENSOR_2
#if 0 // 1 if a Thermistor, 0 if a PT100
#define TEMPERATURE_SENSOR_2_TYPE Thermistor<kADC3_PinNumber>
#define TEMPERATURE_SENSOR_2_INIT { \
/*T1:*/ 20.0, /*T2:*/ 190.0, /*T3:*/ 255.0, \
/*R1:*/ 144700.0, /*R2:*/ 5190.0, /*R3:*/ 4809.0, /*pullup_resistance:*/ 4700 \
}
#else
#define TEMPERATURE_SENSOR_2_CIRCUIT_TYPE ADCCircuitDifferentialPullup
#define TEMPERATURE_SENSOR_2_CIRCUIT_INIT { /*pullup_resistance:*/ 200 }
#define TEMPERATURE_SENSOR_2_TYPE PT100<ADCDifferentialPair<kADC2_Neg_PinNumber, kADC2_Pos_PinNumber>>
#define TEMPERATURE_SENSOR_2_INIT {/*pullup_resistance:*/ 200, /*inline_resistance*/0.0}
// #define TEMPERATURE_SENSOR_2_TYPE PT100<MAX31865<SPIBus_used_t::SPIBusDevice>>
// #define TEMPERATURE_SENSOR_2_INIT {/*pullup_resistance:*/ 430, /*inline_resistance*/0, spiBus, spiCSPinMux.getCS(5)}
#endif // 0 or 1
#define TEMPERATURE_SENSOR_2_INIT {&temperature_sensor_2_circuit}
// #define TEMPERATURE_SENSOR_2_CIRCUIT_TYPE ADCCircuitRawResistance
// #define TEMPERATURE_SENSOR_2_CIRCUIT_INIT { /*pullup_resistance:*/ 430 }
// #define TEMPERATURE_SENSOR_2_TYPE PT100<MAX31865<SPIBus_used_t::SPIBusDevice>>
// #define TEMPERATURE_SENSOR_2_INIT {/*pullup_resistance:*/ 430, /*inline_resistance*/0, spiBus, spiCSPinMux.getCS(5)}
#endif // HAS_TEMPERATURE_SENSOR_2
#define EXTRUDER_2_OUTPUT_PIN kHeaterOutput2_PinNumber
#define HAS_TEMPERATURE_SENSOR_3 true
#if HAS_TEMPERATURE_SENSOR_3
#if 0 // 1 if a Thermistor, 0 if a PT100
#define TEMPERATURE_SENSOR_3_TYPE Thermistor<kADC2_PinNumber>
#define TEMPERATURE_SENSOR_3_INIT { \
/*T1:*/ 20.0, /*T2:*/ 190.0, /*T3:*/ 255.0, \
/*R1:*/ 144700.0, /*R2:*/ 5190.0, /*R3:*/ 4809.0, /*pullup_resistance:*/ 4700 \
}
#else
// #define TEMPERATURE_SENSOR_3_TYPE PT100<ADCDifferentialPair<kADC2_Neg_PinNumber, kADC2_Pos_PinNumber>>
// #define TEMPERATURE_SENSOR_3_INIT {/*pullup_resistance:*/ 200, /*inline_resistance*/0.0}
#define TEMPERATURE_SENSOR_3_TYPE PT100<MAX31865<SPIBus_used_t::SPIBusDevice>>
#define TEMPERATURE_SENSOR_3_INIT {/*pullup_resistance:*/ 430, /*inline_resistance*/0, spiBus, spiCSPinMux.getCS(6)}
#endif // 0 or 1
#define TEMPERATURE_SENSOR_3_CIRCUIT_TYPE ADCCircuitRawResistance
#define TEMPERATURE_SENSOR_3_CIRCUIT_INIT { /*pullup_resistance:*/ 430 }
#define TEMPERATURE_SENSOR_3_TYPE PT100<MAX31865<SPIBus_used_t::SPIBusDevice>>
#define TEMPERATURE_SENSOR_3_INIT {&temperature_sensor_3_circuit, spiBus, spiCSPinMux.getCS(6)}
#endif // HAS_TEMPERATURE_SENSOR_3
#define BED_OUTPUT_PIN kHeaterOutput11_PinNumber

View File

@@ -225,12 +225,66 @@ struct ValueHistory {
};
struct ADCCircuit
{
virtual float get_resistance(const float voltage) const;
virtual float get_voltage(const float resistance) const;
};
struct ADCCircuitSimplePullup : ADCCircuit
{
const float _pullup_resistance;
ADCCircuitSimplePullup(const float pullup_resistance) : _pullup_resistance{pullup_resistance} {};
float get_resistance(const float v) const override
{
return ((_pullup_resistance * v) / (kSystemVoltage - v));
};
float get_voltage(const float r) const override
{
return r/(r+_pullup_resistance)*kSystemVoltage;
};
};
struct ADCCircuitDifferentialPullup : ADCCircuit
{
const float _pullup_resistance;
ADCCircuitDifferentialPullup(const float pullup_resistance) : _pullup_resistance{pullup_resistance} {};
float get_resistance(float v) const override
{
float v2 = v / kSystemVoltage;
return (v2 * 2.0 * _pullup_resistance)/(1.0 - v2);
};
float get_voltage(const float r) const override
{
return (kSystemVoltage * r)/(2.0 * _pullup_resistance + r);
};
};
struct ADCCircuitRawResistance : ADCCircuit
{
const float _vref;
ADCCircuitRawResistance(const float vref = kSystemVoltage) : _vref{vref} {};
float get_resistance(float v) const override
{
return v/_vref;
};
float get_voltage(const float r) const override
{
return r*_vref;
};
};
template<typename ADC_t, uint16_t min_temp = 0, uint16_t max_temp = 300>
struct Thermistor {
const bool differential;
float c1, c2, c3, pullup_resistance;
// We'll pull adc top value from the adc_pin.getTop()
float c1, c2, c3;
const ADCCircuit *circuit;
ADC_t adc_pin;
uint16_t raw_adc_value = 0;
@@ -245,22 +299,22 @@ struct Thermistor {
// http://assets.newport.com/webDocuments-EN/images/AN04_Thermistor_Calibration_IX.PDF
// http://hydraraptor.blogspot.com/2012/11/more-accurate-thermistor-tables.html
Thermistor(const float temp_low, const float temp_med, const float temp_high, const float res_low, const float res_med, const float res_high, const float pullup_resistance_)
: differential{ adc_pin.is_differential }, pullup_resistance{ pullup_resistance_ },
adc_pin {adc_pin.is_differential ? kDifferentialPair : kNormal, [&]{this->adc_has_new_value();} }
{
setup(temp_low, temp_med, temp_high, res_low, res_med, res_high);
adc_pin.setInterrupts(kPinInterruptOnChange|kInterruptPriorityLow);
adc_pin.setVoltageRange(kSystemVoltage,
0, //get_voltage_of_temp(min_temp),
kSystemVoltage, //get_voltage_of_temp(max_temp),
1000000.0);
};
// Thermistor(const float temp_low, const float temp_med, const float temp_high, const float res_low, const float res_med, const float res_high, const ADCCircuit *_circuit)
// : circuit{_circuit}
// adc_pin {kNormal, [&]{this->adc_has_new_value();} }
// {
// setup(temp_low, temp_med, temp_high, res_low, res_med, res_high);
// adc_pin.setInterrupts(kPinInterruptOnChange|kInterruptPriorityLow);
// adc_pin.setVoltageRange(kSystemVoltage,
// 0, //get_voltage_of_temp(min_temp),
// kSystemVoltage, //get_voltage_of_temp(max_temp),
// 1000000.0);
// };
template <typename... Ts>
Thermistor(const float temp_low, const float temp_med, const float temp_high, const float res_low, const float res_med, const float res_high, const float pullup_resistance_, Ts&&... additional_values)
: differential{ adc_pin.is_differential }, pullup_resistance{ pullup_resistance_ },
adc_pin{adc_pin.is_differential ? kDifferentialPair : kNormal, [&]{this->adc_has_new_value();}, additional_values...}
Thermistor(const float temp_low, const float temp_med, const float temp_high, const float res_low, const float res_med, const float res_high, const ADCCircuit *_circuit, Ts&&... additional_values)
: circuit{_circuit},
adc_pin{kNormal, [&]{this->adc_has_new_value();}, additional_values...}
{
setup(temp_low, temp_med, temp_high, res_low, res_med, res_high);
adc_pin.setInterrupts(kPinInterruptOnChange|kInterruptPriorityLow);
@@ -312,22 +366,13 @@ struct Thermistor {
};
float get_resistance() {
float r;
raw_adc_voltage = history.value();
if (isnan(raw_adc_voltage)) {
return -1;
}
if (differential) {
float v = raw_adc_voltage / kSystemVoltage;
r = (v * 2.0 * pullup_resistance)/(1.0 - v);// - inline_resistance;
}
else {
float v = raw_adc_voltage;
r = ((pullup_resistance * v) / (kSystemVoltage - v));// - inline_resistance;
}
return r;
return circuit->get_resistance(raw_adc_voltage);
};
// float get_resistance() {
@@ -362,10 +407,7 @@ struct Thermistor {
template<typename ADC_t, uint16_t min_temp = 0, uint16_t max_temp = 400>
struct PT100 {
const float pullup_resistance;
const float inline_resistance;
const bool differential;
bool gives_raw_resistance = false;
const ADCCircuit *circuit;
ADC_t adc_pin;
float raw_adc_voltage = 0.0;
@@ -376,27 +418,21 @@ struct PT100 {
typedef PT100<ADC_t, min_temp, max_temp> type;
PT100(const float pullup_resistance_, const float inline_resistance_)
: pullup_resistance{ pullup_resistance_ },
inline_resistance{ inline_resistance_ },
differential{adc_pin.is_differential},
gives_raw_resistance{false},
adc_pin{ADC_t::is_differential ? kDifferentialPair : kNormal, [&]{this->adc_has_new_value();} }
{
adc_pin.setInterrupts(kPinInterruptOnChange|kInterruptPriorityLow);
adc_pin.setVoltageRange(kSystemVoltage,
get_voltage_of_temp(min_temp),
get_voltage_of_temp(max_temp),
6400.0);
};
// PT100(const ADCCircuit *_circuit)
// : circuit{_circuit},
// adc_pin{ADC_t::is_differential ? kDifferentialPair : kNormal, [&]{this->adc_has_new_value();} }
// {
// adc_pin.setInterrupts(kPinInterruptOnChange|kInterruptPriorityLow);
// adc_pin.setVoltageRange(kSystemVoltage,
// get_voltage_of_temp(min_temp),
// get_voltage_of_temp(max_temp),
// 6400.0);
// };
template <typename... Ts>
PT100(const float pullup_resistance_, const float inline_resistance_, Ts&&... additional_values)
: pullup_resistance{ pullup_resistance_ },
inline_resistance{ inline_resistance_ },
differential{false},
gives_raw_resistance{true},
adc_pin{[&]{this->adc_has_new_value();}, additional_values...}
PT100(const ADCCircuit *_circuit, Ts&&... additional_values)
: circuit{_circuit},
adc_pin{kNormal, [&]{this->adc_has_new_value();}, additional_values...}
{
adc_pin.setInterrupts(kPinInterruptOnChange|kInterruptPriorityLow);
adc_pin.setVoltageRange(kSystemVoltage,
@@ -407,16 +443,13 @@ struct PT100 {
constexpr float get_resistance_of_temp(float t) {
// R = 100(1 + A*T + B*T^2); A = 3.9083*10^-3; B = -5.775*10^-7
return 100 * (1 + 0.0039083*t + -0.0000005775*t*t) + inline_resistance;
return 100 * (1 + 0.0039083*t + -0.0000005775*t*t);
};
constexpr float get_voltage_of_temp(float t) {
float r = get_resistance_of_temp(t);
if (differential) {
return (kSystemVoltage * r)/(2.0 * pullup_resistance + r);
}
return r/(r+pullup_resistance)*kSystemVoltage;
return circuit->get_voltage(r);
};
float temperature_exact() {
@@ -430,27 +463,37 @@ struct PT100 {
};
float get_resistance() {
float r;
raw_adc_voltage = history.value();
if (isnan(raw_adc_voltage)) {
return -1;
}
if (gives_raw_resistance) {
r = raw_adc_voltage;
}
else if (differential) {
float v = raw_adc_voltage / kSystemVoltage;
r = (v * 2.0 * pullup_resistance)/(1.0 - v) - inline_resistance;
}
else {
float v = raw_adc_voltage;
r = ((pullup_resistance * v) / (kSystemVoltage - v)) - inline_resistance;
}
return r;
return circuit->get_resistance(raw_adc_voltage);
};
// float get_resistance() {
// float r;
// raw_adc_voltage = history.value();
//
// if (isnan(raw_adc_voltage)) {
// return -1;
// }
//
// if (gives_raw_resistance) {
// r = raw_adc_voltage;
// }
// else if (differential) {
// float v = raw_adc_voltage / kSystemVoltage;
// r = (v * 2.0 * pullup_resistance)/(1.0 - v) - inline_resistance;
// }
// else {
// float v = raw_adc_voltage;
// r = ((pullup_resistance * v) / (kSystemVoltage - v)) - inline_resistance;
// }
// return r;
// };
uint16_t get_raw_value() {
return raw_adc_value;
};
@@ -466,14 +509,8 @@ struct PT100 {
// Call back function from the ADC to tell it that the ADC has a new sample...
void adc_has_new_value() {
if (gives_raw_resistance) {
raw_adc_value = adc_pin.getRaw();
raw_adc_voltage = (raw_adc_value*pullup_resistance)/32768;
history.add_sample(raw_adc_voltage);
} else {
float v = fabs(adc_pin.getVoltage());
history.add_sample(v);
}
float v = fabs(adc_pin.getVoltage());
history.add_sample(v);
};
};
@@ -482,6 +519,7 @@ struct PT100 {
#if HAS_TEMPERATURE_SENSOR_1
// Extruder 1
TEMPERATURE_SENSOR_1_CIRCUIT_TYPE temperature_sensor_1_circuit TEMPERATURE_SENSOR_1_CIRCUIT_INIT;
TEMPERATURE_SENSOR_1_TYPE temperature_sensor_1 TEMPERATURE_SENSOR_1_INIT;
#else
TemperatureSensor temperature_sensor_1;
@@ -490,6 +528,7 @@ TemperatureSensor temperature_sensor_1;
// Extruder 2
#if HAS_TEMPERATURE_SENSOR_2
// Extruder 2
TEMPERATURE_SENSOR_2_CIRCUIT_TYPE temperature_sensor_2_circuit TEMPERATURE_SENSOR_2_CIRCUIT_INIT;
TEMPERATURE_SENSOR_2_TYPE temperature_sensor_2 TEMPERATURE_SENSOR_2_INIT;
#else
TemperatureSensor temperature_sensor_2;
@@ -497,6 +536,7 @@ TemperatureSensor temperature_sensor_2;
#if HAS_TEMPERATURE_SENSOR_3
// Heated bed
TEMPERATURE_SENSOR_3_CIRCUIT_TYPE temperature_sensor_3_circuit TEMPERATURE_SENSOR_3_CIRCUIT_INIT;
TEMPERATURE_SENSOR_3_TYPE temperature_sensor_3 TEMPERATURE_SENSOR_3_INIT;
#else
TemperatureSensor temperature_sensor_3;