Browse Source

Track target temperature separately for each heater

Scott Lahteine 9 years ago
parent
commit
9ba55baa5b
1 changed files with 20 additions and 18 deletions
  1. 20
    18
      Marlin/temperature.cpp

+ 20
- 18
Marlin/temperature.cpp View File

@@ -646,7 +646,7 @@ void manage_heater() {
646 646
   #if TEMP_SENSOR_BED != 0
647 647
   
648 648
     #if HAS_BED_THERMAL_PROTECTION
649
-      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);
650 650
     #endif
651 651
 
652 652
     #ifdef PIDTEMPBED
@@ -1007,21 +1007,21 @@ void setWatch() {
1007 1007
 
1008 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 1009
 
1010
-    static int tr_target_temperature = 0;
1010
+    static int tr_target_temperature[EXTRUDERS+1];
1011 1011
 
1012 1012
     /*
1013 1013
         SERIAL_ECHO_START;
1014
-        SERIAL_ECHO("Thermal Thermal Runaway Running. Heater ID:");
1015
-        SERIAL_ECHO(heater_id);
1016
-        SERIAL_ECHO(" ;  State:");
1017
-        SERIAL_ECHO(*state);
1018
-        SERIAL_ECHO(" ;  Timer:");
1019
-        SERIAL_ECHO(*timer);
1020
-        SERIAL_ECHO(" ;  Temperature:");
1021
-        SERIAL_ECHO(temperature);
1022
-        SERIAL_ECHO(" ;  Target Temp:");
1023
-        SERIAL_ECHO(target_temperature);
1024
-        SERIAL_ECHOLN("");    
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 1025
     */
1026 1026
     if (target_temperature == 0 || thermal_runaway) {
1027 1027
       *state = TRInactive;
@@ -1029,35 +1029,37 @@ void setWatch() {
1029 1029
       return;
1030 1030
     }
1031 1031
 
1032
+    int heater_index = heater_id >= 0 ? heater_id : EXTRUDERS;
1033
+
1032 1034
     switch (*state) {
1033 1035
       // Inactive state waits for a target temperature to be set
1034 1036
       case TRInactive:
1035 1037
         if (target_temperature > 0) {
1036 1038
           *state = TRFirstHeating;
1037
-          tr_target_temperature = target_temperature;
1039
+          tr_target_temperature[heater_index] = target_temperature;
1038 1040
         }
1039 1041
         break;
1040 1042
       // When first heating, wait for the temperature to be reached then go to Stable state
1041 1043
       case TRFirstHeating:
1042
-        if (temperature >= tr_target_temperature) *state = TRStable;
1044
+        if (temperature >= tr_target_temperature[heater_index]) *state = TRStable;
1043 1045
         break;
1044 1046
       // While the temperature is stable watch for a bad temperature
1045 1047
       case TRStable:
1046 1048
       {
1047 1049
         // If the target temperature changes, restart
1048
-        if (tr_target_temperature != target_temperature) {
1050
+        if (tr_target_temperature[heater_index] != target_temperature) {
1049 1051
           *state = TRInactive;
1050 1052
           break;
1051 1053
         }
1052 1054
 
1053 1055
         // If the temperature is over the target (-hysteresis) restart the timer
1054
-        if (temperature >= tr_target_temperature - hysteresis_degc) *timer = millis();
1056
+        if (temperature >= tr_target_temperature[heater_index] - hysteresis_degc) *timer = millis();
1055 1057
 
1056 1058
         // If the timer goes too long without a reset, trigger shutdown
1057 1059
         else if (millis() > *timer + period_seconds * 1000UL) {
1058 1060
           SERIAL_ERROR_START;
1059 1061
           SERIAL_ERRORLNPGM(MSG_THERMAL_RUNAWAY_STOP);
1060
-          SERIAL_ERRORLN((int)heater_id);
1062
+          if (heater_id < 0) SERIAL_ERRORLNPGM("bed"); else SERIAL_ERRORLN(heater_id);
1061 1063
           LCD_ALERTMESSAGEPGM(MSG_THERMAL_RUNAWAY);
1062 1064
           thermal_runaway = true;
1063 1065
           for (;;) {

Loading…
Cancel
Save