Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce temp watch protection for the bed #3554

Closed
wants to merge 8 commits into from
12 changes: 12 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@
#if ENABLED(THERMAL_PROTECTION_BED)
#define THERMAL_PROTECTION_BED_PERIOD 20 // Seconds
#define THERMAL_PROTECTION_BED_HYSTERESIS 2 // Degrees Celsius

/**
* Whenever an M140 or M190 increases the target temperature the firmware will wait for the
* WATCH_BED_TEMP_PERIOD to expire, and if the temperature hasn't increased by WATCH_BED_TEMP_INCREASE
* degrees, the machine is halted, requiring a hard reset. This test restarts with any M140/M190,
* but only if the current temperature is far enough below the target for a reliable test.
*
* If you get false positives for "Heating failed" increase WATCH_BED_TEMP_PERIOD and/or decrease WATCH_BED_TEMP_INCREASE
* WATCH_BED_TEMP_INCREASE should not be below 2.
*/
#define WATCH_BED_TEMP_PERIOD 60 // Seconds
#define WATCH_BED_TEMP_INCREASE 2 // Degrees Celsius
#endif

#if ENABLED(PIDTEMP)
Expand Down
12 changes: 12 additions & 0 deletions Marlin/example_configurations/Felix/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@
#if ENABLED(THERMAL_PROTECTION_BED)
#define THERMAL_PROTECTION_BED_PERIOD 20 // Seconds
#define THERMAL_PROTECTION_BED_HYSTERESIS 2 // Degrees Celsius

/**
* Whenever an M140 or M190 increases the target temperature the firmware will wait for the
* WATCH_BED_TEMP_PERIOD to expire, and if the temperature hasn't increased by WATCH_BED_TEMP_INCREASE
* degrees, the machine is halted, requiring a hard reset. This test restarts with any M140/M190,
* but only if the current temperature is far enough below the target for a reliable test.
*
* If you get false positives for "Heating failed" increase WATCH_BED_TEMP_PERIOD and/or decrease WATCH_BED_TEMP_INCREASE
* WATCH_BED_TEMP_INCREASE should not be below 2.
*/
#define WATCH_BED_TEMP_PERIOD 60 // Seconds
#define WATCH_BED_TEMP_INCREASE 2 // Degrees Celsius
#endif

#if ENABLED(PIDTEMP)
Expand Down
12 changes: 12 additions & 0 deletions Marlin/example_configurations/Hephestos/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@
#if ENABLED(THERMAL_PROTECTION_BED)
#define THERMAL_PROTECTION_BED_PERIOD 20 // Seconds
#define THERMAL_PROTECTION_BED_HYSTERESIS 2 // Degrees Celsius

/**
* Whenever an M140 or M190 increases the target temperature the firmware will wait for the
* WATCH_BED_TEMP_PERIOD to expire, and if the temperature hasn't increased by WATCH_BED_TEMP_INCREASE
* degrees, the machine is halted, requiring a hard reset. This test restarts with any M140/M190,
* but only if the current temperature is far enough below the target for a reliable test.
*
* If you get false positives for "Heating failed" increase WATCH_BED_TEMP_PERIOD and/or decrease WATCH_BED_TEMP_INCREASE
* WATCH_BED_TEMP_INCREASE should not be below 2.
*/
#define WATCH_BED_TEMP_PERIOD 60 // Seconds
#define WATCH_BED_TEMP_INCREASE 2 // Degrees Celsius
#endif

#if ENABLED(PIDTEMP)
Expand Down
12 changes: 12 additions & 0 deletions Marlin/example_configurations/Hephestos_2/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@
#if ENABLED(THERMAL_PROTECTION_BED)
#define THERMAL_PROTECTION_BED_PERIOD 20 // Seconds
#define THERMAL_PROTECTION_BED_HYSTERESIS 2 // Degrees Celsius

/**
* Whenever an M140 or M190 increases the target temperature the firmware will wait for the
* WATCH_BED_TEMP_PERIOD to expire, and if the temperature hasn't increased by WATCH_BED_TEMP_INCREASE
* degrees, the machine is halted, requiring a hard reset. This test restarts with any M140/M190,
* but only if the current temperature is far enough below the target for a reliable test.
*
* If you get false positives for "Heating failed" increase WATCH_BED_TEMP_PERIOD and/or decrease WATCH_BED_TEMP_INCREASE
* WATCH_BED_TEMP_INCREASE should not be below 2.
*/
#define WATCH_BED_TEMP_PERIOD 60 // Seconds
#define WATCH_BED_TEMP_INCREASE 2 // Degrees Celsius
#endif

#if ENABLED(PIDTEMP)
Expand Down
12 changes: 12 additions & 0 deletions Marlin/example_configurations/K8200/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@
#if ENABLED(THERMAL_PROTECTION_BED)
#define THERMAL_PROTECTION_BED_PERIOD 20 // Seconds
#define THERMAL_PROTECTION_BED_HYSTERESIS 2 // Degrees Celsius

/**
* Whenever an M140 or M190 increases the target temperature the firmware will wait for the
* WATCH_BED_TEMP_PERIOD to expire, and if the temperature hasn't increased by WATCH_BED_TEMP_INCREASE
* degrees, the machine is halted, requiring a hard reset. This test restarts with any M140/M190,
* but only if the current temperature is far enough below the target for a reliable test.
*
* If you get false positives for "Heating failed" increase WATCH_BED_TEMP_PERIOD and/or decrease WATCH_BED_TEMP_INCREASE
* WATCH_BED_TEMP_INCREASE should not be below 2.
*/
#define WATCH_BED_TEMP_PERIOD 60 // Seconds
#define WATCH_BED_TEMP_INCREASE 2 // Degrees Celsius
#endif

#if ENABLED(PIDTEMP)
Expand Down
12 changes: 12 additions & 0 deletions Marlin/example_configurations/RigidBot/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@
#if ENABLED(THERMAL_PROTECTION_BED)
#define THERMAL_PROTECTION_BED_PERIOD 20 // Seconds
#define THERMAL_PROTECTION_BED_HYSTERESIS 2 // Degrees Celsius

/**
* Whenever an M140 or M190 increases the target temperature the firmware will wait for the
* WATCH_BED_TEMP_PERIOD to expire, and if the temperature hasn't increased by WATCH_BED_TEMP_INCREASE
* degrees, the machine is halted, requiring a hard reset. This test restarts with any M140/M190,
* but only if the current temperature is far enough below the target for a reliable test.
*
* If you get false positives for "Heating failed" increase WATCH_BED_TEMP_PERIOD and/or decrease WATCH_BED_TEMP_INCREASE
* WATCH_BED_TEMP_INCREASE should not be below 2.
*/
#define WATCH_BED_TEMP_PERIOD 60 // Seconds
#define WATCH_BED_TEMP_INCREASE 2 // Degrees Celsius
#endif

#if ENABLED(PIDTEMP)
Expand Down
12 changes: 12 additions & 0 deletions Marlin/example_configurations/SCARA/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@
#if ENABLED(THERMAL_PROTECTION_BED)
#define THERMAL_PROTECTION_BED_PERIOD 20 // Seconds
#define THERMAL_PROTECTION_BED_HYSTERESIS 2 // Degrees Celsius

/**
* Whenever an M140 or M190 increases the target temperature the firmware will wait for the
* WATCH_BED_TEMP_PERIOD to expire, and if the temperature hasn't increased by WATCH_BED_TEMP_INCREASE
* degrees, the machine is halted, requiring a hard reset. This test restarts with any M140/M190,
* but only if the current temperature is far enough below the target for a reliable test.
*
* If you get false positives for "Heating failed" increase WATCH_BED_TEMP_PERIOD and/or decrease WATCH_BED_TEMP_INCREASE
* WATCH_BED_TEMP_INCREASE should not be below 2.
*/
#define WATCH_BED_TEMP_PERIOD 60 // Seconds
#define WATCH_BED_TEMP_INCREASE 2 // Degrees Celsius
#endif

#if ENABLED(PIDTEMP)
Expand Down
12 changes: 12 additions & 0 deletions Marlin/example_configurations/TAZ4/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@
#if ENABLED(THERMAL_PROTECTION_BED)
#define THERMAL_PROTECTION_BED_PERIOD 20 // Seconds
#define THERMAL_PROTECTION_BED_HYSTERESIS 2 // Degrees Celsius

/**
* Whenever an M140 or M190 increases the target temperature the firmware will wait for the
* WATCH_BED_TEMP_PERIOD to expire, and if the temperature hasn't increased by WATCH_BED_TEMP_INCREASE
* degrees, the machine is halted, requiring a hard reset. This test restarts with any M140/M190,
* but only if the current temperature is far enough below the target for a reliable test.
*
* If you get false positives for "Heating failed" increase WATCH_BED_TEMP_PERIOD and/or decrease WATCH_BED_TEMP_INCREASE
* WATCH_BED_TEMP_INCREASE should not be below 2.
*/
#define WATCH_BED_TEMP_PERIOD 60 // Seconds
#define WATCH_BED_TEMP_INCREASE 2 // Degrees Celsius
#endif

#if ENABLED(PIDTEMP)
Expand Down
12 changes: 12 additions & 0 deletions Marlin/example_configurations/WITBOX/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@
#if ENABLED(THERMAL_PROTECTION_BED)
#define THERMAL_PROTECTION_BED_PERIOD 20 // Seconds
#define THERMAL_PROTECTION_BED_HYSTERESIS 2 // Degrees Celsius

/**
* Whenever an M140 or M190 increases the target temperature the firmware will wait for the
* WATCH_BED_TEMP_PERIOD to expire, and if the temperature hasn't increased by WATCH_BED_TEMP_INCREASE
* degrees, the machine is halted, requiring a hard reset. This test restarts with any M140/M190,
* but only if the current temperature is far enough below the target for a reliable test.
*
* If you get false positives for "Heating failed" increase WATCH_BED_TEMP_PERIOD and/or decrease WATCH_BED_TEMP_INCREASE
* WATCH_BED_TEMP_INCREASE should not be below 2.
*/
#define WATCH_BED_TEMP_PERIOD 60 // Seconds
#define WATCH_BED_TEMP_INCREASE 2 // Degrees Celsius
#endif

#if ENABLED(PIDTEMP)
Expand Down
12 changes: 12 additions & 0 deletions Marlin/example_configurations/delta/biv2.5/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@
#if ENABLED(THERMAL_PROTECTION_BED)
#define THERMAL_PROTECTION_BED_PERIOD 120 // Seconds
#define THERMAL_PROTECTION_BED_HYSTERESIS 4 // Degrees Celsius

/**
* Whenever an M140 or M190 increases the target temperature the firmware will wait for the
* WATCH_BED_TEMP_PERIOD to expire, and if the temperature hasn't increased by WATCH_BED_TEMP_INCREASE
* degrees, the machine is halted, requiring a hard reset. This test restarts with any M140/M190,
* but only if the current temperature is far enough below the target for a reliable test.
*
* If you get false positives for "Heating failed" increase WATCH_BED_TEMP_PERIOD and/or decrease WATCH_BED_TEMP_INCREASE
* WATCH_BED_TEMP_INCREASE should not be below 2.
*/
#define WATCH_BED_TEMP_PERIOD 60 // Seconds
#define WATCH_BED_TEMP_INCREASE 2 // Degrees Celsius
#endif

#if ENABLED(PIDTEMP)
Expand Down
12 changes: 12 additions & 0 deletions Marlin/example_configurations/delta/generic/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@
#if ENABLED(THERMAL_PROTECTION_BED)
#define THERMAL_PROTECTION_BED_PERIOD 20 // Seconds
#define THERMAL_PROTECTION_BED_HYSTERESIS 2 // Degrees Celsius

/**
* Whenever an M140 or M190 increases the target temperature the firmware will wait for the
* WATCH_BED_TEMP_PERIOD to expire, and if the temperature hasn't increased by WATCH_BED_TEMP_INCREASE
* degrees, the machine is halted, requiring a hard reset. This test restarts with any M140/M190,
* but only if the current temperature is far enough below the target for a reliable test.
*
* If you get false positives for "Heating failed" increase WATCH_BED_TEMP_PERIOD and/or decrease WATCH_BED_TEMP_INCREASE
* WATCH_BED_TEMP_INCREASE should not be below 2.
*/
#define WATCH_BED_TEMP_PERIOD 60 // Seconds
#define WATCH_BED_TEMP_INCREASE 2 // Degrees Celsius
#endif

#if ENABLED(PIDTEMP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@
#if ENABLED(THERMAL_PROTECTION_BED)
#define THERMAL_PROTECTION_BED_PERIOD 20 // Seconds
#define THERMAL_PROTECTION_BED_HYSTERESIS 2 // Degrees Celsius

/**
* Whenever an M140 or M190 increases the target temperature the firmware will wait for the
* WATCH_BED_TEMP_PERIOD to expire, and if the temperature hasn't increased by WATCH_BED_TEMP_INCREASE
* degrees, the machine is halted, requiring a hard reset. This test restarts with any M140/M190,
* but only if the current temperature is far enough below the target for a reliable test.
*
* If you get false positives for "Heating failed" increase WATCH_BED_TEMP_PERIOD and/or decrease WATCH_BED_TEMP_INCREASE
* WATCH_BED_TEMP_INCREASE should not be below 2.
*/
#define WATCH_BED_TEMP_PERIOD 60 // Seconds
#define WATCH_BED_TEMP_INCREASE 2 // Degrees Celsius
#endif

#if ENABLED(PIDTEMP)
Expand Down
12 changes: 12 additions & 0 deletions Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@
#if ENABLED(THERMAL_PROTECTION_BED)
#define THERMAL_PROTECTION_BED_PERIOD 20 // Seconds
#define THERMAL_PROTECTION_BED_HYSTERESIS 2 // Degrees Celsius

/**
* Whenever an M140 or M190 increases the target temperature the firmware will wait for the
* WATCH_BED_TEMP_PERIOD to expire, and if the temperature hasn't increased by WATCH_BED_TEMP_INCREASE
* degrees, the machine is halted, requiring a hard reset. This test restarts with any M140/M190,
* but only if the current temperature is far enough below the target for a reliable test.
*
* If you get false positives for "Heating failed" increase WATCH_BED_TEMP_PERIOD and/or decrease WATCH_BED_TEMP_INCREASE
* WATCH_BED_TEMP_INCREASE should not be below 2.
*/
#define WATCH_BED_TEMP_PERIOD 60 // Seconds
#define WATCH_BED_TEMP_INCREASE 2 // Degrees Celsius
#endif

#if ENABLED(PIDTEMP)
Expand Down
12 changes: 12 additions & 0 deletions Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@
#if ENABLED(THERMAL_PROTECTION_BED)
#define THERMAL_PROTECTION_BED_PERIOD 20 // Seconds
#define THERMAL_PROTECTION_BED_HYSTERESIS 2 // Degrees Celsius

/**
* Whenever an M140 or M190 increases the target temperature the firmware will wait for the
* WATCH_BED_TEMP_PERIOD to expire, and if the temperature hasn't increased by WATCH_BED_TEMP_INCREASE
* degrees, the machine is halted, requiring a hard reset. This test restarts with any M140/M190,
* but only if the current temperature is far enough below the target for a reliable test.
*
* If you get false positives for "Heating failed" increase WATCH_BED_TEMP_PERIOD and/or decrease WATCH_BED_TEMP_INCREASE
* WATCH_BED_TEMP_INCREASE should not be below 2.
*/
#define WATCH_BED_TEMP_PERIOD 60 // Seconds
#define WATCH_BED_TEMP_INCREASE 2 // Degrees Celsius
#endif

#if ENABLED(PIDTEMP)
Expand Down
12 changes: 12 additions & 0 deletions Marlin/example_configurations/makibox/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@
#if ENABLED(THERMAL_PROTECTION_BED)
#define THERMAL_PROTECTION_BED_PERIOD 20 // Seconds
#define THERMAL_PROTECTION_BED_HYSTERESIS 2 // Degrees Celsius

/**
* Whenever an M140 or M190 increases the target temperature the firmware will wait for the
* WATCH_BED_TEMP_PERIOD to expire, and if the temperature hasn't increased by WATCH_BED_TEMP_INCREASE
* degrees, the machine is halted, requiring a hard reset. This test restarts with any M140/M190,
* but only if the current temperature is far enough below the target for a reliable test.
*
* If you get false positives for "Heating failed" increase WATCH_BED_TEMP_PERIOD and/or decrease WATCH_BED_TEMP_INCREASE
* WATCH_BED_TEMP_INCREASE should not be below 2.
*/
#define WATCH_BED_TEMP_PERIOD 60 // Seconds
#define WATCH_BED_TEMP_INCREASE 2 // Degrees Celsius
#endif

#if ENABLED(PIDTEMP)
Expand Down
12 changes: 12 additions & 0 deletions Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@
#if ENABLED(THERMAL_PROTECTION_BED)
#define THERMAL_PROTECTION_BED_PERIOD 20 // Seconds
#define THERMAL_PROTECTION_BED_HYSTERESIS 2 // Degrees Celsius

/**
* Whenever an M140 or M190 increases the target temperature the firmware will wait for the
* WATCH_BED_TEMP_PERIOD to expire, and if the temperature hasn't increased by WATCH_BED_TEMP_INCREASE
* degrees, the machine is halted, requiring a hard reset. This test restarts with any M140/M190,
* but only if the current temperature is far enough below the target for a reliable test.
*
* If you get false positives for "Heating failed" increase WATCH_BED_TEMP_PERIOD and/or decrease WATCH_BED_TEMP_INCREASE
* WATCH_BED_TEMP_INCREASE should not be below 2.
*/
#define WATCH_BED_TEMP_PERIOD 60 // Seconds
#define WATCH_BED_TEMP_INCREASE 2 // Degrees Celsius
#endif

#if ENABLED(PIDTEMP)
Expand Down
47 changes: 43 additions & 4 deletions Marlin/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,16 @@ static float analog2temp(int raw, uint8_t e);
static float analog2tempBed(int raw);
static void updateTemperaturesFromRawValues();

#if ENABLED(THERMAL_PROTECTION_HOTENDS)
#if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ok however.

int watch_target_temp[EXTRUDERS] = { 0 };
millis_t watch_heater_next_ms[EXTRUDERS] = { 0 };
#endif

#if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
int watch_target_bed_temp = 0;
millis_t watch_bed_next_ms = 0;
#endif

#ifndef SOFT_PWM_SCALE
#define SOFT_PWM_SCALE 0
#endif
Expand Down Expand Up @@ -657,7 +662,7 @@ void manage_heater() {
if (ct < max(HEATER_0_MINTEMP, 0.01)) min_temp_error(0);
#endif

#if ENABLED(THERMAL_PROTECTION_HOTENDS) || DISABLED(PIDTEMPBED) || HAS_AUTO_FAN
#if (ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0) || (ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0) || DISABLED(PIDTEMPBED) || HAS_AUTO_FAN
millis_t ms = millis();
#endif

Expand All @@ -674,7 +679,7 @@ void manage_heater() {
soft_pwm[e] = current_temperature[e] > minttemp[e] && current_temperature[e] < maxttemp[e] ? (int)pid_output >> 1 : 0;

// Check if the temperature is failing to increase
#if ENABLED(THERMAL_PROTECTION_HOTENDS)
#if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0

// Is it time to check this extruder's heater?
if (watch_heater_next_ms[e] && ELAPSED(ms, watch_heater_next_ms[e])) {
Expand All @@ -691,6 +696,24 @@ void manage_heater() {

#endif // THERMAL_PROTECTION_HOTENDS

// Check if the temperature is failing to increase
#if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0

// Is it time to check the bed?
if (watch_bed_next_ms && ELAPSED(ms, watch_bed_next_ms)) {
// Has it failed to increase enough?
if (degBed() < watch_target_bed_temp) {
// Stop!
_temp_error(-1, PSTR(MSG_T_HEATING_FAILED), PSTR(MSG_HEATING_FAILED_LCD));
}
else {
// Start again if the target is still far off
start_watching_bed();
}
}

#endif // THERMAL_PROTECTION_HOTENDS

#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
if (fabs(current_temperature[0] - redundant_temperature) > MAX_REDUNDANT_TEMP_SENSOR_DIFF) {
_temp_error(0, PSTR(MSG_REDUNDANCY), PSTR(MSG_ERR_REDUNDANT_TEMP));
Expand Down Expand Up @@ -1100,7 +1123,7 @@ void tp_init() {
#endif //BED_MAXTEMP
}

#if ENABLED(THERMAL_PROTECTION_HOTENDS)
#if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
/**
* Start Heating Sanity Check for hotends that are below
* their target temperature by a configurable margin.
Expand All @@ -1116,6 +1139,22 @@ void tp_init() {
}
#endif

#if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
/**
* Start Heating Sanity Check for hotends that are below
* their target temperature by a configurable margin.
* This is called when the temperature is set. (M140, M190)
*/
void start_watching_bed() {
if (degBed() < degTargetBed() - (WATCH_BED_TEMP_INCREASE + TEMP_BED_HYSTERESIS + 1)) {
watch_target_bed_temp = degBed() + WATCH_BED_TEMP_INCREASE;
watch_bed_next_ms = millis() + (WATCH_BED_TEMP_PERIOD) * 1000UL;
}
else
watch_bed_next_ms = 0;
}
#endif

#if ENABLED(THERMAL_PROTECTION_HOTENDS) || ENABLED(THERMAL_PROTECTION_BED)

void thermal_runaway_protection(TRState* state, millis_t* timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc) {
Expand Down
Loading