diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 9eb098f8d..11a3ed8bc 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -269,7 +269,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS], // PID Tuning loop while (wait_for_heatup) { - millis_t ms = millis(); + const millis_t ms = millis(); if (temp_meas_ready) { // temp sample ready updateTemperaturesFromRawValues(); @@ -384,21 +384,21 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS], #define MAX_OVERSHOOT_PID_AUTOTUNE 20 if (input > temp + MAX_OVERSHOOT_PID_AUTOTUNE) { SERIAL_PROTOCOLLNPGM(MSG_PID_TEMP_TOO_HIGH); - return; + break; } // Every 2 seconds... - if (ELAPSED(ms, temp_ms + 2000UL)) { + if (ELAPSED(ms, temp_ms)) { #if HAS_TEMP_HOTEND || HAS_TEMP_BED print_heaterstates(); SERIAL_EOL(); #endif - temp_ms = ms; + temp_ms = ms + 2000UL; } // every 2 seconds - // Over 2 minutes? - if (((ms - t1) + (ms - t2)) > (10L * 60L * 1000L * 2L)) { + // Timeout after 20 minutes since the last undershoot/overshoot cycle + if (((ms - t1) + (ms - t2)) > (20L * 60L * 1000L)) { SERIAL_PROTOCOLLNPGM(MSG_PID_TIMEOUT); - return; + break; } if (cycles > ncycles) { SERIAL_PROTOCOLLNPGM(MSG_PID_AUTOTUNE_FINISHED); @@ -447,7 +447,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS], } lcd_update(); } - if (!wait_for_heatup) disable_all_heaters(); + disable_all_heaters(); } #endif // HAS_PID_HEATING @@ -2067,8 +2067,15 @@ void Temperature::isr() { for (uint8_t e = 0; e < COUNT(temp_dir); e++) { const int16_t tdir = temp_dir[e], rawtemp = current_temperature_raw[e] * tdir; - if (rawtemp > maxttemp_raw[e] * tdir && target_temperature[e] > 0) max_temp_error(e); - if (rawtemp < minttemp_raw[e] * tdir && !is_preheating(e) && target_temperature[e] > 0) { + const bool heater_on = 0 < + #if ENABLED(PIDTEMP) + soft_pwm_amount[e] + #else + target_temperature[e] + #endif + ; + if (rawtemp > maxttemp_raw[e] * tdir && heater_on) max_temp_error(e); + if (rawtemp < minttemp_raw[e] * tdir && !is_preheating(e) && heater_on) { #ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED if (++consecutive_low_temperature_error[e] >= MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED) #endif @@ -2086,8 +2093,15 @@ void Temperature::isr() { #else #define GEBED >= #endif - if (current_temperature_bed_raw GEBED bed_maxttemp_raw && target_temperature_bed > 0) max_temp_error(-1); - if (bed_minttemp_raw GEBED current_temperature_bed_raw && target_temperature_bed > 0) min_temp_error(-1); + const bool bed_on = 0 < + #if ENABLED(PIDTEMPBED) + soft_pwm_amount_bed + #else + target_temperature_bed + #endif + ; + if (current_temperature_bed_raw GEBED bed_maxttemp_raw && bed_on) max_temp_error(-1); + if (bed_minttemp_raw GEBED current_temperature_bed_raw && bed_on) min_temp_error(-1); #endif } // temp_count >= OVERSAMPLENR