From 4e482baa7f8f2ebd78b862b30788f656d9f26c53 Mon Sep 17 00:00:00 2001 From: Rob Giseburt Date: Fri, 27 Oct 2017 13:47:59 -0500 Subject: [PATCH] Make temperature reading more tolerant --- g2core/temperature.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/g2core/temperature.cpp b/g2core/temperature.cpp index c669cc0b..d97a91b9 100755 --- a/g2core/temperature.cpp +++ b/g2core/temperature.cpp @@ -459,7 +459,13 @@ struct PT100 { // from https://www.maximintegrated.com/en/app-notes/index.mvp/id/3450 // run through wolfram as: // solve R = 100(1 + A*T + B*T^2); A = 3.9083*10^-3; B = -5.775*10^-7 for T - return 3383.81 - (0.287154*sqrt(159861899.0 - 210000.0*r)); + float t = 3383.81 - (0.287154*sqrt(159861899.0 - 210000.0*r)); + + if (t > max_temp) { + return -1; + } + + return t; }; float get_resistance() { @@ -509,7 +515,15 @@ struct PT100 { // Call back function from the ADC to tell it that the ADC has a new sample... void adc_has_new_value() { + raw_adc_value = adc_pin.getRaw(); float v = fabs(adc_pin.getVoltage()); +// if (v < 0) { +// char buffer[128]; +// char *str = buffer; +// str += sprintf(str, "Heater sensor failure. Reading was: %f", v); +// cm_alarm(STAT_TEMPERATURE_CONTROL_ERROR, buffer); +// return; +// } history.add_sample(v); }; };