Browse Source

Temperature cleanup

Scott Lahteine 3 years ago
parent
commit
becdac19ea
3 changed files with 61 additions and 106 deletions
  1. 10
    8
      Marlin/src/lcd/tft/touch.cpp
  2. 32
    63
      Marlin/src/module/temperature.cpp
  3. 19
    35
      Marlin/src/module/temperature.h

+ 10
- 8
Marlin/src/lcd/tft/touch.cpp View File

@@ -184,14 +184,16 @@ void Touch::touch(touch_control_t *control) {
184 184
       int8_t heater;
185 185
       heater = control->data;
186 186
       ui.clear_lcd();
187
-      if (heater >= 0) { // HotEnd
188
-        #if HOTENDS == 1
189
-          MenuItem_int3::action((const char *)GET_TEXT_F(MSG_NOZZLE), &thermalManager.temp_hotend[0].target, 0, thermalManager.hotend_max_target(0), []{ thermalManager.start_watching_hotend(0); });
190
-        #else
191
-          MenuItemBase::itemIndex = heater;
192
-          MenuItem_int3::action((const char *)GET_TEXT_F(MSG_NOZZLE_N), &thermalManager.temp_hotend[heater].target, 0, thermalManager.hotend_max_target(heater), []{ thermalManager.start_watching_hotend(MenuItemBase::itemIndex); });
193
-        #endif
194
-      }
187
+      #if HAS_HOTEND
188
+        if (heater >= 0) { // HotEnd
189
+          #if HOTENDS == 1
190
+            MenuItem_int3::action((const char *)GET_TEXT_F(MSG_NOZZLE), &thermalManager.temp_hotend[0].target, 0, thermalManager.hotend_max_target(0), []{ thermalManager.start_watching_hotend(0); });
191
+          #else
192
+            MenuItemBase::itemIndex = heater;
193
+            MenuItem_int3::action((const char *)GET_TEXT_F(MSG_NOZZLE_N), &thermalManager.temp_hotend[heater].target, 0, thermalManager.hotend_max_target(heater), []{ thermalManager.start_watching_hotend(MenuItemBase::itemIndex); });
194
+          #endif
195
+        }
196
+      #endif
195 197
       #if HAS_HEATED_BED
196 198
         else if (heater == H_BED) {
197 199
           MenuItem_int3::action((const char *)GET_TEXT_F(MSG_BED), &thermalManager.temp_bed.target, 0, BED_MAX_TARGET, thermalManager.start_watching_bed);

+ 32
- 63
Marlin/src/module/temperature.cpp View File

@@ -447,11 +447,11 @@ volatile bool Temperature::raw_temps_ready = false;
447 447
   temp_range_t Temperature::temp_range[HOTENDS] = ARRAY_BY_HOTENDS(sensor_heater_0, sensor_heater_1, sensor_heater_2, sensor_heater_3, sensor_heater_4, sensor_heater_5, sensor_heater_6, sensor_heater_7);
448 448
 #endif
449 449
 
450
-#ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
450
+#if MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED > 1
451 451
   uint8_t Temperature::consecutive_low_temperature_error[HOTENDS] = { 0 };
452 452
 #endif
453 453
 
454
-#ifdef MILLISECONDS_PREHEAT_TIME
454
+#if MILLISECONDS_PREHEAT_TIME > 0
455 455
   millis_t Temperature::preheat_end_time[HOTENDS] = { 0 };
456 456
 #endif
457 457
 
@@ -472,7 +472,7 @@ volatile bool Temperature::raw_temps_ready = false;
472 472
 #endif
473 473
 
474 474
 #if ENABLED(PROBING_HEATERS_OFF)
475
-  bool Temperature::paused;
475
+  bool Temperature::paused_for_probing;
476 476
 #endif
477 477
 
478 478
 // public:
@@ -1320,10 +1320,10 @@ void Temperature::manage_heater() {
1320 1320
 
1321 1321
       #if DISABLED(PIDTEMPBED)
1322 1322
         if (PENDING(ms, next_bed_check_ms)
1323
-          && TERN1(PAUSE_CHANGE_REQD, paused == last_pause_state)
1323
+          && TERN1(PAUSE_CHANGE_REQD, paused_for_probing == last_pause_state)
1324 1324
         ) break;
1325 1325
         next_bed_check_ms = ms + BED_CHECK_INTERVAL;
1326
-        TERN_(PAUSE_CHANGE_REQD, last_pause_state = paused);
1326
+        TERN_(PAUSE_CHANGE_REQD, last_pause_state = paused_for_probing);
1327 1327
       #endif
1328 1328
 
1329 1329
       TERN_(HEATER_IDLE_HANDLER, heater_idle[IDLE_INDEX_BED].update(ms));
@@ -1958,9 +1958,30 @@ void Temperature::updateTemperaturesFromRawValues() {
1958 1958
 
1959 1959
 /**
1960 1960
  * Initialize the temperature manager
1961
+ *
1961 1962
  * The manager is implemented by periodic calls to manage_heater()
1963
+ *
1964
+ *  - Init (and disable) SPI thermocouples like MAX6675 and MAX31865
1965
+ *  - Disable RUMBA JTAG to accommodate a thermocouple extension
1966
+ *  - Read-enable thermistors with a read-enable pin
1967
+ *  - Init HEATER and COOLER pins for OUTPUT in OFF state
1968
+ *  - Init the FAN pins as PWM or OUTPUT
1969
+ *  - Init the SPI interface for SPI thermocouples
1970
+ *  - Init ADC according to the HAL
1971
+ *  - Set thermistor pins to analog inputs according to the HAL
1972
+ *  - Start the Temperature ISR timer
1973
+ *  - Init the AUTO FAN pins as PWM or OUTPUT
1974
+ *  - Wait 250ms for temperatures to settle
1975
+ *  - Init temp_range[], used for catching min/maxtemp
1962 1976
  */
1963 1977
 void Temperature::init() {
1978
+
1979
+  TERN_(PROBING_HEATERS_OFF, paused_for_probing = false);
1980
+
1981
+  #if BOTH(PIDTEMP, PID_EXTRUSION_SCALING)
1982
+    last_e_position = 0;
1983
+  #endif
1984
+
1964 1985
   // Init (and disable) SPI thermocouples
1965 1986
   #if TEMP_SENSOR_0_IS_MAX6675 && PIN_EXISTS(MAX6675_CS)
1966 1987
     OUT_WRITE(MAX6675_CS_PIN, HIGH);
@@ -2017,10 +2038,6 @@ void Temperature::init() {
2017 2038
     OUT_WRITE(TEMP_1_TR_ENABLE_PIN, ENABLED(TEMP_SENSOR_1_IS_MAX_TC));
2018 2039
   #endif
2019 2040
 
2020
-  #if BOTH(PIDTEMP, PID_EXTRUSION_SCALING)
2021
-    last_e_position = 0;
2022
-  #endif
2023
-
2024 2041
   #if HAS_HEATER_0
2025 2042
     #ifdef BOARD_OPENDRAIN_MOSFETS
2026 2043
       OUT_WRITE_OD(HEATER_0_PIN, HEATER_0_INVERTING);
@@ -2276,55 +2293,8 @@ void Temperature::init() {
2276 2293
     while (analog_to_celsius_cooler(mintemp_raw_COOLER) > COOLER_MINTEMP) mintemp_raw_COOLER += TEMPDIR(COOLER) * (OVERSAMPLENR);
2277 2294
     while (analog_to_celsius_cooler(maxtemp_raw_COOLER) < COOLER_MAXTEMP) maxtemp_raw_COOLER -= TEMPDIR(COOLER) * (OVERSAMPLENR);
2278 2295
   #endif
2279
-
2280
-  TERN_(PROBING_HEATERS_OFF, paused = false);
2281 2296
 }
2282 2297
 
2283
-#if WATCH_HOTENDS
2284
-  /**
2285
-   * Start Heating Sanity Check for hotends that are below
2286
-   * their target temperature by a configurable margin.
2287
-   * This is called when the temperature is set. (M104, M109)
2288
-   */
2289
-  void Temperature::start_watching_hotend(const uint8_t E_NAME) {
2290
-    const uint8_t ee = HOTEND_INDEX;
2291
-    watch_hotend[ee].restart(degHotend(ee), degTargetHotend(ee));
2292
-  }
2293
-#endif
2294
-
2295
-#if WATCH_BED
2296
-  /**
2297
-   * Start Heating Sanity Check for hotends that are below
2298
-   * their target temperature by a configurable margin.
2299
-   * This is called when the temperature is set. (M140, M190)
2300
-   */
2301
-  void Temperature::start_watching_bed() {
2302
-    watch_bed.restart(degBed(), degTargetBed());
2303
-  }
2304
-#endif
2305
-
2306
-#if WATCH_CHAMBER
2307
-  /**
2308
-   * Start Heating Sanity Check for chamber that is below
2309
-   * its target temperature by a configurable margin.
2310
-   * This is called when the temperature is set. (M141, M191)
2311
-   */
2312
-  void Temperature::start_watching_chamber() {
2313
-    watch_chamber.restart(degChamber(), degTargetChamber());
2314
-  }
2315
-#endif
2316
-
2317
-#if WATCH_COOLER
2318
-  /**
2319
-   * Start Cooling Sanity Check for cooler that is above
2320
-   * its target temperature by a configurable margin.
2321
-   * This is called when the temperature is set. (M143, M193)
2322
-   */
2323
-  void Temperature::start_watching_cooler() {
2324
-    watch_cooler.restart(degCooler(), degTargetCooler());
2325
-  }
2326
-#endif
2327
-
2328 2298
 #if HAS_THERMAL_PROTECTION
2329 2299
 
2330 2300
   Temperature::tr_state_machine_t Temperature::tr_state_machine[NR_HEATER_RUNAWAY]; // = { { TRInactive, 0 } };
@@ -2487,8 +2457,8 @@ void Temperature::disable_all_heaters() {
2487 2457
 #if ENABLED(PROBING_HEATERS_OFF)
2488 2458
 
2489 2459
   void Temperature::pause(const bool p) {
2490
-    if (p != paused) {
2491
-      paused = p;
2460
+    if (p != paused_for_probing) {
2461
+      paused_for_probing = p;
2492 2462
       if (p) {
2493 2463
         HOTEND_LOOP() heater_idle[e].expire();    // Timeout immediately
2494 2464
         TERN_(HAS_HEATED_BED, heater_idle[IDLE_INDEX_BED].expire()); // Timeout immediately
@@ -2773,17 +2743,16 @@ void Temperature::readings_ready() {
2773 2743
       const int8_t tdir = temp_dir[e];
2774 2744
       if (tdir) {
2775 2745
         const int16_t rawtemp = temp_hotend[e].raw * tdir; // normal direction, +rawtemp, else -rawtemp
2776
-        const bool heater_on = (temp_hotend[e].target > 0
2777
-          || TERN0(PIDTEMP, temp_hotend[e].soft_pwm_amount) > 0
2778
-        );
2779 2746
         if (rawtemp > temp_range[e].raw_max * tdir) max_temp_error((heater_id_t)e);
2747
+
2748
+        const bool heater_on = (temp_hotend[e].target > 0 || TERN0(PIDTEMP, temp_hotend[e].soft_pwm_amount > 0));
2780 2749
         if (heater_on && rawtemp < temp_range[e].raw_min * tdir && !is_preheating(e)) {
2781
-          #ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
2750
+          #if MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED > 1
2782 2751
             if (++consecutive_low_temperature_error[e] >= MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED)
2783 2752
           #endif
2784 2753
               min_temp_error((heater_id_t)e);
2785 2754
         }
2786
-        #ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
2755
+        #if MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED > 1
2787 2756
           else
2788 2757
             consecutive_low_temperature_error[e] = 0;
2789 2758
         #endif

+ 19
- 35
Marlin/src/module/temperature.h View File

@@ -462,11 +462,11 @@ class Temperature {
462 462
       static int16_t mintemp_raw_COOLER, maxtemp_raw_COOLER;
463 463
     #endif
464 464
 
465
-    #ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
465
+    #if MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED > 1
466 466
       static uint8_t consecutive_low_temperature_error[HOTENDS];
467 467
     #endif
468 468
 
469
-    #ifdef MILLISECONDS_PREHEAT_TIME
469
+    #if MILLISECONDS_PREHEAT_TIME > 0
470 470
       static millis_t preheat_end_time[HOTENDS];
471 471
     #endif
472 472
 
@@ -475,7 +475,7 @@ class Temperature {
475 475
     #endif
476 476
 
477 477
     #if ENABLED(PROBING_HEATERS_OFF)
478
-      static bool paused;
478
+      static bool paused_for_probing;
479 479
     #endif
480 480
 
481 481
   public:
@@ -610,7 +610,7 @@ class Temperature {
610 610
     /**
611 611
      * Preheating hotends
612 612
      */
613
-    #ifdef MILLISECONDS_PREHEAT_TIME
613
+    #if MILLISECONDS_PREHEAT_TIME > 0
614 614
       static inline bool is_preheating(const uint8_t E_NAME) {
615 615
         return preheat_end_time[HOTEND_INDEX] && PENDING(millis(), preheat_end_time[HOTEND_INDEX]);
616 616
       }
@@ -653,17 +653,11 @@ class Temperature {
653 653
       return TERN0(HAS_HOTEND, temp_hotend[HOTEND_INDEX].target);
654 654
     }
655 655
 
656
-    #if WATCH_HOTENDS
657
-      static void start_watching_hotend(const uint8_t e=0);
658
-    #else
659
-      static inline void start_watching_hotend(const uint8_t=0) {}
660
-    #endif
661
-
662 656
     #if HAS_HOTEND
663 657
 
664 658
       static void setTargetHotend(const celsius_t celsius, const uint8_t E_NAME) {
665 659
         const uint8_t ee = HOTEND_INDEX;
666
-        #ifdef MILLISECONDS_PREHEAT_TIME
660
+        #if MILLISECONDS_PREHEAT_TIME > 0
667 661
           if (celsius == 0)
668 662
             reset_preheat_time(ee);
669 663
           else if (temp_hotend[ee].target == 0)
@@ -702,6 +696,14 @@ class Temperature {
702 696
         return ABS(wholeDegHotend(e) - temp) < (TEMP_HYSTERESIS);
703 697
       }
704 698
 
699
+      // Start watching a Hotend to make sure it's really heating up
700
+      static inline void start_watching_hotend(const uint8_t E_NAME) {
701
+        UNUSED(HOTEND_INDEX);
702
+        #if WATCH_HOTENDS
703
+          watch_hotend[HOTEND_INDEX].restart(degHotend(HOTEND_INDEX), degTargetHotend(HOTEND_INDEX));
704
+        #endif
705
+      }
706
+
705 707
     #endif // HAS_HOTEND
706 708
 
707 709
     #if HAS_HEATED_BED
@@ -715,11 +717,8 @@ class Temperature {
715 717
       static inline bool isHeatingBed()       { return temp_bed.target > temp_bed.celsius; }
716 718
       static inline bool isCoolingBed()       { return temp_bed.target < temp_bed.celsius; }
717 719
 
718
-      #if WATCH_BED
719
-        static void start_watching_bed();
720
-      #else
721
-        static inline void start_watching_bed() {}
722
-      #endif
720
+      // Start watching the Bed to make sure it's really heating up
721
+      static inline void start_watching_bed() { TERN_(WATCH_BED, watch_bed.restart(degBed(), degTargetBed())); }
723 722
 
724 723
       static void setTargetBed(const celsius_t celsius) {
725 724
         TERN_(AUTO_POWER_CONTROL, if (celsius) powerManager.power_on());
@@ -752,12 +751,6 @@ class Temperature {
752 751
       static bool wait_for_probe(const celsius_t target_temp, bool no_wait_for_cooling=true);
753 752
     #endif
754 753
 
755
-    #if WATCH_PROBE
756
-      static void start_watching_probe();
757
-    #else
758
-      static inline void start_watching_probe() {}
759
-    #endif
760
-
761 754
     #if HAS_TEMP_CHAMBER
762 755
       #if ENABLED(SHOW_TEMP_ADC_VALUES)
763 756
         static inline int16_t rawChamberTemp()      { return temp_chamber.raw; }
@@ -772,17 +765,13 @@ class Temperature {
772 765
       #endif
773 766
     #endif
774 767
 
775
-    #if WATCH_CHAMBER
776
-      static void start_watching_chamber();
777
-    #else
778
-      static inline void start_watching_chamber() {}
779
-    #endif
780
-
781 768
     #if HAS_HEATED_CHAMBER
782 769
       static void setTargetChamber(const celsius_t celsius) {
783 770
         temp_chamber.target = _MIN(celsius, CHAMBER_MAX_TARGET);
784 771
         start_watching_chamber();
785 772
       }
773
+      // Start watching the Chamber to make sure it's really heating up
774
+      static inline void start_watching_chamber() { TERN_(WATCH_CHAMBER, watch_chamber.restart(degChamber(), degTargetChamber())); }
786 775
     #endif
787 776
 
788 777
     #if HAS_TEMP_COOLER
@@ -799,17 +788,13 @@ class Temperature {
799 788
       #endif
800 789
     #endif
801 790
 
802
-    #if WATCH_COOLER
803
-      static void start_watching_cooler();
804
-    #else
805
-      static inline void start_watching_cooler() {}
806
-    #endif
807
-
808 791
     #if HAS_COOLER
809 792
       static inline void setTargetCooler(const celsius_t celsius) {
810 793
         temp_cooler.target = constrain(celsius, COOLER_MIN_TARGET, COOLER_MAX_TARGET);
811 794
         start_watching_cooler();
812 795
       }
796
+      // Start watching the Cooler to make sure it's really cooling down
797
+      static inline void start_watching_cooler() { TERN_(WATCH_COOLER, watch_cooler.restart(degCooler(), degTargetCooler())); }
813 798
     #endif
814 799
 
815 800
     /**
@@ -860,7 +845,6 @@ class Temperature {
860 845
 
861 846
     #if ENABLED(PROBING_HEATERS_OFF)
862 847
       static void pause(const bool p);
863
-      static inline bool is_paused() { return paused; }
864 848
     #endif
865 849
 
866 850
     #if HEATER_IDLE_HANDLER

Loading…
Cancel
Save