[1.1.x] Fix M303 thermal protection #8103 (#8126)

* Fixed M303 thermal protection

The temperature sanity checking logic was not being applied during M303
(pid autotuning) because instead of setting a target temperature, it
directly manipulated the pwm values.  When PIDTEMP/PIDTEMPBED is
enabled, PWM values rather than the target temperature determine whether
the heater is on.  I changed this to look directly at the PWM amount
when pid is enabled.

* Turn off heaters on M303 error

Currently, PID autotuning stops if it overshoots the temperature by 20C
or if if the temperature does not change for 20 minutes and it times
out.  I added calls to disable the heaters in these scenarios.

* Removed unnecessary if statement.

Added changes suggested by GMagician.

* Update temperature.cpp

* Update temperature.cpp

* Update temperature.cpp
This commit is contained in:
Rowan Meara 2017-10-29 02:34:47 -07:00 committed by Scott Lahteine
parent c0a8275cb0
commit 9850ba0cbd

View File

@ -269,7 +269,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();
@ -384,21 +384,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, 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; 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);
@ -447,7 +447,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
@ -2067,8 +2067,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
@ -2086,8 +2093,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