Browse Source

Use temp_info_t for temp_redundant (#21715)

Fixes #21712

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
ellensp 4 years ago
parent
commit
5f9aac2027
No account linked to committer's email address
2 changed files with 41 additions and 38 deletions
  1. 24
    25
      Marlin/src/module/temperature.cpp
  2. 17
    13
      Marlin/src/module/temperature.h

+ 24
- 25
Marlin/src/module/temperature.cpp View File

@@ -256,7 +256,11 @@ const char str_t_thermal_runaway[] PROGMEM = STR_T_THERMAL_RUNAWAY,
256 256
 #endif
257 257
 
258 258
 #if HAS_HOTEND
259
-  hotend_info_t Temperature::temp_hotend[HOTEND_TEMPS]; // = { 0 }
259
+  hotend_info_t Temperature::temp_hotend[HOTENDS];
260
+  #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
261
+    temp_info_t Temperature::temp_redundant;
262
+  #endif
263
+  #define _HMT(N) HEATER_##N##_MAXTEMP,
260 264
   const celsius_t Temperature::hotend_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP, HEATER_5_MAXTEMP, HEATER_6_MAXTEMP, HEATER_7_MAXTEMP);
261 265
 #endif
262 266
 
@@ -420,11 +424,6 @@ const char str_t_thermal_runaway[] PROGMEM = STR_T_THERMAL_RUNAWAY,
420 424
   bool Temperature::inited = false;
421 425
 #endif
422 426
 
423
-#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
424
-  int16_t Temperature::redundant_temperature_raw = 0;
425
-  celsius_float_t Temperature::redundant_temperature = 0.0;
426
-#endif
427
-
428 427
 volatile bool Temperature::raw_temps_ready = false;
429 428
 
430 429
 #if ENABLED(PID_EXTRUSION_SCALING)
@@ -1225,12 +1224,12 @@ void Temperature::manage_heater() {
1225 1224
 
1226 1225
   #if DISABLED(IGNORE_THERMOCOUPLE_ERRORS)
1227 1226
     #if TEMP_SENSOR_0_IS_MAX_TC
1228
-      if (temp_hotend[0].celsius > _MIN(HEATER_0_MAXTEMP, TEMP_SENSOR_0_MAX_TC_TMAX - 1.0)) max_temp_error(H_E0);
1229
-      if (temp_hotend[0].celsius < _MAX(HEATER_0_MINTEMP, TEMP_SENSOR_0_MAX_TC_TMIN + .01)) min_temp_error(H_E0);
1227
+      if (degHotend(0) > _MIN(HEATER_0_MAXTEMP, TEMP_SENSOR_0_MAX_TC_TMAX - 1.0)) max_temp_error(H_E0);
1228
+      if (degHotend(0) < _MAX(HEATER_0_MINTEMP, TEMP_SENSOR_0_MAX_TC_TMIN + .01)) min_temp_error(H_E0);
1230 1229
     #endif
1231 1230
     #if TEMP_SENSOR_1_IS_MAX_TC
1232
-      if (temp_hotend[1].celsius > _MIN(HEATER_1_MAXTEMP, TEMP_SENSOR_1_MAX_TC_TMAX - 1.0)) max_temp_error(H_E1);
1233
-      if (temp_hotend[1].celsius < _MAX(HEATER_1_MINTEMP, TEMP_SENSOR_1_MAX_TC_TMIN + .01)) min_temp_error(H_E1);
1231
+      if (TERN(TEMP_SENSOR_1_AS_REDUNDANT, degHotendRedundant(), degHotend(1)) > _MIN(HEATER_1_MAXTEMP, TEMP_SENSOR_1_MAX_TC_TMAX - 1.0)) max_temp_error(H_E1);
1232
+      if (TERN(TEMP_SENSOR_1_AS_REDUNDANT, degHotendRedundant(), degHotend(1)) < _MAX(HEATER_1_MINTEMP, TEMP_SENSOR_1_MAX_TC_TMIN + .01)) min_temp_error(H_E1);
1234 1233
     #endif
1235 1234
   #endif
1236 1235
 
@@ -1266,7 +1265,7 @@ void Temperature::manage_heater() {
1266 1265
 
1267 1266
       #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
1268 1267
         // Make sure measured temperatures are close together
1269
-        if (ABS(temp_hotend[0].celsius - redundant_temperature) > MAX_REDUNDANT_TEMP_SENSOR_DIFF)
1268
+        if (ABS(degHotend(0) - degHotendRedundant()) > MAX_REDUNDANT_TEMP_SENSOR_DIFF)
1270 1269
           _temp_error(H_E0, PSTR(STR_REDUNDANCY), GET_TEXT(MSG_ERR_REDUNDANT_TEMP));
1271 1270
       #endif
1272 1271
 
@@ -1668,7 +1667,7 @@ void Temperature::manage_heater() {
1668 1667
     SERIAL_EOL();
1669 1668
   }
1670 1669
 
1671
-  celsius_float_t Temperature::user_thermistor_to_deg_c(const uint8_t t_index, const int raw) {
1670
+  celsius_float_t Temperature::user_thermistor_to_deg_c(const uint8_t t_index, const int16_t raw) {
1672 1671
     //#if (MOTHERBOARD == BOARD_RAMPS_14_EFB)
1673 1672
     //  static uint32_t clocks_total = 0;
1674 1673
     //  static uint32_t calls = 0;
@@ -1717,8 +1716,8 @@ void Temperature::manage_heater() {
1717 1716
 #if HAS_HOTEND
1718 1717
   // Derived from RepRap FiveD extruder::getTemperature()
1719 1718
   // For hot end temperature measurement.
1720
-  celsius_float_t Temperature::analog_to_celsius_hotend(const int raw, const uint8_t e) {
1721
-      if (e > HOTENDS - DISABLED(TEMP_SENSOR_1_AS_REDUNDANT)) {
1719
+  celsius_float_t Temperature::analog_to_celsius_hotend(const int16_t raw, const uint8_t e) {
1720
+      if (e >= HOTENDS + ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)) {
1722 1721
         SERIAL_ERROR_START();
1723 1722
         SERIAL_ECHO(e);
1724 1723
         SERIAL_ECHOLNPGM(STR_INVALID_EXTRUDER_NUM);
@@ -1826,7 +1825,7 @@ void Temperature::manage_heater() {
1826 1825
 
1827 1826
 #if HAS_HEATED_BED
1828 1827
   // For bed temperature measurement.
1829
-  celsius_float_t Temperature::analog_to_celsius_bed(const int raw) {
1828
+  celsius_float_t Temperature::analog_to_celsius_bed(const int16_t raw) {
1830 1829
     #if TEMP_SENSOR_BED_IS_CUSTOM
1831 1830
       return user_thermistor_to_deg_c(CTI_BED, raw);
1832 1831
     #elif TEMP_SENSOR_BED_IS_THERMISTOR
@@ -1844,7 +1843,7 @@ void Temperature::manage_heater() {
1844 1843
 
1845 1844
 #if HAS_TEMP_CHAMBER
1846 1845
   // For chamber temperature measurement.
1847
-  celsius_float_t Temperature::analog_to_celsius_chamber(const int raw) {
1846
+  celsius_float_t Temperature::analog_to_celsius_chamber(const int16_t raw) {
1848 1847
     #if TEMP_SENSOR_CHAMBER_IS_CUSTOM
1849 1848
       return user_thermistor_to_deg_c(CTI_CHAMBER, raw);
1850 1849
     #elif TEMP_SENSOR_CHAMBER_IS_THERMISTOR
@@ -1862,7 +1861,7 @@ void Temperature::manage_heater() {
1862 1861
 
1863 1862
 #if HAS_TEMP_COOLER
1864 1863
   // For cooler temperature measurement.
1865
-  celsius_float_t Temperature::analog_to_celsius_cooler(const int raw) {
1864
+  celsius_float_t Temperature::analog_to_celsius_cooler(const int16_t raw) {
1866 1865
     #if TEMP_SENSOR_COOLER_IS_CUSTOM
1867 1866
       return user_thermistor_to_deg_c(CTI_COOLER, raw);
1868 1867
     #elif TEMP_SENSOR_COOLER_IS_THERMISTOR
@@ -1880,7 +1879,7 @@ void Temperature::manage_heater() {
1880 1879
 
1881 1880
 #if HAS_TEMP_PROBE
1882 1881
   // For probe temperature measurement.
1883
-  celsius_float_t Temperature::analog_to_celsius_probe(const int raw) {
1882
+  celsius_float_t Temperature::analog_to_celsius_probe(const int16_t raw) {
1884 1883
     #if TEMP_SENSOR_PROBE_IS_CUSTOM
1885 1884
       return user_thermistor_to_deg_c(CTI_PROBE, raw);
1886 1885
     #elif TEMP_SENSOR_PROBE_IS_THERMISTOR
@@ -1904,15 +1903,15 @@ void Temperature::manage_heater() {
1904 1903
  */
1905 1904
 void Temperature::updateTemperaturesFromRawValues() {
1906 1905
   TERN_(TEMP_SENSOR_0_IS_MAX_TC, temp_hotend[0].raw = READ_MAX_TC(0));
1907
-  TERN_(TEMP_SENSOR_1_IS_MAX_TC, temp_hotend[1].raw = READ_MAX_TC(1));
1906
+  TERN_(TEMP_SENSOR_1_IS_MAX_TC, TERN(TEMP_SENSOR_1_AS_REDUNDANT, temp_redundant, temp_hotend[1]).raw = READ_MAX_TC(1));
1908 1907
   #if HAS_HOTEND
1909 1908
     HOTEND_LOOP() temp_hotend[e].celsius = analog_to_celsius_hotend(temp_hotend[e].raw, e);
1910 1909
   #endif
1910
+  TERN_(TEMP_SENSOR_1_AS_REDUNDANT, temp_redundant.celsius = analog_to_celsius_hotend(temp_redundant.raw, 1));
1911 1911
   TERN_(HAS_HEATED_BED, temp_bed.celsius = analog_to_celsius_bed(temp_bed.raw));
1912 1912
   TERN_(HAS_TEMP_CHAMBER, temp_chamber.celsius = analog_to_celsius_chamber(temp_chamber.raw));
1913 1913
   TERN_(HAS_TEMP_COOLER, temp_cooler.celsius = analog_to_celsius_cooler(temp_cooler.raw));
1914 1914
   TERN_(HAS_TEMP_PROBE, temp_probe.celsius = analog_to_celsius_probe(temp_probe.raw));
1915
-  TERN_(TEMP_SENSOR_1_AS_REDUNDANT, redundant_temperature = analog_to_celsius_hotend(redundant_temperature_raw, 1));
1916 1915
   TERN_(FILAMENT_WIDTH_SENSOR, filwidth.update_measured_mm());
1917 1916
   TERN_(HAS_POWER_MONITOR, power_monitor.capture_values());
1918 1917
 
@@ -2707,7 +2706,7 @@ void Temperature::update_raw_temperatures() {
2707 2706
 
2708 2707
   #if HAS_TEMP_ADC_1
2709 2708
     #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
2710
-      redundant_temperature_raw = temp_hotend[1].acc;
2709
+      temp_redundant.update();
2711 2710
     #elif !TEMP_SENSOR_1_IS_MAX_TC
2712 2711
       temp_hotend[1].update();
2713 2712
     #endif
@@ -2741,7 +2740,7 @@ void Temperature::readings_ready() {
2741 2740
 
2742 2741
   #if HAS_HOTEND
2743 2742
     HOTEND_LOOP() temp_hotend[e].reset();
2744
-    TERN_(TEMP_SENSOR_1_AS_REDUNDANT, temp_hotend[1].reset());
2743
+    TERN_(TEMP_SENSOR_1_AS_REDUNDANT, temp_redundant.reset());
2745 2744
   #endif
2746 2745
 
2747 2746
   TERN_(HAS_HEATED_BED, temp_bed.reset());
@@ -3245,7 +3244,7 @@ void Temperature::isr() {
3245 3244
 
3246 3245
     #if HAS_TEMP_ADC_1
3247 3246
       case PrepareTemp_1: HAL_START_ADC(TEMP_1_PIN); break;
3248
-      case MeasureTemp_1: ACCUMULATE_ADC(temp_hotend[1]); break;
3247
+      case MeasureTemp_1: ACCUMULATE_ADC(TERN(TEMP_SENSOR_1_AS_REDUNDANT, temp_redundant, temp_hotend[1])); break;
3249 3248
     #endif
3250 3249
 
3251 3250
     #if HAS_TEMP_ADC_2
@@ -3443,9 +3442,9 @@ void Temperature::isr() {
3443 3442
         #endif
3444 3443
       );
3445 3444
       #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
3446
-        if (include_r) print_heater_state(redundant_temperature, degTargetHotend(target_extruder)
3445
+        if (include_r) print_heater_state(degHotendRedundant(), degTargetHotend(0)
3447 3446
           #if ENABLED(SHOW_TEMP_ADC_VALUES)
3448
-            , redundant_temperature_raw
3447
+            , rawHotendTempRedundant()
3449 3448
           #endif
3450 3449
           , H_REDUNDANT
3451 3450
         );

+ 17
- 13
Marlin/src/module/temperature.h View File

@@ -321,8 +321,10 @@ class Temperature {
321 321
   public:
322 322
 
323 323
     #if HAS_HOTEND
324
-      #define HOTEND_TEMPS (HOTENDS + ENABLED(TEMP_SENSOR_1_AS_REDUNDANT))
325
-      static hotend_info_t temp_hotend[HOTEND_TEMPS];
324
+      #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
325
+        static temp_info_t temp_redundant;
326
+      #endif
327
+      static hotend_info_t temp_hotend[HOTENDS];
326 328
       static const celsius_t hotend_maxtemp[HOTENDS];
327 329
       static inline celsius_t hotend_max_target(const uint8_t e) { return hotend_maxtemp[e] - (HOTEND_OVERSHOOT); }
328 330
     #endif
@@ -423,11 +425,6 @@ class Temperature {
423 425
       static hotend_watch_t watch_hotend[HOTENDS];
424 426
     #endif
425 427
 
426
-    #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
427
-      static uint16_t redundant_temperature_raw;
428
-      static celsius_t redundant_temperature;
429
-    #endif
430
-
431 428
     #if ENABLED(PID_EXTRUSION_SCALING)
432 429
       static int32_t last_e_position, lpq[LPQ_MAX_LEN];
433 430
       static lpq_ptr_t lpq_ptr;
@@ -501,7 +498,7 @@ class Temperature {
501 498
       static user_thermistor_t user_thermistor[USER_THERMISTORS];
502 499
       static void log_user_thermistor(const uint8_t t_index, const bool eprom=false);
503 500
       static void reset_user_thermistors();
504
-      static celsius_float_t user_thermistor_to_deg_c(const uint8_t t_index, const int raw);
501
+      static celsius_float_t user_thermistor_to_deg_c(const uint8_t t_index, const int16_t raw);
505 502
       static inline bool set_pull_up_res(int8_t t_index, float value) {
506 503
         //if (!WITHIN(t_index, 0, USER_THERMISTORS - 1)) return false;
507 504
         if (!WITHIN(value, 1, 1000000)) return false;
@@ -529,19 +526,19 @@ class Temperature {
529 526
     #endif
530 527
 
531 528
     #if HAS_HOTEND
532
-      static celsius_float_t analog_to_celsius_hotend(const int raw, const uint8_t e);
529
+      static celsius_float_t analog_to_celsius_hotend(const int16_t raw, const uint8_t e);
533 530
     #endif
534 531
     #if HAS_HEATED_BED
535
-      static celsius_float_t analog_to_celsius_bed(const int raw);
532
+      static celsius_float_t analog_to_celsius_bed(const int16_t raw);
536 533
     #endif
537 534
     #if HAS_TEMP_PROBE
538
-      static celsius_float_t analog_to_celsius_probe(const int raw);
535
+      static celsius_float_t analog_to_celsius_probe(const int16_t raw);
539 536
     #endif
540 537
     #if HAS_TEMP_CHAMBER
541
-      static celsius_float_t analog_to_celsius_chamber(const int raw);
538
+      static celsius_float_t analog_to_celsius_chamber(const int16_t raw);
542 539
     #endif
543 540
     #if HAS_TEMP_COOLER
544
-      static celsius_float_t analog_to_celsius_cooler(const int raw);
541
+      static celsius_float_t analog_to_celsius_cooler(const int16_t raw);
545 542
     #endif
546 543
 
547 544
     #if HAS_FAN
@@ -631,6 +628,10 @@ class Temperature {
631 628
       return TERN0(HAS_HOTEND, temp_hotend[HOTEND_INDEX].celsius);
632 629
     }
633 630
 
631
+    #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
632
+      static inline celsius_float_t degHotendRedundant() { return temp_redundant.celsius; }
633
+    #endif
634
+
634 635
     static inline celsius_t wholeDegHotend(const uint8_t E_NAME) {
635 636
       return TERN0(HAS_HOTEND, static_cast<celsius_t>(temp_hotend[HOTEND_INDEX].celsius + 0.5f));
636 637
     }
@@ -639,6 +640,9 @@ class Temperature {
639 640
       static inline int16_t rawHotendTemp(const uint8_t E_NAME) {
640 641
         return TERN0(HAS_HOTEND, temp_hotend[HOTEND_INDEX].raw);
641 642
       }
643
+      #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
644
+        static inline int16_t rawHotendTempRedundant() { return temp_redundant.raw; }
645
+      #endif
642 646
     #endif
643 647
 
644 648
     static inline celsius_t degTargetHotend(const uint8_t E_NAME) {

Loading…
Cancel
Save