|
@@ -76,15 +76,14 @@ unsigned char soft_pwm_bed;
|
76
|
76
|
#define HAS_HEATER_THERMAL_PROTECTION (defined(THERMAL_RUNAWAY_PROTECTION_PERIOD) && THERMAL_RUNAWAY_PROTECTION_PERIOD > 0)
|
77
|
77
|
#define HAS_BED_THERMAL_PROTECTION (defined(THERMAL_RUNAWAY_PROTECTION_BED_PERIOD) && THERMAL_RUNAWAY_PROTECTION_BED_PERIOD > 0 && TEMP_SENSOR_BED != 0)
|
78
|
78
|
#if HAS_HEATER_THERMAL_PROTECTION || HAS_BED_THERMAL_PROTECTION
|
79
|
|
- enum TRState { TRInactive, TRFirstHeating, TRStable };
|
80
|
|
- static bool thermal_runaway = false;
|
|
79
|
+ enum TRState { TRReset, TRInactive, TRFirstHeating, TRStable, TRRunaway };
|
81
|
80
|
void thermal_runaway_protection(TRState *state, unsigned long *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc);
|
82
|
81
|
#if HAS_HEATER_THERMAL_PROTECTION
|
83
|
|
- static TRState thermal_runaway_state_machine[4] = { TRInactive, TRInactive, TRInactive, TRInactive };
|
|
82
|
+ static TRState thermal_runaway_state_machine[4] = { TRReset, TRReset, TRReset, TRReset };
|
84
|
83
|
static unsigned long thermal_runaway_timer[4]; // = {0,0,0,0};
|
85
|
84
|
#endif
|
86
|
85
|
#if HAS_BED_THERMAL_PROTECTION
|
87
|
|
- static TRState thermal_runaway_bed_state_machine = TRInactive;
|
|
86
|
+ static TRState thermal_runaway_bed_state_machine = TRReset;
|
88
|
87
|
static unsigned long thermal_runaway_bed_timer;
|
89
|
88
|
#endif
|
90
|
89
|
#endif
|
|
@@ -1007,7 +1006,7 @@ void setWatch() {
|
1007
|
1006
|
|
1008
|
1007
|
void thermal_runaway_protection(TRState *state, unsigned long *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc) {
|
1009
|
1008
|
|
1010
|
|
- static int tr_target_temperature[EXTRUDERS+1];
|
|
1009
|
+ static float tr_target_temperature[EXTRUDERS+1] = { 0.0 };
|
1011
|
1010
|
|
1012
|
1011
|
/*
|
1013
|
1012
|
SERIAL_ECHO_START;
|
|
@@ -1023,20 +1022,23 @@ void setWatch() {
|
1023
|
1022
|
SERIAL_ECHOPGM(target_temperature);
|
1024
|
1023
|
SERIAL_EOL;
|
1025
|
1024
|
*/
|
1026
|
|
- if (target_temperature == 0 || thermal_runaway) {
|
1027
|
|
- *state = TRInactive;
|
1028
|
|
- *timer = 0;
|
1029
|
|
- return;
|
1030
|
|
- }
|
1031
|
1025
|
|
1032
|
1026
|
int heater_index = heater_id >= 0 ? heater_id : EXTRUDERS;
|
1033
|
1027
|
|
|
1028
|
+ // If the target temperature changes, restart
|
|
1029
|
+ if (tr_target_temperature[heater_index] != target_temperature)
|
|
1030
|
+ *state = TRReset;
|
|
1031
|
+
|
1034
|
1032
|
switch (*state) {
|
|
1033
|
+ case TRReset:
|
|
1034
|
+ *timer = 0;
|
|
1035
|
+ *state = TRInactive;
|
|
1036
|
+ break;
|
1035
|
1037
|
// Inactive state waits for a target temperature to be set
|
1036
|
1038
|
case TRInactive:
|
1037
|
1039
|
if (target_temperature > 0) {
|
1038
|
|
- *state = TRFirstHeating;
|
1039
|
1040
|
tr_target_temperature[heater_index] = target_temperature;
|
|
1041
|
+ *state = TRFirstHeating;
|
1040
|
1042
|
}
|
1041
|
1043
|
break;
|
1042
|
1044
|
// When first heating, wait for the temperature to be reached then go to Stable state
|
|
@@ -1045,31 +1047,24 @@ void setWatch() {
|
1045
|
1047
|
break;
|
1046
|
1048
|
// While the temperature is stable watch for a bad temperature
|
1047
|
1049
|
case TRStable:
|
1048
|
|
- {
|
1049
|
|
- // If the target temperature changes, restart
|
1050
|
|
- if (tr_target_temperature[heater_index] != target_temperature) {
|
1051
|
|
- *state = TRInactive;
|
1052
|
|
- break;
|
1053
|
|
- }
|
1054
|
|
-
|
1055
|
1050
|
// If the temperature is over the target (-hysteresis) restart the timer
|
1056
|
|
- if (temperature >= tr_target_temperature[heater_index] - hysteresis_degc) *timer = millis();
|
1057
|
|
-
|
1058
|
|
- // If the timer goes too long without a reset, trigger shutdown
|
1059
|
|
- else if (millis() > *timer + period_seconds * 1000UL) {
|
1060
|
|
- SERIAL_ERROR_START;
|
1061
|
|
- SERIAL_ERRORLNPGM(MSG_THERMAL_RUNAWAY_STOP);
|
1062
|
|
- if (heater_id < 0) SERIAL_ERRORLNPGM("bed"); else SERIAL_ERRORLN(heater_id);
|
1063
|
|
- LCD_ALERTMESSAGEPGM(MSG_THERMAL_RUNAWAY);
|
1064
|
|
- thermal_runaway = true;
|
1065
|
|
- for (;;) {
|
1066
|
|
- disable_heater();
|
1067
|
|
- disable_all_steppers();
|
1068
|
|
- manage_heater();
|
1069
|
|
- lcd_update();
|
1070
|
|
- }
|
|
1051
|
+ if (temperature >= tr_target_temperature[heater_index] - hysteresis_degc)
|
|
1052
|
+ *timer = millis();
|
|
1053
|
+ // If the timer goes too long without a reset, trigger shutdown
|
|
1054
|
+ else if (millis() > *timer + period_seconds * 1000UL)
|
|
1055
|
+ *state = TRRunaway;
|
|
1056
|
+ break;
|
|
1057
|
+ case TRRunaway:
|
|
1058
|
+ SERIAL_ERROR_START;
|
|
1059
|
+ SERIAL_ERRORLNPGM(MSG_THERMAL_RUNAWAY_STOP);
|
|
1060
|
+ if (heater_id < 0) SERIAL_ERRORLNPGM("bed"); else SERIAL_ERRORLN(heater_id);
|
|
1061
|
+ LCD_ALERTMESSAGEPGM(MSG_THERMAL_RUNAWAY);
|
|
1062
|
+ disable_heater();
|
|
1063
|
+ disable_all_steppers();
|
|
1064
|
+ for (;;) {
|
|
1065
|
+ manage_heater();
|
|
1066
|
+ lcd_update();
|
1071
|
1067
|
}
|
1072
|
|
- } break;
|
1073
|
1068
|
}
|
1074
|
1069
|
}
|
1075
|
1070
|
|