Fix M303 thermal protection

2.0.x
Scott Lahteine 7 years ago
parent 325233b454
commit eae0aea1e0

@ -222,7 +222,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS],
int cycles = 0; int cycles = 0;
bool heating = true; bool heating = true;
millis_t temp_ms = millis(), t1 = temp_ms, t2 = temp_ms; millis_t next_temp_ms = millis(), t1 = next_temp_ms, t2 = next_temp_ms;
long t_high = 0, t_low = 0; long t_high = 0, t_low = 0;
long bias, d; long bias, d;
@ -231,7 +231,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS],
float max = 0, min = 10000; float max = 0, min = 10000;
#if HAS_AUTO_FAN #if HAS_AUTO_FAN
next_auto_fan_check_ms = temp_ms + 2500UL; next_auto_fan_check_ms = next_temp_ms + 2500UL;
#endif #endif
if (hotend >= if (hotend >=
@ -271,7 +271,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS],
// PID Tuning loop // PID Tuning loop
while (wait_for_heatup) { while (wait_for_heatup) {
millis_t ms = millis(); const millis_t ms = millis();
if (temp_meas_ready) { // temp sample ready if (temp_meas_ready) { // temp sample ready
updateTemperaturesFromRawValues(); updateTemperaturesFromRawValues();
@ -386,21 +386,21 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS],
#define MAX_OVERSHOOT_PID_AUTOTUNE 20 #define MAX_OVERSHOOT_PID_AUTOTUNE 20
if (input > temp + MAX_OVERSHOOT_PID_AUTOTUNE) { if (input > temp + MAX_OVERSHOOT_PID_AUTOTUNE) {
SERIAL_PROTOCOLLNPGM(MSG_PID_TEMP_TOO_HIGH); SERIAL_PROTOCOLLNPGM(MSG_PID_TEMP_TOO_HIGH);
return; break;
} }
// Every 2 seconds... // Every 2 seconds...
if (ELAPSED(ms, temp_ms + 2000UL)) { if (ELAPSED(ms, next_temp_ms)) {
#if HAS_TEMP_HOTEND || HAS_TEMP_BED #if HAS_TEMP_HOTEND || HAS_TEMP_BED
print_heaterstates(); print_heaterstates();
SERIAL_EOL(); SERIAL_EOL();
#endif #endif
temp_ms = ms; next_temp_ms = ms + 2000UL;
} // every 2 seconds } // every 2 seconds
// Over 2 minutes? // Timeout after 20 minutes since the last undershoot/overshoot cycle
if (((ms - t1) + (ms - t2)) > (10L * 60L * 1000L * 2L)) { if (((ms - t1) + (ms - t2)) > (20L * 60L * 1000L)) {
SERIAL_PROTOCOLLNPGM(MSG_PID_TIMEOUT); SERIAL_PROTOCOLLNPGM(MSG_PID_TIMEOUT);
return; break;
} }
if (cycles > ncycles) { if (cycles > ncycles) {
SERIAL_PROTOCOLLNPGM(MSG_PID_AUTOTUNE_FINISHED); SERIAL_PROTOCOLLNPGM(MSG_PID_AUTOTUNE_FINISHED);
@ -449,7 +449,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS],
} }
lcd_update(); lcd_update();
} }
if (!wait_for_heatup) disable_all_heaters(); disable_all_heaters();
} }
#endif // HAS_PID_HEATING #endif // HAS_PID_HEATING
@ -2033,8 +2033,15 @@ void Temperature::isr() {
for (uint8_t e = 0; e < COUNT(temp_dir); e++) { for (uint8_t e = 0; e < COUNT(temp_dir); e++) {
const int16_t tdir = temp_dir[e], rawtemp = current_temperature_raw[e] * tdir; 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); const bool heater_on = 0 <
if (rawtemp < minttemp_raw[e] * tdir && !is_preheating(e) && target_temperature[e] > 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 #ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
if (++consecutive_low_temperature_error[e] >= MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED) if (++consecutive_low_temperature_error[e] >= MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED)
#endif #endif
@ -2052,8 +2059,15 @@ void Temperature::isr() {
#else #else
#define GEBED >= #define GEBED >=
#endif #endif
if (current_temperature_bed_raw GEBED bed_maxttemp_raw && target_temperature_bed > 0) max_temp_error(-1); const bool bed_on = 0 <
if (bed_minttemp_raw GEBED current_temperature_bed_raw && target_temperature_bed > 0) min_temp_error(-1); #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 #endif
} // temp_count >= OVERSAMPLENR } // temp_count >= OVERSAMPLENR

Loading…
Cancel
Save