Browse Source

Merge pull request #3705 from thinkyhead/rc_runaway_logic

Fallthru in thermal runaway test when TRState changes
Scott Lahteine 8 years ago
parent
commit
050e0bd2af
2 changed files with 15 additions and 22 deletions
  1. 12
    19
      Marlin/temperature.cpp
  2. 3
    3
      Marlin/temperature.h

+ 12
- 19
Marlin/temperature.cpp View File

@@ -1047,33 +1047,26 @@ void Temperature::init() {
1047 1047
     int heater_index = heater_id >= 0 ? heater_id : EXTRUDERS;
1048 1048
 
1049 1049
     // If the target temperature changes, restart
1050
-    if (tr_target_temperature[heater_index] != target_temperature)
1051
-      *state = TRReset;
1050
+    if (tr_target_temperature[heater_index] != target_temperature) {
1051
+      tr_target_temperature[heater_index] = target_temperature;
1052
+      *state = target_temperature > 0 ? TRFirstHeating : TRInactive;
1053
+    }
1052 1054
 
1053 1055
     switch (*state) {
1054
-      case TRReset:
1055
-        *timer = 0;
1056
-        *state = TRInactive;
1057 1056
       // Inactive state waits for a target temperature to be set
1058
-      case TRInactive:
1059
-        if (target_temperature > 0) {
1060
-          tr_target_temperature[heater_index] = target_temperature;
1061
-          *state = TRFirstHeating;
1062
-        }
1063
-        break;
1057
+      case TRInactive: break;
1064 1058
       // When first heating, wait for the temperature to be reached then go to Stable state
1065 1059
       case TRFirstHeating:
1066
-        if (temperature >= tr_target_temperature[heater_index]) *state = TRStable;
1067
-        break;
1060
+        if (temperature < tr_target_temperature[heater_index]) break;
1061
+        *state = TRStable;
1068 1062
       // While the temperature is stable watch for a bad temperature
1069 1063
       case TRStable:
1070
-        // If the temperature is over the target (-hysteresis) restart the timer
1071
-        if (temperature >= tr_target_temperature[heater_index] - hysteresis_degc)
1072
-          *timer = millis();
1073
-        // If the timer goes too long without a reset, trigger shutdown
1074
-        else if (ELAPSED(millis(), *timer + period_seconds * 1000UL))
1064
+        if (temperature < tr_target_temperature[heater_index] - hysteresis_degc && ELAPSED(millis(), *timer))
1075 1065
           *state = TRRunaway;
1076
-        break;
1066
+        else {
1067
+          *timer = millis() + period_seconds * 1000UL;
1068
+          break;
1069
+        }
1077 1070
       case TRRunaway:
1078 1071
         _temp_error(heater_id, PSTR(MSG_T_THERMAL_RUNAWAY), PSTR(MSG_THERMAL_RUNAWAY));
1079 1072
     }

+ 3
- 3
Marlin/temperature.h View File

@@ -358,17 +358,17 @@ class Temperature {
358 358
 
359 359
     #if ENABLED(THERMAL_PROTECTION_HOTENDS) || HAS_THERMALLY_PROTECTED_BED
360 360
 
361
-      typedef enum TRState { TRReset, TRInactive, TRFirstHeating, TRStable, TRRunaway } TRstate;
361
+      typedef enum TRState { TRInactive, TRFirstHeating, TRStable, TRRunaway } TRstate;
362 362
 
363 363
       void thermal_runaway_protection(TRState* state, millis_t* timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc);
364 364
 
365 365
       #if ENABLED(THERMAL_PROTECTION_HOTENDS)
366
-        TRState thermal_runaway_state_machine[EXTRUDERS] = { TRReset };
366
+        TRState thermal_runaway_state_machine[EXTRUDERS] = { TRInactive };
367 367
         millis_t thermal_runaway_timer[EXTRUDERS] = { 0 };
368 368
       #endif
369 369
 
370 370
       #if HAS_THERMALLY_PROTECTED_BED
371
-        TRState thermal_runaway_bed_state_machine = TRReset;
371
+        TRState thermal_runaway_bed_state_machine = TRInactive;
372 372
         millis_t thermal_runaway_bed_timer;
373 373
       #endif
374 374
 

Loading…
Cancel
Save