From 82e23d4774aa2aef5a164818263fcad1c4461d55 Mon Sep 17 00:00:00 2001 From: David Crocker Date: Wed, 15 Jan 2014 13:42:59 +0000 Subject: [PATCH] Make disconnected thermistor show temp as absolute zero again In a previous commit I changed the temperature calculation to give more accurate readings at extreme values. This change meant that a disconnected thermistor no longer shows as absolute zero. Coupled with the change in thermistor beta value, this meant that a disconnected extruder thermistor would show as -28.2C, which is above the usual error threshold of -30C. This commit introduces a special case for a disconnected thermistor and restores the reading to absolute zero for that case. --- Platform.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Platform.cpp b/Platform.cpp index 9eec2e8..d03b82b 100644 --- a/Platform.cpp +++ b/Platform.cpp @@ -334,9 +334,15 @@ void Platform::ClassReport(char* className, float &lastTime) float Platform::GetTemperature(int8_t heater) { - // If the ADC reading is N then for an ideal ADC, the input voltage is at least N/(ADC_RANGE + 1) and less than (N + 1)/(ADC_RANGE + 1), times the analog reference. - // So we add 0.5 to to the reading to get a better estimate of the input. We don't care whether or not we get exactly zero with the thermistor disconnected. - float r = (float)GetRawTemperature(heater) + 0.5; + // If the ADC reading is N then for an ideal ADC, the input voltage is at least N/(AD_RANGE + 1) and less than (N + 1)/(AD_RANGE + 1), times the analog reference. + // So we add 0.5 to to the reading to get a better estimate of the input. But first, recognise the special case of thermistor disconnected. + int rawTemp = GetRawTemperature(heater); + if (rawTemp == AD_RANGE) + { + // Thermistor is disconnected + return ABS_ZERO; + } + float r = (float)rawTemp + 0.5; return ABS_ZERO + thermistorBetas[heater]/log( (r*thermistorSeriesRs[heater]/((AD_RANGE + 1) - r))/thermistorInfRs[heater] ); }