Browse Source

Add HAL-based thermal protection grace period for all heaters (#13778)

Kajetan Rzepecki 6 years ago
parent
commit
875e673a8c
2 changed files with 42 additions and 19 deletions
  1. 3
    0
      Marlin/src/HAL/HAL_LPC1768/HAL.h
  2. 39
    19
      Marlin/src/module/temperature.cpp

+ 3
- 0
Marlin/src/HAL/HAL_LPC1768/HAL.h View File

@@ -147,6 +147,9 @@ using FilteredADC = LPC176x::ADC<ADC_LOWPASS_K_VALUE, ADC_MEDIAN_FILTER_SIZE>;
147 147
 #define HAL_READ_ADC()         FilteredADC::get_result()
148 148
 #define HAL_ADC_READY()        FilteredADC::finished_conversion()
149 149
 
150
+// A grace period for the ADC readings to stabilize before they start causing thermal protection errors.
151
+#define THERMAL_PROTECTION_GRACE_PERIOD 500
152
+
150 153
 // Parse a G-code word into a pin index
151 154
 int16_t PARSED_PIN_INDEX(const char code, const int16_t dval);
152 155
 // P0.6 thru P0.9 are for the onboard SD card

+ 39
- 19
Marlin/src/module/temperature.cpp View File

@@ -944,13 +944,29 @@ void Temperature::manage_heater() {
944 944
     if (temp_hotend[1].current < MAX(HEATER_1_MINTEMP, HEATER_1_MAX6675_TMIN + .01)) min_temp_error(1);
945 945
   #endif
946 946
 
947
-  #if WATCH_HOTENDS || WATCH_BED || DISABLED(PIDTEMPBED) || HAS_AUTO_FAN || HEATER_IDLE_HANDLER || WATCH_CHAMBER
947
+  #define HAS_THERMAL_PROTECTION (ENABLED(THERMAL_PROTECTION_HOTENDS) || HAS_THERMALLY_PROTECTED_BED || ENABLED(THERMAL_PROTECTION_CHAMBER))
948
+
949
+  #if HAS_THERMAL_PROTECTION || DISABLED(PIDTEMPBED) || HAS_AUTO_FAN || HEATER_IDLE_HANDLER
948 950
     millis_t ms = millis();
949 951
   #endif
950 952
 
953
+  #if HAS_THERMAL_PROTECTION
954
+    #ifndef THERMAL_PROTECTION_GRACE_PERIOD
955
+      #define THERMAL_PROTECTION_GRACE_PERIOD 0 // No grace period needed on well-behaved boards
956
+    #endif
957
+    #if THERMAL_PROTECTION_GRACE_PERIOD > 0
958
+      static millis_t grace_period = ms + THERMAL_PROTECTION_GRACE_PERIOD;
959
+      if (ELAPSED(ms, grace_period)) grace_period = 0UL;
960
+    #else
961
+      static constexpr millis_t grace_period = 0UL;
962
+    #endif
963
+  #endif
964
+
951 965
   HOTEND_LOOP() {
952
-    if (degHotend(e) > temp_range[e].maxtemp)
953
-      _temp_error(e, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, e));
966
+    #if ENABLED(THERMAL_PROTECTION_HOTENDS)
967
+      if (!grace_period && degHotend(e) > temp_range[e].maxtemp)
968
+        _temp_error(e, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, e));
969
+    #endif
954 970
 
955 971
     #if HEATER_IDLE_HANDLER
956 972
       hotend_idle[e].update(ms);
@@ -1003,8 +1019,10 @@ void Temperature::manage_heater() {
1003 1019
 
1004 1020
   #if HAS_HEATED_BED
1005 1021
 
1006
-    if (degBed() > BED_MAXTEMP)
1007
-      _temp_error(-1, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, -1));
1022
+    #if ENABLED(THERMAL_PROTECTION_BED)
1023
+      if (!grace_period && degBed() > BED_MAXTEMP)
1024
+        _temp_error(-1, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, -1));
1025
+    #endif
1008 1026
 
1009 1027
     #if WATCH_BED
1010 1028
       // Make sure temperature is increasing
@@ -1076,8 +1094,10 @@ void Temperature::manage_heater() {
1076 1094
 
1077 1095
     #if HAS_HEATED_CHAMBER
1078 1096
 
1079
-      if (degChamber() > CHAMBER_MAXTEMP)
1080
-        _temp_error(-2, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, -2));
1097
+      #if ENABLED(THERMAL_PROTECTION_CHAMBER)
1098
+        if (!grace_period && degChamber() > CHAMBER_MAXTEMP)
1099
+          _temp_error(-2, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, -2));
1100
+      #endif
1081 1101
 
1082 1102
       #if WATCH_CHAMBER
1083 1103
         // Make sure temperature is increasing
@@ -1610,7 +1630,7 @@ void Temperature::init() {
1610 1630
   }
1611 1631
 #endif
1612 1632
 
1613
-#if ENABLED(THERMAL_PROTECTION_HOTENDS) || HAS_THERMALLY_PROTECTED_BED || ENABLED(THERMAL_PROTECTION_CHAMBER)
1633
+#if HAS_THERMAL_PROTECTION
1614 1634
 
1615 1635
   #if ENABLED(THERMAL_PROTECTION_HOTENDS)
1616 1636
     Temperature::tr_state_machine_t Temperature::tr_state_machine[HOTENDS]; // = { { TRInactive, 0 } };
@@ -1627,17 +1647,17 @@ void Temperature::init() {
1627 1647
     static float tr_target_temperature[HOTENDS + 1] = { 0.0 };
1628 1648
 
1629 1649
     /**
1630
-        SERIAL_ECHO_START();
1631
-        SERIAL_ECHOPGM("Thermal Thermal Runaway Running. Heater ID: ");
1632
-        if (heater_id == -2) SERIAL_ECHOPGM("chamber");
1633
-        if (heater_id < 0) SERIAL_ECHOPGM("bed"); else SERIAL_ECHO(heater_id);
1634
-        SERIAL_ECHOPAIR(" ;  State:", sm.state, " ;  Timer:", sm.timer, " ;  Temperature:", current, " ;  Target Temp:", target);
1635
-        if (heater_id >= 0)
1636
-          SERIAL_ECHOPAIR(" ;  Idle Timeout:", hotend_idle[heater_id].timed_out);
1637
-        else
1638
-          SERIAL_ECHOPAIR(" ;  Idle Timeout:", bed_idle.timed_out);
1639
-        SERIAL_EOL();
1640
-    */
1650
+      SERIAL_ECHO_START();
1651
+      SERIAL_ECHOPGM("Thermal Thermal Runaway Running. Heater ID: ");
1652
+      if (heater_id == -2) SERIAL_ECHOPGM("chamber");
1653
+      if (heater_id < 0) SERIAL_ECHOPGM("bed"); else SERIAL_ECHO(heater_id);
1654
+      SERIAL_ECHOPAIR(" ;  State:", sm.state, " ;  Timer:", sm.timer, " ;  Temperature:", current, " ;  Target Temp:", target);
1655
+      if (heater_id >= 0)
1656
+        SERIAL_ECHOPAIR(" ;  Idle Timeout:", hotend_idle[heater_id].timed_out);
1657
+      else
1658
+        SERIAL_ECHOPAIR(" ;  Idle Timeout:", bed_idle.timed_out);
1659
+      SERIAL_EOL();
1660
+    //*/
1641 1661
 
1642 1662
     const int heater_index = heater_id >= 0 ? heater_id : HOTENDS;
1643 1663
 

Loading…
Cancel
Save