Sfoglia il codice sorgente

Merge pull request #1813 from thinkyhead/fixup_probing

Fix bad thermal runaway trigger
Scott Lahteine 10 anni fa
parent
commit
6c5f07c5cb
1 ha cambiato i file con 29 aggiunte e 34 eliminazioni
  1. 29
    34
      Marlin/temperature.cpp

+ 29
- 34
Marlin/temperature.cpp Vedi File

76
 #define HAS_HEATER_THERMAL_PROTECTION (defined(THERMAL_RUNAWAY_PROTECTION_PERIOD) && THERMAL_RUNAWAY_PROTECTION_PERIOD > 0)
76
 #define HAS_HEATER_THERMAL_PROTECTION (defined(THERMAL_RUNAWAY_PROTECTION_PERIOD) && THERMAL_RUNAWAY_PROTECTION_PERIOD > 0)
77
 #define HAS_BED_THERMAL_PROTECTION (defined(THERMAL_RUNAWAY_PROTECTION_BED_PERIOD) && THERMAL_RUNAWAY_PROTECTION_BED_PERIOD > 0 && TEMP_SENSOR_BED != 0)
77
 #define HAS_BED_THERMAL_PROTECTION (defined(THERMAL_RUNAWAY_PROTECTION_BED_PERIOD) && THERMAL_RUNAWAY_PROTECTION_BED_PERIOD > 0 && TEMP_SENSOR_BED != 0)
78
 #if HAS_HEATER_THERMAL_PROTECTION || HAS_BED_THERMAL_PROTECTION
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
   void thermal_runaway_protection(TRState *state, unsigned long *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc);
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
   #if HAS_HEATER_THERMAL_PROTECTION
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
     static unsigned long thermal_runaway_timer[4]; // = {0,0,0,0};
83
     static unsigned long thermal_runaway_timer[4]; // = {0,0,0,0};
85
   #endif
84
   #endif
86
   #if HAS_BED_THERMAL_PROTECTION
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
     static unsigned long thermal_runaway_bed_timer;
87
     static unsigned long thermal_runaway_bed_timer;
89
   #endif
88
   #endif
90
 #endif
89
 #endif
1007
 
1006
 
1008
   void thermal_runaway_protection(TRState *state, unsigned long *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc) {
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
         SERIAL_ECHO_START;
1012
         SERIAL_ECHO_START;
1023
         SERIAL_ECHOPGM(target_temperature);
1022
         SERIAL_ECHOPGM(target_temperature);
1024
         SERIAL_EOL;
1023
         SERIAL_EOL;
1025
     */
1024
     */
1026
-    if (target_temperature == 0 || thermal_runaway) {
1027
-      *state = TRInactive;
1028
-      *timer = 0;
1029
-      return;
1030
-    }
1031
 
1025
 
1032
     int heater_index = heater_id >= 0 ? heater_id : EXTRUDERS;
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
     switch (*state) {
1032
     switch (*state) {
1033
+      case TRReset:
1034
+        *timer = 0;
1035
+        *state = TRInactive;
1036
+        break;
1035
       // Inactive state waits for a target temperature to be set
1037
       // Inactive state waits for a target temperature to be set
1036
       case TRInactive:
1038
       case TRInactive:
1037
         if (target_temperature > 0) {
1039
         if (target_temperature > 0) {
1038
-          *state = TRFirstHeating;
1039
           tr_target_temperature[heater_index] = target_temperature;
1040
           tr_target_temperature[heater_index] = target_temperature;
1041
+          *state = TRFirstHeating;
1040
         }
1042
         }
1041
         break;
1043
         break;
1042
       // When first heating, wait for the temperature to be reached then go to Stable state
1044
       // When first heating, wait for the temperature to be reached then go to Stable state
1045
         break;
1047
         break;
1046
       // While the temperature is stable watch for a bad temperature
1048
       // While the temperature is stable watch for a bad temperature
1047
       case TRStable:
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
         // If the temperature is over the target (-hysteresis) restart the timer
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
 

Loading…
Annulla
Salva