Browse Source

Merge pull request #1787 from thinkyhead/fixup_tr

Fix: thermal_runaway_protection triggered by target temperature increase
Scott Lahteine 9 years ago
parent
commit
4c7af484f8
6 changed files with 146 additions and 159 deletions
  1. 3
    0
      Marlin/Marlin.h
  2. 47
    40
      Marlin/Marlin_main.cpp
  3. 3
    3
      Marlin/planner.cpp
  4. 1
    7
      Marlin/stepper.cpp
  5. 76
    79
      Marlin/temperature.cpp
  6. 16
    30
      Marlin/temperature.h

+ 3
- 0
Marlin/Marlin.h View File

@@ -179,6 +179,9 @@ void manage_inactivity(bool ignore_stepper_queue=false);
179 179
   #define disable_e3() /* nothing */
180 180
 #endif
181 181
 
182
+void enable_all_steppers();
183
+void disable_all_steppers();
184
+
182 185
 enum AxisEnum {X_AXIS=0, Y_AXIS=1, A_AXIS=0, B_AXIS=1, Z_AXIS=2, E_AXIS=3, X_HEAD=4, Y_HEAD=5};
183 186
 //X_HEAD and Y_HEAD is used for systems that don't have a 1:1 relationship between X_AXIS and X Head movement, like CoreXY bots.
184 187
 

+ 47
- 40
Marlin/Marlin_main.cpp View File

@@ -110,6 +110,7 @@
110 110
 //        Call gcode file : "M32 P !filename#" and return to caller file after finishing (similar to #include).
111 111
 //        The '#' is necessary when calling from within sd files, as it stops buffer prereading
112 112
 // M42  - Change pin status via gcode Use M42 Px Sy to set pin x to value y, when omitting Px the onboard led will be used.
113
+// M48  - Measure Z_Probe repeatability. M48 [n # of points] [X position] [Y position] [V_erboseness #] [E_ngage Probe] [L # of legs of travel]
113 114
 // M80  - Turn on Power Supply
114 115
 // M81  - Turn off Power Supply
115 116
 // M82  - Set E codes absolute (default)
@@ -2569,13 +2570,7 @@ inline void gcode_G92() {
2569 2570
  */
2570 2571
 inline void gcode_M17() {
2571 2572
   LCD_MESSAGEPGM(MSG_NO_MOVE);
2572
-  enable_x();
2573
-  enable_y();
2574
-  enable_z();
2575
-  enable_e0();
2576
-  enable_e1();
2577
-  enable_e2();
2578
-  enable_e3();
2573
+  enable_all_steppers();
2579 2574
 }
2580 2575
 
2581 2576
 #ifdef SDSUPPORT
@@ -3055,26 +3050,29 @@ inline void gcode_M104() {
3055 3050
 inline void gcode_M105() {
3056 3051
   if (setTargetedHotend(105)) return;
3057 3052
 
3058
-  #if HAS_TEMP_0
3059
-    SERIAL_PROTOCOLPGM("ok T:");
3060
-    SERIAL_PROTOCOL_F(degHotend(tmp_extruder),1);
3061
-    SERIAL_PROTOCOLPGM(" /");
3062
-    SERIAL_PROTOCOL_F(degTargetHotend(tmp_extruder),1);
3053
+  #if HAS_TEMP_0 || HAS_TEMP_BED
3054
+    SERIAL_PROTOCOLPGM("ok");
3055
+    #if HAS_TEMP_0
3056
+      SERIAL_PROTOCOLPGM(" T:");
3057
+      SERIAL_PROTOCOL_F(degHotend(tmp_extruder), 1);
3058
+      SERIAL_PROTOCOLPGM(" /");
3059
+      SERIAL_PROTOCOL_F(degTargetHotend(tmp_extruder), 1);
3060
+    #endif
3063 3061
     #if HAS_TEMP_BED
3064 3062
       SERIAL_PROTOCOLPGM(" B:");
3065
-      SERIAL_PROTOCOL_F(degBed(),1);
3063
+      SERIAL_PROTOCOL_F(degBed(), 1);
3066 3064
       SERIAL_PROTOCOLPGM(" /");
3067
-      SERIAL_PROTOCOL_F(degTargetBed(),1);
3068
-    #endif // HAS_TEMP_BED
3069
-    for (int8_t cur_extruder = 0; cur_extruder < EXTRUDERS; ++cur_extruder) {
3065
+      SERIAL_PROTOCOL_F(degTargetBed(), 1);
3066
+    #endif
3067
+    for (int8_t e = 0; e < EXTRUDERS; ++e) {
3070 3068
       SERIAL_PROTOCOLPGM(" T");
3071
-      SERIAL_PROTOCOL(cur_extruder);
3069
+      SERIAL_PROTOCOL(e);
3072 3070
       SERIAL_PROTOCOLPGM(":");
3073
-      SERIAL_PROTOCOL_F(degHotend(cur_extruder),1);
3071
+      SERIAL_PROTOCOL_F(degHotend(e), 1);
3074 3072
       SERIAL_PROTOCOLPGM(" /");
3075
-      SERIAL_PROTOCOL_F(degTargetHotend(cur_extruder),1);
3073
+      SERIAL_PROTOCOL_F(degTargetHotend(e), 1);
3076 3074
     }
3077
-  #else // !HAS_TEMP_0
3075
+  #else // !HAS_TEMP_0 && !HAS_TEMP_BED
3078 3076
     SERIAL_ERROR_START;
3079 3077
     SERIAL_ERRORLNPGM(MSG_ERR_NO_THERMISTORS);
3080 3078
   #endif
@@ -3112,7 +3110,7 @@ inline void gcode_M105() {
3112 3110
     }
3113 3111
   #endif
3114 3112
 
3115
-  SERIAL_PROTOCOLLN("");
3113
+  SERIAL_EOL;
3116 3114
 }
3117 3115
 
3118 3116
 #if HAS_FAN
@@ -3127,7 +3125,7 @@ inline void gcode_M105() {
3127 3125
    */
3128 3126
   inline void gcode_M107() { fanSpeed = 0; }
3129 3127
 
3130
-#endif //FAN_PIN
3128
+#endif // HAS_FAN
3131 3129
 
3132 3130
 /**
3133 3131
  * M109: Wait for extruder(s) to reach temperature
@@ -3185,10 +3183,10 @@ inline void gcode_M109() {
3185 3183
             SERIAL_PROTOCOLLN( timetemp );
3186 3184
           }
3187 3185
           else {
3188
-            SERIAL_PROTOCOLLN( "?" );
3186
+            SERIAL_PROTOCOLLNPGM("?");
3189 3187
           }
3190 3188
         #else
3191
-          SERIAL_PROTOCOLLN("");
3189
+          SERIAL_EOL;
3192 3190
         #endif
3193 3191
         timetemp = millis();
3194 3192
       }
@@ -3240,7 +3238,7 @@ inline void gcode_M109() {
3240 3238
         SERIAL_PROTOCOL((int)active_extruder);
3241 3239
         SERIAL_PROTOCOLPGM(" B:");
3242 3240
         SERIAL_PROTOCOL_F(degBed(), 1);
3243
-        SERIAL_PROTOCOLLN("");
3241
+        SERIAL_EOL;
3244 3242
       }
3245 3243
       manage_heater();
3246 3244
       manage_inactivity();
@@ -3441,27 +3439,26 @@ inline void gcode_M114() {
3441 3439
   SERIAL_PROTOCOLPGM(" Z:");
3442 3440
   SERIAL_PROTOCOL(float(st_get_position(Z_AXIS))/axis_steps_per_unit[Z_AXIS]);
3443 3441
 
3444
-  SERIAL_PROTOCOLLN("");
3442
+  SERIAL_EOL;
3445 3443
 
3446 3444
   #ifdef SCARA
3447 3445
     SERIAL_PROTOCOLPGM("SCARA Theta:");
3448 3446
     SERIAL_PROTOCOL(delta[X_AXIS]);
3449 3447
     SERIAL_PROTOCOLPGM("   Psi+Theta:");
3450 3448
     SERIAL_PROTOCOL(delta[Y_AXIS]);
3451
-    SERIAL_PROTOCOLLN("");
3449
+    SERIAL_EOL;
3452 3450
     
3453 3451
     SERIAL_PROTOCOLPGM("SCARA Cal - Theta:");
3454 3452
     SERIAL_PROTOCOL(delta[X_AXIS]+home_offset[X_AXIS]);
3455 3453
     SERIAL_PROTOCOLPGM("   Psi+Theta (90):");
3456 3454
     SERIAL_PROTOCOL(delta[Y_AXIS]-delta[X_AXIS]-90+home_offset[Y_AXIS]);
3457
-    SERIAL_PROTOCOLLN("");
3455
+    SERIAL_EOL;
3458 3456
     
3459 3457
     SERIAL_PROTOCOLPGM("SCARA step Cal - Theta:");
3460 3458
     SERIAL_PROTOCOL(delta[X_AXIS]/90*axis_steps_per_unit[X_AXIS]);
3461 3459
     SERIAL_PROTOCOLPGM("   Psi+Theta:");
3462 3460
     SERIAL_PROTOCOL((delta[Y_AXIS]-delta[X_AXIS])/90*axis_steps_per_unit[Y_AXIS]);
3463
-    SERIAL_PROTOCOLLN("");
3464
-    SERIAL_PROTOCOLLN("");
3461
+    SERIAL_EOL; SERIAL_EOL;
3465 3462
   #endif
3466 3463
 }
3467 3464
 
@@ -3907,7 +3904,7 @@ inline void gcode_M226() {
3907 3904
       SERIAL_PROTOCOL(servo_index);
3908 3905
       SERIAL_PROTOCOL(": ");
3909 3906
       SERIAL_PROTOCOL(servos[servo_index].read());
3910
-      SERIAL_PROTOCOLLN("");
3907
+      SERIAL_EOL;
3911 3908
     }
3912 3909
   }
3913 3910
 
@@ -3975,7 +3972,7 @@ inline void gcode_M226() {
3975 3972
         //Kc does not have scaling applied above, or in resetting defaults
3976 3973
         SERIAL_PROTOCOL(PID_PARAM(Kc, e));
3977 3974
       #endif
3978
-      SERIAL_PROTOCOLLN("");    
3975
+      SERIAL_EOL;    
3979 3976
     }
3980 3977
     else {
3981 3978
       SERIAL_ECHO_START;
@@ -4000,7 +3997,7 @@ inline void gcode_M226() {
4000 3997
     SERIAL_PROTOCOL(unscalePID_i(bedKi));
4001 3998
     SERIAL_PROTOCOL(" d:");
4002 3999
     SERIAL_PROTOCOL(unscalePID_d(bedKd));
4003
-    SERIAL_PROTOCOLLN("");
4000
+    SERIAL_EOL;
4004 4001
   }
4005 4002
 
4006 4003
 #endif // PIDTEMPBED
@@ -4050,7 +4047,7 @@ inline void gcode_M226() {
4050 4047
     if (code_seen('C')) lcd_setcontrast(code_value_long() & 0x3F);
4051 4048
     SERIAL_PROTOCOLPGM("lcd contrast value: ");
4052 4049
     SERIAL_PROTOCOL(lcd_contrast);
4053
-    SERIAL_PROTOCOLLN("");
4050
+    SERIAL_EOL;
4054 4051
   }
4055 4052
 
4056 4053
 #endif // DOGLCD
@@ -4323,7 +4320,7 @@ inline void gcode_M503() {
4323 4320
         zprobe_zoffset = -value; // compare w/ line 278 of ConfigurationStore.cpp
4324 4321
         SERIAL_ECHO_START;
4325 4322
         SERIAL_ECHOLNPGM(MSG_ZPROBE_ZOFFSET " " MSG_OK);
4326
-        SERIAL_PROTOCOLLN("");
4323
+        SERIAL_EOL;
4327 4324
       }
4328 4325
       else {
4329 4326
         SERIAL_ECHO_START;
@@ -4332,14 +4329,14 @@ inline void gcode_M503() {
4332 4329
         SERIAL_ECHO(Z_PROBE_OFFSET_RANGE_MIN);
4333 4330
         SERIAL_ECHOPGM(MSG_Z_MAX);
4334 4331
         SERIAL_ECHO(Z_PROBE_OFFSET_RANGE_MAX);
4335
-        SERIAL_PROTOCOLLN("");
4332
+        SERIAL_EOL;
4336 4333
       }
4337 4334
     }
4338 4335
     else {
4339 4336
       SERIAL_ECHO_START;
4340 4337
       SERIAL_ECHOLNPGM(MSG_ZPROBE_ZOFFSET " : ");
4341 4338
       SERIAL_ECHO(-zprobe_zoffset);
4342
-      SERIAL_PROTOCOLLN("");
4339
+      SERIAL_EOL;
4343 4340
     }
4344 4341
   }
4345 4342
 
@@ -5693,7 +5690,17 @@ void handle_status_leds(void) {
5693 5690
 }
5694 5691
 #endif
5695 5692
 
5696
-void disable_all_axes() {
5693
+void enable_all_steppers() {
5694
+  enable_x();
5695
+  enable_y();
5696
+  enable_z();
5697
+  enable_e0();
5698
+  enable_e1();
5699
+  enable_e2();
5700
+  enable_e3();
5701
+}
5702
+
5703
+void disable_all_steppers() {
5697 5704
   disable_x();
5698 5705
   disable_y();
5699 5706
   disable_z();
@@ -5721,7 +5728,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
5721 5728
 
5722 5729
   if (stepper_inactive_time && ms > previous_millis_cmd + stepper_inactive_time
5723 5730
       && !ignore_stepper_queue && !blocks_queued())
5724
-    disable_all_axes();
5731
+    disable_all_steppers();
5725 5732
 
5726 5733
   #ifdef CHDK //Check if pin should be set to LOW after M240 set it to HIGH
5727 5734
     if (chdkActive && ms > chdkHigh + CHDK_DELAY) {
@@ -5809,7 +5816,7 @@ void kill()
5809 5816
   cli(); // Stop interrupts
5810 5817
   disable_heater();
5811 5818
 
5812
-  disable_all_axes();
5819
+  disable_all_steppers();
5813 5820
 
5814 5821
   #if HAS_POWER_SWITCH
5815 5822
     pinMode(PS_ON_PIN, INPUT);

+ 3
- 3
Marlin/planner.cpp View File

@@ -614,7 +614,7 @@ float junction_deviation = 0.1;
614 614
         #if EXTRUDERS > 1
615 615
           case 1:
616 616
             enable_e1();
617
-            g_uc_extruder_last_move[1] = BLOCK_BUFFER_SIZE*2;
617
+            g_uc_extruder_last_move[1] = BLOCK_BUFFER_SIZE * 2;
618 618
             if (g_uc_extruder_last_move[0] == 0) disable_e0();
619 619
             #if EXTRUDERS > 2
620 620
               if (g_uc_extruder_last_move[2] == 0) disable_e2();
@@ -626,7 +626,7 @@ float junction_deviation = 0.1;
626 626
           #if EXTRUDERS > 2
627 627
             case 2:
628 628
               enable_e2();
629
-              g_uc_extruder_last_move[2] = BLOCK_BUFFER_SIZE*2;
629
+              g_uc_extruder_last_move[2] = BLOCK_BUFFER_SIZE * 2;
630 630
               if (g_uc_extruder_last_move[0] == 0) disable_e0();
631 631
               if (g_uc_extruder_last_move[1] == 0) disable_e1();
632 632
               #if EXTRUDERS > 3
@@ -636,7 +636,7 @@ float junction_deviation = 0.1;
636 636
             #if EXTRUDERS > 3
637 637
               case 3:
638 638
                 enable_e3();
639
-                g_uc_extruder_last_move[3] = BLOCK_BUFFER_SIZE*2;
639
+                g_uc_extruder_last_move[3] = BLOCK_BUFFER_SIZE * 2;
640 640
                 if (g_uc_extruder_last_move[0] == 0) disable_e0();
641 641
                 if (g_uc_extruder_last_move[1] == 0) disable_e1();
642 642
                 if (g_uc_extruder_last_move[2] == 0) disable_e2();

+ 1
- 7
Marlin/stepper.cpp View File

@@ -1127,13 +1127,7 @@ long st_get_position(uint8_t axis) {
1127 1127
 
1128 1128
 void finishAndDisableSteppers() {
1129 1129
   st_synchronize();
1130
-  disable_x();
1131
-  disable_y();
1132
-  disable_z();
1133
-  disable_e0();
1134
-  disable_e1();
1135
-  disable_e2();
1136
-  disable_e3();
1130
+  disable_all_steppers();
1137 1131
 }
1138 1132
 
1139 1133
 void quickStop() {

+ 76
- 79
Marlin/temperature.cpp View File

@@ -1,5 +1,5 @@
1 1
 /*
2
-  temperature.c - temperature control
2
+  temperature.cpp - temperature control
3 3
   Part of Marlin
4 4
   
5 5
  Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
@@ -16,18 +16,7 @@
16 16
  
17 17
  You should have received a copy of the GNU General Public License
18 18
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
- */
20
-
21
-/*
22
- This firmware is a mashup between Sprinter and grbl.
23
-  (https://github.com/kliment/Sprinter)
24
-  (https://github.com/simen/grbl/tree)
25
- 
26
- It has preliminary support for Matthew Roberts advance algorithm 
27
-    http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
28
-
29
- */
30
-
19
+*/
31 20
 
32 21
 #include "Marlin.h"
33 22
 #include "ultralcd.h"
@@ -87,14 +76,15 @@ unsigned char soft_pwm_bed;
87 76
 #define HAS_HEATER_THERMAL_PROTECTION (defined(THERMAL_RUNAWAY_PROTECTION_PERIOD) && THERMAL_RUNAWAY_PROTECTION_PERIOD > 0)
88 77
 #define HAS_BED_THERMAL_PROTECTION (defined(THERMAL_RUNAWAY_PROTECTION_BED_PERIOD) && THERMAL_RUNAWAY_PROTECTION_BED_PERIOD > 0 && TEMP_SENSOR_BED != 0)
89 78
 #if HAS_HEATER_THERMAL_PROTECTION || HAS_BED_THERMAL_PROTECTION
79
+  enum TRState { TRInactive, TRFirstHeating, TRStable };
90 80
   static bool thermal_runaway = false;
91
-  void thermal_runaway_protection(int *state, unsigned long *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc);
81
+  void thermal_runaway_protection(TRState *state, unsigned long *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc);
92 82
   #if HAS_HEATER_THERMAL_PROTECTION
93
-    static int thermal_runaway_state_machine[4]; // = {0,0,0,0};
83
+    static TRState thermal_runaway_state_machine[4] = { TRInactive, TRInactive, TRInactive, TRInactive };
94 84
     static unsigned long thermal_runaway_timer[4]; // = {0,0,0,0};
95 85
   #endif
96 86
   #if HAS_BED_THERMAL_PROTECTION
97
-    static int thermal_runaway_bed_state_machine;
87
+    static TRState thermal_runaway_bed_state_machine = { TRInactive, TRInactive, TRInactive, TRInactive };
98 88
     static unsigned long thermal_runaway_bed_timer;
99 89
   #endif
100 90
 #endif
@@ -238,7 +228,7 @@ void PID_autotune(float temp, int extruder, int ncycles)
238 228
     soft_pwm[extruder] = bias = d = PID_MAX / 2;
239 229
 
240 230
   // PID Tuning loop
241
-  for(;;) {
231
+  for (;;) {
242 232
 
243 233
     unsigned long ms = millis();
244 234
 
@@ -609,7 +599,7 @@ void manage_heater() {
609 599
   // Loop through all extruders
610 600
   for (int e = 0; e < EXTRUDERS; e++) {
611 601
 
612
-    #if defined (THERMAL_RUNAWAY_PROTECTION_PERIOD) && THERMAL_RUNAWAY_PROTECTION_PERIOD > 0
602
+    #if HAS_HEATER_THERMAL_PROTECTION
613 603
       thermal_runaway_protection(&thermal_runaway_state_machine[e], &thermal_runaway_timer[e], current_temperature[e], target_temperature[e], e, THERMAL_RUNAWAY_PROTECTION_PERIOD, THERMAL_RUNAWAY_PROTECTION_HYSTERESIS);
614 604
     #endif
615 605
 
@@ -637,7 +627,7 @@ void manage_heater() {
637 627
         disable_heater();
638 628
         _temp_error(0, PSTR(MSG_EXTRUDER_SWITCHED_OFF), PSTR(MSG_ERR_REDUNDANT_TEMP));
639 629
       }
640
-    #endif //TEMP_SENSOR_1_AS_REDUNDANT
630
+    #endif // TEMP_SENSOR_1_AS_REDUNDANT
641 631
 
642 632
   } // Extruders Loop
643 633
 
@@ -656,7 +646,7 @@ void manage_heater() {
656 646
   #if TEMP_SENSOR_BED != 0
657 647
   
658 648
     #if HAS_BED_THERMAL_PROTECTION
659
-      thermal_runaway_protection(&thermal_runaway_bed_state_machine, &thermal_runaway_bed_timer, current_temperature_bed, target_temperature_bed, 9, THERMAL_RUNAWAY_PROTECTION_BED_PERIOD, THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS);
649
+      thermal_runaway_protection(&thermal_runaway_bed_state_machine, &thermal_runaway_bed_timer, current_temperature_bed, target_temperature_bed, -1, THERMAL_RUNAWAY_PROTECTION_BED_PERIOD, THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS);
660 650
     #endif
661 651
 
662 652
     #ifdef PIDTEMPBED
@@ -1014,69 +1004,76 @@ void setWatch() {
1014 1004
 }
1015 1005
 
1016 1006
 #if HAS_HEATER_THERMAL_PROTECTION || HAS_BED_THERMAL_PROTECTION
1017
-void thermal_runaway_protection(int *state, unsigned long *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc)
1018
-{
1019
-/*
1020
-      SERIAL_ECHO_START;
1021
-      SERIAL_ECHO("Thermal Thermal Runaway Running. Heater ID:");
1022
-      SERIAL_ECHO(heater_id);
1023
-      SERIAL_ECHO(" ;  State:");
1024
-      SERIAL_ECHO(*state);
1025
-      SERIAL_ECHO(" ;  Timer:");
1026
-      SERIAL_ECHO(*timer);
1027
-      SERIAL_ECHO(" ;  Temperature:");
1028
-      SERIAL_ECHO(temperature);
1029
-      SERIAL_ECHO(" ;  Target Temp:");
1030
-      SERIAL_ECHO(target_temperature);
1031
-      SERIAL_ECHOLN("");    
1032
-*/
1033
-  if ((target_temperature == 0) || thermal_runaway)
1034
-  {
1035
-    *state = 0;
1036
-    *timer = 0;
1037
-    return;
1038
-  }
1039
-  switch (*state)
1040
-  {
1041
-    case 0: // "Heater Inactive" state
1042
-      if (target_temperature > 0) *state = 1;
1043
-      break;
1044
-    case 1: // "First Heating" state
1045
-      if (temperature >= target_temperature) *state = 2;
1046
-      break;
1047
-    case 2: // "Temperature Stable" state
1048
-    {
1049
-      unsigned long ms = millis();
1050
-      if (temperature >= (target_temperature - hysteresis_degc))
1051
-      {
1052
-        *timer = ms;
1053
-      } 
1054
-      else if ( (ms - *timer) > ((unsigned long) period_seconds) * 1000)
1007
+
1008
+  void thermal_runaway_protection(TRState *state, unsigned long *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc) {
1009
+
1010
+    static int tr_target_temperature[EXTRUDERS+1];
1011
+
1012
+    /*
1013
+        SERIAL_ECHO_START;
1014
+        SERIAL_ECHOPGM("Thermal Thermal Runaway Running. Heater ID: ");
1015
+        if (heater_id < 0) SERIAL_ECHOPGM("bed"); else SERIAL_ECHOPGM(heater_id);
1016
+        SERIAL_ECHOPGM(" ;  State:");
1017
+        SERIAL_ECHOPGM(*state);
1018
+        SERIAL_ECHOPGM(" ;  Timer:");
1019
+        SERIAL_ECHOPGM(*timer);
1020
+        SERIAL_ECHOPGM(" ;  Temperature:");
1021
+        SERIAL_ECHOPGM(temperature);
1022
+        SERIAL_ECHOPGM(" ;  Target Temp:");
1023
+        SERIAL_ECHOPGM(target_temperature);
1024
+        SERIAL_EOL;
1025
+    */
1026
+    if (target_temperature == 0 || thermal_runaway) {
1027
+      *state = TRInactive;
1028
+      *timer = 0;
1029
+      return;
1030
+    }
1031
+
1032
+    int heater_index = heater_id >= 0 ? heater_id : EXTRUDERS;
1033
+
1034
+    switch (*state) {
1035
+      // Inactive state waits for a target temperature to be set
1036
+      case TRInactive:
1037
+        if (target_temperature > 0) {
1038
+          *state = TRFirstHeating;
1039
+          tr_target_temperature[heater_index] = target_temperature;
1040
+        }
1041
+        break;
1042
+      // When first heating, wait for the temperature to be reached then go to Stable state
1043
+      case TRFirstHeating:
1044
+        if (temperature >= tr_target_temperature[heater_index]) *state = TRStable;
1045
+        break;
1046
+      // While the temperature is stable watch for a bad temperature
1047
+      case TRStable:
1055 1048
       {
1056
-        SERIAL_ERROR_START;
1057
-        SERIAL_ERRORLNPGM(MSG_THERMAL_RUNAWAY_STOP);
1058
-        SERIAL_ERRORLN((int)heater_id);
1059
-        LCD_ALERTMESSAGEPGM(MSG_THERMAL_RUNAWAY); // translatable
1060
-        thermal_runaway = true;
1061
-        while(1)
1062
-        {
1063
-          disable_heater();
1064
-          disable_x();
1065
-          disable_y();
1066
-          disable_z();
1067
-          disable_e0();
1068
-          disable_e1();
1069
-          disable_e2();
1070
-          disable_e3();
1071
-          manage_heater();
1072
-          lcd_update();
1049
+        // If the target temperature changes, restart
1050
+        if (tr_target_temperature[heater_index] != target_temperature) {
1051
+          *state = TRInactive;
1052
+          break;
1073 1053
         }
1074
-      }
1075
-    } break;
1054
+
1055
+        // 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
+          }
1071
+        }
1072
+      } break;
1073
+    }
1076 1074
   }
1077
-}
1078
-#endif //THERMAL_RUNAWAY_PROTECTION_PERIOD
1079 1075
 
1076
+#endif // HAS_HEATER_THERMAL_PROTECTION || HAS_BED_THERMAL_PROTECTION
1080 1077
 
1081 1078
 void disable_heater() {
1082 1079
   for (int i=0; i<EXTRUDERS; i++) setTargetHotend(0, i);

+ 16
- 30
Marlin/temperature.h View File

@@ -18,8 +18,8 @@
18 18
   along with Grbl.  If not, see <http://www.gnu.org/licenses/>.
19 19
 */
20 20
 
21
-#ifndef temperature_h
22
-#define temperature_h 
21
+#ifndef TEMPERATURE_H
22
+#define TEMPERATURE_H 
23 23
 
24 24
 #include "Marlin.h"
25 25
 #include "planner.h"
@@ -105,40 +105,27 @@ FORCE_INLINE bool isHeatingBed() { return target_temperature_bed > current_tempe
105 105
 FORCE_INLINE bool isCoolingHotend(uint8_t extruder) { return target_temperature[extruder] < current_temperature[extruder]; }
106 106
 FORCE_INLINE bool isCoolingBed() { return target_temperature_bed < current_temperature_bed; }
107 107
 
108
-#define degHotend0() degHotend(0)
109
-#define degTargetHotend0() degTargetHotend(0)
110
-#define setTargetHotend0(_celsius) setTargetHotend((_celsius), 0)
111
-#define isHeatingHotend0() isHeatingHotend(0)
112
-#define isCoolingHotend0() isCoolingHotend(0)
108
+#define HOTEND_ROUTINES(NR) \
109
+  FORCE_INLINE float degHotend##NR() { return degHotend(NR); } \
110
+  FORCE_INLINE float degTargetHotend##NR() { return degTargetHotend(NR); } \
111
+  FORCE_INLINE void setTargetHotend##NR(const float c) { setTargetHotend(c, NR); } \
112
+  FORCE_INLINE bool isHeatingHotend##NR() { return isHeatingHotend(NR); } \
113
+  FORCE_INLINE bool isCoolingHotend##NR() { return isCoolingHotend(NR); }
114
+HOTEND_ROUTINES(0);
113 115
 #if EXTRUDERS > 1
114
-  #define degHotend1() degHotend(1)
115
-  #define degTargetHotend1() degTargetHotend(1)
116
-  #define setTargetHotend1(_celsius) setTargetHotend((_celsius), 1)
117
-  #define isHeatingHotend1() isHeatingHotend(1)
118
-  #define isCoolingHotend1() isCoolingHotend(1)
116
+  HOTEND_ROUTINES(1);
119 117
 #else
120
-  #define setTargetHotend1(_celsius) do{}while(0)
118
+  #define setTargetHotend1(c) do{}while(0)
121 119
 #endif
122 120
 #if EXTRUDERS > 2
123
-  #define degHotend2() degHotend(2)
124
-  #define degTargetHotend2() degTargetHotend(2)
125
-  #define setTargetHotend2(_celsius) setTargetHotend((_celsius), 2)
126
-  #define isHeatingHotend2() isHeatingHotend(2)
127
-  #define isCoolingHotend2() isCoolingHotend(2)
121
+  HOTEND_ROUTINES(2);
128 122
 #else
129
-  #define setTargetHotend2(_celsius) do{}while(0)
123
+  #define setTargetHotend2(c) do{}while(0)
130 124
 #endif
131 125
 #if EXTRUDERS > 3
132
-  #define degHotend3() degHotend(3)
133
-  #define degTargetHotend3() degTargetHotend(3)
134
-  #define setTargetHotend3(_celsius) setTargetHotend((_celsius), 3)
135
-  #define isHeatingHotend3() isHeatingHotend(3)
136
-  #define isCoolingHotend3() isCoolingHotend(3)
126
+  HOTEND_ROUTINES(3);
137 127
 #else
138
-  #define setTargetHotend3(_celsius) do{}while(0)
139
-#endif
140
-#if EXTRUDERS > 4
141
-  #error Invalid number of extruders
128
+  #define setTargetHotend3(c) do{}while(0)
142 129
 #endif
143 130
 
144 131
 int getHeaterPower(int heater);
@@ -161,5 +148,4 @@ FORCE_INLINE void autotempShutdown() {
161 148
   #endif
162 149
 }
163 150
 
164
-
165
-#endif
151
+#endif // TEMPERATURE_H

Loading…
Cancel
Save