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
   #define disable_e3() /* nothing */
179
   #define disable_e3() /* nothing */
180
 #endif
180
 #endif
181
 
181
 
182
+void enable_all_steppers();
183
+void disable_all_steppers();
184
+
182
 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};
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
 //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.
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
 //        Call gcode file : "M32 P !filename#" and return to caller file after finishing (similar to #include).
110
 //        Call gcode file : "M32 P !filename#" and return to caller file after finishing (similar to #include).
111
 //        The '#' is necessary when calling from within sd files, as it stops buffer prereading
111
 //        The '#' is necessary when calling from within sd files, as it stops buffer prereading
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.
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
 // M80  - Turn on Power Supply
114
 // M80  - Turn on Power Supply
114
 // M81  - Turn off Power Supply
115
 // M81  - Turn off Power Supply
115
 // M82  - Set E codes absolute (default)
116
 // M82  - Set E codes absolute (default)
2569
  */
2570
  */
2570
 inline void gcode_M17() {
2571
 inline void gcode_M17() {
2571
   LCD_MESSAGEPGM(MSG_NO_MOVE);
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
 #ifdef SDSUPPORT
2576
 #ifdef SDSUPPORT
3055
 inline void gcode_M105() {
3050
 inline void gcode_M105() {
3056
   if (setTargetedHotend(105)) return;
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
     #if HAS_TEMP_BED
3061
     #if HAS_TEMP_BED
3064
       SERIAL_PROTOCOLPGM(" B:");
3062
       SERIAL_PROTOCOLPGM(" B:");
3065
-      SERIAL_PROTOCOL_F(degBed(),1);
3063
+      SERIAL_PROTOCOL_F(degBed(), 1);
3066
       SERIAL_PROTOCOLPGM(" /");
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
       SERIAL_PROTOCOLPGM(" T");
3068
       SERIAL_PROTOCOLPGM(" T");
3071
-      SERIAL_PROTOCOL(cur_extruder);
3069
+      SERIAL_PROTOCOL(e);
3072
       SERIAL_PROTOCOLPGM(":");
3070
       SERIAL_PROTOCOLPGM(":");
3073
-      SERIAL_PROTOCOL_F(degHotend(cur_extruder),1);
3071
+      SERIAL_PROTOCOL_F(degHotend(e), 1);
3074
       SERIAL_PROTOCOLPGM(" /");
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
     SERIAL_ERROR_START;
3076
     SERIAL_ERROR_START;
3079
     SERIAL_ERRORLNPGM(MSG_ERR_NO_THERMISTORS);
3077
     SERIAL_ERRORLNPGM(MSG_ERR_NO_THERMISTORS);
3080
   #endif
3078
   #endif
3112
     }
3110
     }
3113
   #endif
3111
   #endif
3114
 
3112
 
3115
-  SERIAL_PROTOCOLLN("");
3113
+  SERIAL_EOL;
3116
 }
3114
 }
3117
 
3115
 
3118
 #if HAS_FAN
3116
 #if HAS_FAN
3127
    */
3125
    */
3128
   inline void gcode_M107() { fanSpeed = 0; }
3126
   inline void gcode_M107() { fanSpeed = 0; }
3129
 
3127
 
3130
-#endif //FAN_PIN
3128
+#endif // HAS_FAN
3131
 
3129
 
3132
 /**
3130
 /**
3133
  * M109: Wait for extruder(s) to reach temperature
3131
  * M109: Wait for extruder(s) to reach temperature
3185
             SERIAL_PROTOCOLLN( timetemp );
3183
             SERIAL_PROTOCOLLN( timetemp );
3186
           }
3184
           }
3187
           else {
3185
           else {
3188
-            SERIAL_PROTOCOLLN( "?" );
3186
+            SERIAL_PROTOCOLLNPGM("?");
3189
           }
3187
           }
3190
         #else
3188
         #else
3191
-          SERIAL_PROTOCOLLN("");
3189
+          SERIAL_EOL;
3192
         #endif
3190
         #endif
3193
         timetemp = millis();
3191
         timetemp = millis();
3194
       }
3192
       }
3240
         SERIAL_PROTOCOL((int)active_extruder);
3238
         SERIAL_PROTOCOL((int)active_extruder);
3241
         SERIAL_PROTOCOLPGM(" B:");
3239
         SERIAL_PROTOCOLPGM(" B:");
3242
         SERIAL_PROTOCOL_F(degBed(), 1);
3240
         SERIAL_PROTOCOL_F(degBed(), 1);
3243
-        SERIAL_PROTOCOLLN("");
3241
+        SERIAL_EOL;
3244
       }
3242
       }
3245
       manage_heater();
3243
       manage_heater();
3246
       manage_inactivity();
3244
       manage_inactivity();
3441
   SERIAL_PROTOCOLPGM(" Z:");
3439
   SERIAL_PROTOCOLPGM(" Z:");
3442
   SERIAL_PROTOCOL(float(st_get_position(Z_AXIS))/axis_steps_per_unit[Z_AXIS]);
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
   #ifdef SCARA
3444
   #ifdef SCARA
3447
     SERIAL_PROTOCOLPGM("SCARA Theta:");
3445
     SERIAL_PROTOCOLPGM("SCARA Theta:");
3448
     SERIAL_PROTOCOL(delta[X_AXIS]);
3446
     SERIAL_PROTOCOL(delta[X_AXIS]);
3449
     SERIAL_PROTOCOLPGM("   Psi+Theta:");
3447
     SERIAL_PROTOCOLPGM("   Psi+Theta:");
3450
     SERIAL_PROTOCOL(delta[Y_AXIS]);
3448
     SERIAL_PROTOCOL(delta[Y_AXIS]);
3451
-    SERIAL_PROTOCOLLN("");
3449
+    SERIAL_EOL;
3452
     
3450
     
3453
     SERIAL_PROTOCOLPGM("SCARA Cal - Theta:");
3451
     SERIAL_PROTOCOLPGM("SCARA Cal - Theta:");
3454
     SERIAL_PROTOCOL(delta[X_AXIS]+home_offset[X_AXIS]);
3452
     SERIAL_PROTOCOL(delta[X_AXIS]+home_offset[X_AXIS]);
3455
     SERIAL_PROTOCOLPGM("   Psi+Theta (90):");
3453
     SERIAL_PROTOCOLPGM("   Psi+Theta (90):");
3456
     SERIAL_PROTOCOL(delta[Y_AXIS]-delta[X_AXIS]-90+home_offset[Y_AXIS]);
3454
     SERIAL_PROTOCOL(delta[Y_AXIS]-delta[X_AXIS]-90+home_offset[Y_AXIS]);
3457
-    SERIAL_PROTOCOLLN("");
3455
+    SERIAL_EOL;
3458
     
3456
     
3459
     SERIAL_PROTOCOLPGM("SCARA step Cal - Theta:");
3457
     SERIAL_PROTOCOLPGM("SCARA step Cal - Theta:");
3460
     SERIAL_PROTOCOL(delta[X_AXIS]/90*axis_steps_per_unit[X_AXIS]);
3458
     SERIAL_PROTOCOL(delta[X_AXIS]/90*axis_steps_per_unit[X_AXIS]);
3461
     SERIAL_PROTOCOLPGM("   Psi+Theta:");
3459
     SERIAL_PROTOCOLPGM("   Psi+Theta:");
3462
     SERIAL_PROTOCOL((delta[Y_AXIS]-delta[X_AXIS])/90*axis_steps_per_unit[Y_AXIS]);
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
   #endif
3462
   #endif
3466
 }
3463
 }
3467
 
3464
 
3907
       SERIAL_PROTOCOL(servo_index);
3904
       SERIAL_PROTOCOL(servo_index);
3908
       SERIAL_PROTOCOL(": ");
3905
       SERIAL_PROTOCOL(": ");
3909
       SERIAL_PROTOCOL(servos[servo_index].read());
3906
       SERIAL_PROTOCOL(servos[servo_index].read());
3910
-      SERIAL_PROTOCOLLN("");
3907
+      SERIAL_EOL;
3911
     }
3908
     }
3912
   }
3909
   }
3913
 
3910
 
3975
         //Kc does not have scaling applied above, or in resetting defaults
3972
         //Kc does not have scaling applied above, or in resetting defaults
3976
         SERIAL_PROTOCOL(PID_PARAM(Kc, e));
3973
         SERIAL_PROTOCOL(PID_PARAM(Kc, e));
3977
       #endif
3974
       #endif
3978
-      SERIAL_PROTOCOLLN("");    
3975
+      SERIAL_EOL;    
3979
     }
3976
     }
3980
     else {
3977
     else {
3981
       SERIAL_ECHO_START;
3978
       SERIAL_ECHO_START;
4000
     SERIAL_PROTOCOL(unscalePID_i(bedKi));
3997
     SERIAL_PROTOCOL(unscalePID_i(bedKi));
4001
     SERIAL_PROTOCOL(" d:");
3998
     SERIAL_PROTOCOL(" d:");
4002
     SERIAL_PROTOCOL(unscalePID_d(bedKd));
3999
     SERIAL_PROTOCOL(unscalePID_d(bedKd));
4003
-    SERIAL_PROTOCOLLN("");
4000
+    SERIAL_EOL;
4004
   }
4001
   }
4005
 
4002
 
4006
 #endif // PIDTEMPBED
4003
 #endif // PIDTEMPBED
4050
     if (code_seen('C')) lcd_setcontrast(code_value_long() & 0x3F);
4047
     if (code_seen('C')) lcd_setcontrast(code_value_long() & 0x3F);
4051
     SERIAL_PROTOCOLPGM("lcd contrast value: ");
4048
     SERIAL_PROTOCOLPGM("lcd contrast value: ");
4052
     SERIAL_PROTOCOL(lcd_contrast);
4049
     SERIAL_PROTOCOL(lcd_contrast);
4053
-    SERIAL_PROTOCOLLN("");
4050
+    SERIAL_EOL;
4054
   }
4051
   }
4055
 
4052
 
4056
 #endif // DOGLCD
4053
 #endif // DOGLCD
4323
         zprobe_zoffset = -value; // compare w/ line 278 of ConfigurationStore.cpp
4320
         zprobe_zoffset = -value; // compare w/ line 278 of ConfigurationStore.cpp
4324
         SERIAL_ECHO_START;
4321
         SERIAL_ECHO_START;
4325
         SERIAL_ECHOLNPGM(MSG_ZPROBE_ZOFFSET " " MSG_OK);
4322
         SERIAL_ECHOLNPGM(MSG_ZPROBE_ZOFFSET " " MSG_OK);
4326
-        SERIAL_PROTOCOLLN("");
4323
+        SERIAL_EOL;
4327
       }
4324
       }
4328
       else {
4325
       else {
4329
         SERIAL_ECHO_START;
4326
         SERIAL_ECHO_START;
4332
         SERIAL_ECHO(Z_PROBE_OFFSET_RANGE_MIN);
4329
         SERIAL_ECHO(Z_PROBE_OFFSET_RANGE_MIN);
4333
         SERIAL_ECHOPGM(MSG_Z_MAX);
4330
         SERIAL_ECHOPGM(MSG_Z_MAX);
4334
         SERIAL_ECHO(Z_PROBE_OFFSET_RANGE_MAX);
4331
         SERIAL_ECHO(Z_PROBE_OFFSET_RANGE_MAX);
4335
-        SERIAL_PROTOCOLLN("");
4332
+        SERIAL_EOL;
4336
       }
4333
       }
4337
     }
4334
     }
4338
     else {
4335
     else {
4339
       SERIAL_ECHO_START;
4336
       SERIAL_ECHO_START;
4340
       SERIAL_ECHOLNPGM(MSG_ZPROBE_ZOFFSET " : ");
4337
       SERIAL_ECHOLNPGM(MSG_ZPROBE_ZOFFSET " : ");
4341
       SERIAL_ECHO(-zprobe_zoffset);
4338
       SERIAL_ECHO(-zprobe_zoffset);
4342
-      SERIAL_PROTOCOLLN("");
4339
+      SERIAL_EOL;
4343
     }
4340
     }
4344
   }
4341
   }
4345
 
4342
 
5693
 }
5690
 }
5694
 #endif
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
   disable_x();
5704
   disable_x();
5698
   disable_y();
5705
   disable_y();
5699
   disable_z();
5706
   disable_z();
5721
 
5728
 
5722
   if (stepper_inactive_time && ms > previous_millis_cmd + stepper_inactive_time
5729
   if (stepper_inactive_time && ms > previous_millis_cmd + stepper_inactive_time
5723
       && !ignore_stepper_queue && !blocks_queued())
5730
       && !ignore_stepper_queue && !blocks_queued())
5724
-    disable_all_axes();
5731
+    disable_all_steppers();
5725
 
5732
 
5726
   #ifdef CHDK //Check if pin should be set to LOW after M240 set it to HIGH
5733
   #ifdef CHDK //Check if pin should be set to LOW after M240 set it to HIGH
5727
     if (chdkActive && ms > chdkHigh + CHDK_DELAY) {
5734
     if (chdkActive && ms > chdkHigh + CHDK_DELAY) {
5809
   cli(); // Stop interrupts
5816
   cli(); // Stop interrupts
5810
   disable_heater();
5817
   disable_heater();
5811
 
5818
 
5812
-  disable_all_axes();
5819
+  disable_all_steppers();
5813
 
5820
 
5814
   #if HAS_POWER_SWITCH
5821
   #if HAS_POWER_SWITCH
5815
     pinMode(PS_ON_PIN, INPUT);
5822
     pinMode(PS_ON_PIN, INPUT);

+ 3
- 3
Marlin/planner.cpp View File

614
         #if EXTRUDERS > 1
614
         #if EXTRUDERS > 1
615
           case 1:
615
           case 1:
616
             enable_e1();
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
             if (g_uc_extruder_last_move[0] == 0) disable_e0();
618
             if (g_uc_extruder_last_move[0] == 0) disable_e0();
619
             #if EXTRUDERS > 2
619
             #if EXTRUDERS > 2
620
               if (g_uc_extruder_last_move[2] == 0) disable_e2();
620
               if (g_uc_extruder_last_move[2] == 0) disable_e2();
626
           #if EXTRUDERS > 2
626
           #if EXTRUDERS > 2
627
             case 2:
627
             case 2:
628
               enable_e2();
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
               if (g_uc_extruder_last_move[0] == 0) disable_e0();
630
               if (g_uc_extruder_last_move[0] == 0) disable_e0();
631
               if (g_uc_extruder_last_move[1] == 0) disable_e1();
631
               if (g_uc_extruder_last_move[1] == 0) disable_e1();
632
               #if EXTRUDERS > 3
632
               #if EXTRUDERS > 3
636
             #if EXTRUDERS > 3
636
             #if EXTRUDERS > 3
637
               case 3:
637
               case 3:
638
                 enable_e3();
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
                 if (g_uc_extruder_last_move[0] == 0) disable_e0();
640
                 if (g_uc_extruder_last_move[0] == 0) disable_e0();
641
                 if (g_uc_extruder_last_move[1] == 0) disable_e1();
641
                 if (g_uc_extruder_last_move[1] == 0) disable_e1();
642
                 if (g_uc_extruder_last_move[2] == 0) disable_e2();
642
                 if (g_uc_extruder_last_move[2] == 0) disable_e2();

+ 1
- 7
Marlin/stepper.cpp View File

1127
 
1127
 
1128
 void finishAndDisableSteppers() {
1128
 void finishAndDisableSteppers() {
1129
   st_synchronize();
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
 void quickStop() {
1133
 void quickStop() {

+ 76
- 79
Marlin/temperature.cpp View File

1
 /*
1
 /*
2
-  temperature.c - temperature control
2
+  temperature.cpp - temperature control
3
   Part of Marlin
3
   Part of Marlin
4
   
4
   
5
  Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
5
  Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
16
  
16
  
17
  You should have received a copy of the GNU General Public License
17
  You should have received a copy of the GNU General Public License
18
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
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
 #include "Marlin.h"
21
 #include "Marlin.h"
33
 #include "ultralcd.h"
22
 #include "ultralcd.h"
87
 #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)
88
 #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)
89
 #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 };
90
   static bool thermal_runaway = false;
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
   #if HAS_HEATER_THERMAL_PROTECTION
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
     static unsigned long thermal_runaway_timer[4]; // = {0,0,0,0};
84
     static unsigned long thermal_runaway_timer[4]; // = {0,0,0,0};
95
   #endif
85
   #endif
96
   #if HAS_BED_THERMAL_PROTECTION
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
     static unsigned long thermal_runaway_bed_timer;
88
     static unsigned long thermal_runaway_bed_timer;
99
   #endif
89
   #endif
100
 #endif
90
 #endif
238
     soft_pwm[extruder] = bias = d = PID_MAX / 2;
228
     soft_pwm[extruder] = bias = d = PID_MAX / 2;
239
 
229
 
240
   // PID Tuning loop
230
   // PID Tuning loop
241
-  for(;;) {
231
+  for (;;) {
242
 
232
 
243
     unsigned long ms = millis();
233
     unsigned long ms = millis();
244
 
234
 
609
   // Loop through all extruders
599
   // Loop through all extruders
610
   for (int e = 0; e < EXTRUDERS; e++) {
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
       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);
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
     #endif
604
     #endif
615
 
605
 
637
         disable_heater();
627
         disable_heater();
638
         _temp_error(0, PSTR(MSG_EXTRUDER_SWITCHED_OFF), PSTR(MSG_ERR_REDUNDANT_TEMP));
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
   } // Extruders Loop
632
   } // Extruders Loop
643
 
633
 
656
   #if TEMP_SENSOR_BED != 0
646
   #if TEMP_SENSOR_BED != 0
657
   
647
   
658
     #if HAS_BED_THERMAL_PROTECTION
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
     #endif
650
     #endif
661
 
651
 
662
     #ifdef PIDTEMPBED
652
     #ifdef PIDTEMPBED
1014
 }
1004
 }
1015
 
1005
 
1016
 #if HAS_HEATER_THERMAL_PROTECTION || HAS_BED_THERMAL_PROTECTION
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
 void disable_heater() {
1078
 void disable_heater() {
1082
   for (int i=0; i<EXTRUDERS; i++) setTargetHotend(0, i);
1079
   for (int i=0; i<EXTRUDERS; i++) setTargetHotend(0, i);

+ 16
- 30
Marlin/temperature.h View File

18
   along with Grbl.  If not, see <http://www.gnu.org/licenses/>.
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
 #include "Marlin.h"
24
 #include "Marlin.h"
25
 #include "planner.h"
25
 #include "planner.h"
105
 FORCE_INLINE bool isCoolingHotend(uint8_t extruder) { return target_temperature[extruder] < current_temperature[extruder]; }
105
 FORCE_INLINE bool isCoolingHotend(uint8_t extruder) { return target_temperature[extruder] < current_temperature[extruder]; }
106
 FORCE_INLINE bool isCoolingBed() { return target_temperature_bed < current_temperature_bed; }
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
 #if EXTRUDERS > 1
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
 #else
117
 #else
120
-  #define setTargetHotend1(_celsius) do{}while(0)
118
+  #define setTargetHotend1(c) do{}while(0)
121
 #endif
119
 #endif
122
 #if EXTRUDERS > 2
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
 #else
122
 #else
129
-  #define setTargetHotend2(_celsius) do{}while(0)
123
+  #define setTargetHotend2(c) do{}while(0)
130
 #endif
124
 #endif
131
 #if EXTRUDERS > 3
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
 #else
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
 #endif
129
 #endif
143
 
130
 
144
 int getHeaterPower(int heater);
131
 int getHeaterPower(int heater);
161
   #endif
148
   #endif
162
 }
149
 }
163
 
150
 
164
-
165
-#endif
151
+#endif // TEMPERATURE_H

Loading…
Cancel
Save