Browse Source

Fix M303 thermal protection

Scott Lahteine 7 years ago
parent
commit
eae0aea1e0
1 changed files with 28 additions and 14 deletions
  1. 28
    14
      Marlin/src/module/temperature.cpp

+ 28
- 14
Marlin/src/module/temperature.cpp View File

222
     int cycles = 0;
222
     int cycles = 0;
223
     bool heating = true;
223
     bool heating = true;
224
 
224
 
225
-    millis_t temp_ms = millis(), t1 = temp_ms, t2 = temp_ms;
225
+    millis_t next_temp_ms = millis(), t1 = next_temp_ms, t2 = next_temp_ms;
226
     long t_high = 0, t_low = 0;
226
     long t_high = 0, t_low = 0;
227
 
227
 
228
     long bias, d;
228
     long bias, d;
231
     float max = 0, min = 10000;
231
     float max = 0, min = 10000;
232
 
232
 
233
     #if HAS_AUTO_FAN
233
     #if HAS_AUTO_FAN
234
-      next_auto_fan_check_ms = temp_ms + 2500UL;
234
+      next_auto_fan_check_ms = next_temp_ms + 2500UL;
235
     #endif
235
     #endif
236
 
236
 
237
     if (hotend >=
237
     if (hotend >=
271
     // PID Tuning loop
271
     // PID Tuning loop
272
     while (wait_for_heatup) {
272
     while (wait_for_heatup) {
273
 
273
 
274
-      millis_t ms = millis();
274
+      const millis_t ms = millis();
275
 
275
 
276
       if (temp_meas_ready) { // temp sample ready
276
       if (temp_meas_ready) { // temp sample ready
277
         updateTemperaturesFromRawValues();
277
         updateTemperaturesFromRawValues();
386
       #define MAX_OVERSHOOT_PID_AUTOTUNE 20
386
       #define MAX_OVERSHOOT_PID_AUTOTUNE 20
387
       if (input > temp + MAX_OVERSHOOT_PID_AUTOTUNE) {
387
       if (input > temp + MAX_OVERSHOOT_PID_AUTOTUNE) {
388
         SERIAL_PROTOCOLLNPGM(MSG_PID_TEMP_TOO_HIGH);
388
         SERIAL_PROTOCOLLNPGM(MSG_PID_TEMP_TOO_HIGH);
389
-        return;
389
+        break;
390
       }
390
       }
391
       // Every 2 seconds...
391
       // Every 2 seconds...
392
-      if (ELAPSED(ms, temp_ms + 2000UL)) {
392
+      if (ELAPSED(ms, next_temp_ms)) {
393
         #if HAS_TEMP_HOTEND || HAS_TEMP_BED
393
         #if HAS_TEMP_HOTEND || HAS_TEMP_BED
394
           print_heaterstates();
394
           print_heaterstates();
395
           SERIAL_EOL();
395
           SERIAL_EOL();
396
         #endif
396
         #endif
397
 
397
 
398
-        temp_ms = ms;
398
+        next_temp_ms = ms + 2000UL;
399
       } // every 2 seconds
399
       } // every 2 seconds
400
-      // Over 2 minutes?
401
-      if (((ms - t1) + (ms - t2)) > (10L * 60L * 1000L * 2L)) {
400
+      // Timeout after 20 minutes since the last undershoot/overshoot cycle
401
+      if (((ms - t1) + (ms - t2)) > (20L * 60L * 1000L)) {
402
         SERIAL_PROTOCOLLNPGM(MSG_PID_TIMEOUT);
402
         SERIAL_PROTOCOLLNPGM(MSG_PID_TIMEOUT);
403
-        return;
403
+        break;
404
       }
404
       }
405
       if (cycles > ncycles) {
405
       if (cycles > ncycles) {
406
         SERIAL_PROTOCOLLNPGM(MSG_PID_AUTOTUNE_FINISHED);
406
         SERIAL_PROTOCOLLNPGM(MSG_PID_AUTOTUNE_FINISHED);
449
       }
449
       }
450
       lcd_update();
450
       lcd_update();
451
     }
451
     }
452
-    if (!wait_for_heatup) disable_all_heaters();
452
+    disable_all_heaters();
453
   }
453
   }
454
 
454
 
455
 #endif // HAS_PID_HEATING
455
 #endif // HAS_PID_HEATING
2033
 
2033
 
2034
     for (uint8_t e = 0; e < COUNT(temp_dir); e++) {
2034
     for (uint8_t e = 0; e < COUNT(temp_dir); e++) {
2035
       const int16_t tdir = temp_dir[e], rawtemp = current_temperature_raw[e] * tdir;
2035
       const int16_t tdir = temp_dir[e], rawtemp = current_temperature_raw[e] * tdir;
2036
-      if (rawtemp > maxttemp_raw[e] * tdir && target_temperature[e] > 0) max_temp_error(e);
2037
-      if (rawtemp < minttemp_raw[e] * tdir && !is_preheating(e) && target_temperature[e] > 0) {
2036
+      const bool heater_on = 0 <
2037
+        #if ENABLED(PIDTEMP)
2038
+          soft_pwm_amount[e]
2039
+        #else
2040
+          target_temperature[e]
2041
+        #endif
2042
+      ;
2043
+      if (rawtemp > maxttemp_raw[e] * tdir && heater_on) max_temp_error(e);
2044
+      if (rawtemp < minttemp_raw[e] * tdir && !is_preheating(e) && heater_on) {
2038
         #ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
2045
         #ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
2039
           if (++consecutive_low_temperature_error[e] >= MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED)
2046
           if (++consecutive_low_temperature_error[e] >= MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED)
2040
         #endif
2047
         #endif
2052
       #else
2059
       #else
2053
         #define GEBED >=
2060
         #define GEBED >=
2054
       #endif
2061
       #endif
2055
-      if (current_temperature_bed_raw GEBED bed_maxttemp_raw && target_temperature_bed > 0) max_temp_error(-1);
2056
-      if (bed_minttemp_raw GEBED current_temperature_bed_raw && target_temperature_bed > 0) min_temp_error(-1);
2062
+      const bool bed_on = 0 <
2063
+        #if ENABLED(PIDTEMPBED)
2064
+          soft_pwm_amount_bed
2065
+        #else
2066
+          target_temperature_bed
2067
+        #endif
2068
+      ;
2069
+      if (current_temperature_bed_raw GEBED bed_maxttemp_raw && bed_on) max_temp_error(-1);
2070
+      if (bed_minttemp_raw GEBED current_temperature_bed_raw && bed_on) min_temp_error(-1);
2057
     #endif
2071
     #endif
2058
 
2072
 
2059
   } // temp_count >= OVERSAMPLENR
2073
   } // temp_count >= OVERSAMPLENR

Loading…
Cancel
Save