From 587154c01ba2b7eba0ac8c899b27563f74011590 Mon Sep 17 00:00:00 2001 From: daid303 Date: Thu, 6 Dec 2012 10:36:07 +0100 Subject: [PATCH] Fix the WATCHPERIOD implementation. It did not work correctly in a multi extruder setup, it did not work after 32 seconds after startup (int16 used as millies timestamp). And it did not work if you gave an M104 or M109 when the target was already around the target setpoint. So on average, it did not work at all. The new implementation should be robust in detecting a failure to heat up. --- Marlin/Configuration_adv.h | 8 ++++--- Marlin/temperature.cpp | 45 ++++++++++++++++---------------------- Marlin/temperature.h | 6 ----- 3 files changed, 24 insertions(+), 35 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 1727606fd..be66d1805 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -13,8 +13,10 @@ //// Heating sanity check: // This waits for the watchperiod in milliseconds whenever an M104 or M109 increases the target temperature // If the temperature has not increased at the end of that period, the target temperature is set to zero. -// It can be reset with another M104/M109 -//#define WATCHPERIOD 20000 //20 seconds +// It can be reset with another M104/M109. This check is also only triggered if the target temperature and the current temperature +// differ by at least 2x WATCH_TEMP_INCREASE +//#define WATCH_TEMP_PERIOD 20000 //20 seconds +//#define WATCH_TEMP_INCREASE 10 //Heat up at least 10 degree in 20 seconds // Wait for Cooldown // This defines if the M109 call should not block if it is cooling down. @@ -199,7 +201,7 @@ //#define USE_WATCHDOG #ifdef USE_WATCHDOG -// If you have a watchdog reboot in an ArduinoMega2560 then the device will hang forever, as a watchdog reset will leave the watchdog on. +// If you have a watchdog reboot in an ArduinoMega2560 then the device will hang forever, as a watchdog reset will leave the watchdog on. // The "WATCHDOG_RESET_MANUAL" goes around this by not using the hardware reset. // However, THIS FEATURE IS UNSAFE!, as it will only work if interrupts are disabled. And the code could hang in an interrupt routine with interrupts disabled. //#define WATCHDOG_RESET_MANUAL diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 4a7f39c0f..9226f6e08 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -105,12 +105,6 @@ static volatile bool temp_meas_ready = false; static unsigned char soft_pwm[EXTRUDERS]; static unsigned char soft_pwm_bed; -#ifdef WATCHPERIOD - int watch_raw[EXTRUDERS] = { -1000 }; // the first value used for all - int watch_oldtemp[3] = {0,0,0}; - unsigned long watchmillis = 0; -#endif //WATCHPERIOD - #if EXTRUDERS > 3 # error Unsupported number of extruders #elif EXTRUDERS > 2 @@ -129,6 +123,10 @@ static int bed_maxttemp = 16383; static void *heater_ttbl_map[EXTRUDERS] = ARRAY_BY_EXTRUDERS((void *)heater_0_temptable, (void *)heater_1_temptable, (void *)heater_2_temptable); static int heater_ttbllen_map[EXTRUDERS] = ARRAY_BY_EXTRUDERS(heater_0_temptable_len, heater_1_temptable_len, heater_2_temptable_len); +#ifdef WATCH_TEMP_PERIOD +int watch_start_temp[EXTRUDERS] = ARRAY_BY_EXTRUDERS(0,0,0); +unsigned long watchmillis[EXTRUDERS] = ARRAY_BY_EXTRUDERS(0,0,0); +#endif //WATCH_TEMP_PERIOD //=========================================================================== //============================= functions ============================ @@ -376,20 +374,23 @@ void manage_heater() else { soft_pwm[e] = 0; } - } // End extruder for loop - - #ifdef WATCHPERIOD - if(watchmillis && millis() - watchmillis > WATCHPERIOD){ - if(watch_oldtemp[0] >= degHotend(active_extruder)){ - setTargetHotend(0,active_extruder); + + #ifdef WATCH_TEMP_PERIOD + if(watchmillis[e] && millis() - watchmillis[e] > WATCH_TEMP_PERIOD) + { + if(degHotend(e) < watch_start_temp[e] + WATCH_TEMP_INCREASE) + { + setTargetHotend(0, e); LCD_MESSAGEPGM("Heating failed"); SERIAL_ECHO_START; SERIAL_ECHOLN("Heating failed"); }else{ - watchmillis = 0; + watchmillis[e] = 0; } } - #endif + #endif + + } // End extruder for loop #ifndef PIDTEMPBED @@ -625,9 +626,6 @@ void tp_init() // Finish init of mult extruder arrays for(int e = 0; e < EXTRUDERS; e++) { // populate with the first value -#ifdef WATCHPERIOD - watch_raw[e] = watch_raw[0]; -#endif maxttemp[e] = maxttemp[0]; #ifdef PIDTEMP temp_iState_min[e] = 0.0; @@ -746,22 +744,17 @@ void tp_init() #endif //BED_MAXTEMP } - - void setWatch() { -#ifdef WATCHPERIOD - int t = 0; +#ifdef WATCH_TEMP_PERIOD for (int e = 0; e < EXTRUDERS; e++) { - if(isHeatingHotend(e)) - watch_oldtemp[0] = degHotend(0); + if(degHotend(e) < degTargetHotend(e) - (WATCH_TEMP_INCREASE * 2)) { - t = max(t,millis()); - watch_raw[e] = current_raw[e]; + watch_start_temp[e] = degHotend(e); + watchmillis[e] = millis(); } } - watchmillis = t; #endif } diff --git a/Marlin/temperature.h b/Marlin/temperature.h index ae289de41..6f4591700 100644 --- a/Marlin/temperature.h +++ b/Marlin/temperature.h @@ -56,12 +56,6 @@ extern int current_raw_bed; extern float pid_setpoint_bed; #endif -// #ifdef WATCHPERIOD - extern int watch_raw[EXTRUDERS] ; -// extern unsigned long watchmillis; -// #endif - - //high level conversion routines, for use outside of temperature.cpp //inline so that there is no performance decrease. //deg=degreeCelsius