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
 #endif
256
 #endif
257
 
257
 
258
 #if HAS_HOTEND
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
   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);
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
 #endif
265
 #endif
262
 
266
 
420
   bool Temperature::inited = false;
424
   bool Temperature::inited = false;
421
 #endif
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
 volatile bool Temperature::raw_temps_ready = false;
427
 volatile bool Temperature::raw_temps_ready = false;
429
 
428
 
430
 #if ENABLED(PID_EXTRUSION_SCALING)
429
 #if ENABLED(PID_EXTRUSION_SCALING)
1225
 
1224
 
1226
   #if DISABLED(IGNORE_THERMOCOUPLE_ERRORS)
1225
   #if DISABLED(IGNORE_THERMOCOUPLE_ERRORS)
1227
     #if TEMP_SENSOR_0_IS_MAX_TC
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
     #endif
1229
     #endif
1231
     #if TEMP_SENSOR_1_IS_MAX_TC
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
     #endif
1233
     #endif
1235
   #endif
1234
   #endif
1236
 
1235
 
1266
 
1265
 
1267
       #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
1266
       #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
1268
         // Make sure measured temperatures are close together
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
           _temp_error(H_E0, PSTR(STR_REDUNDANCY), GET_TEXT(MSG_ERR_REDUNDANT_TEMP));
1269
           _temp_error(H_E0, PSTR(STR_REDUNDANCY), GET_TEXT(MSG_ERR_REDUNDANT_TEMP));
1271
       #endif
1270
       #endif
1272
 
1271
 
1668
     SERIAL_EOL();
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
     //#if (MOTHERBOARD == BOARD_RAMPS_14_EFB)
1671
     //#if (MOTHERBOARD == BOARD_RAMPS_14_EFB)
1673
     //  static uint32_t clocks_total = 0;
1672
     //  static uint32_t clocks_total = 0;
1674
     //  static uint32_t calls = 0;
1673
     //  static uint32_t calls = 0;
1717
 #if HAS_HOTEND
1716
 #if HAS_HOTEND
1718
   // Derived from RepRap FiveD extruder::getTemperature()
1717
   // Derived from RepRap FiveD extruder::getTemperature()
1719
   // For hot end temperature measurement.
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
         SERIAL_ERROR_START();
1721
         SERIAL_ERROR_START();
1723
         SERIAL_ECHO(e);
1722
         SERIAL_ECHO(e);
1724
         SERIAL_ECHOLNPGM(STR_INVALID_EXTRUDER_NUM);
1723
         SERIAL_ECHOLNPGM(STR_INVALID_EXTRUDER_NUM);
1826
 
1825
 
1827
 #if HAS_HEATED_BED
1826
 #if HAS_HEATED_BED
1828
   // For bed temperature measurement.
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
     #if TEMP_SENSOR_BED_IS_CUSTOM
1829
     #if TEMP_SENSOR_BED_IS_CUSTOM
1831
       return user_thermistor_to_deg_c(CTI_BED, raw);
1830
       return user_thermistor_to_deg_c(CTI_BED, raw);
1832
     #elif TEMP_SENSOR_BED_IS_THERMISTOR
1831
     #elif TEMP_SENSOR_BED_IS_THERMISTOR
1844
 
1843
 
1845
 #if HAS_TEMP_CHAMBER
1844
 #if HAS_TEMP_CHAMBER
1846
   // For chamber temperature measurement.
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
     #if TEMP_SENSOR_CHAMBER_IS_CUSTOM
1847
     #if TEMP_SENSOR_CHAMBER_IS_CUSTOM
1849
       return user_thermistor_to_deg_c(CTI_CHAMBER, raw);
1848
       return user_thermistor_to_deg_c(CTI_CHAMBER, raw);
1850
     #elif TEMP_SENSOR_CHAMBER_IS_THERMISTOR
1849
     #elif TEMP_SENSOR_CHAMBER_IS_THERMISTOR
1862
 
1861
 
1863
 #if HAS_TEMP_COOLER
1862
 #if HAS_TEMP_COOLER
1864
   // For cooler temperature measurement.
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
     #if TEMP_SENSOR_COOLER_IS_CUSTOM
1865
     #if TEMP_SENSOR_COOLER_IS_CUSTOM
1867
       return user_thermistor_to_deg_c(CTI_COOLER, raw);
1866
       return user_thermistor_to_deg_c(CTI_COOLER, raw);
1868
     #elif TEMP_SENSOR_COOLER_IS_THERMISTOR
1867
     #elif TEMP_SENSOR_COOLER_IS_THERMISTOR
1880
 
1879
 
1881
 #if HAS_TEMP_PROBE
1880
 #if HAS_TEMP_PROBE
1882
   // For probe temperature measurement.
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
     #if TEMP_SENSOR_PROBE_IS_CUSTOM
1883
     #if TEMP_SENSOR_PROBE_IS_CUSTOM
1885
       return user_thermistor_to_deg_c(CTI_PROBE, raw);
1884
       return user_thermistor_to_deg_c(CTI_PROBE, raw);
1886
     #elif TEMP_SENSOR_PROBE_IS_THERMISTOR
1885
     #elif TEMP_SENSOR_PROBE_IS_THERMISTOR
1904
  */
1903
  */
1905
 void Temperature::updateTemperaturesFromRawValues() {
1904
 void Temperature::updateTemperaturesFromRawValues() {
1906
   TERN_(TEMP_SENSOR_0_IS_MAX_TC, temp_hotend[0].raw = READ_MAX_TC(0));
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
   #if HAS_HOTEND
1907
   #if HAS_HOTEND
1909
     HOTEND_LOOP() temp_hotend[e].celsius = analog_to_celsius_hotend(temp_hotend[e].raw, e);
1908
     HOTEND_LOOP() temp_hotend[e].celsius = analog_to_celsius_hotend(temp_hotend[e].raw, e);
1910
   #endif
1909
   #endif
1910
+  TERN_(TEMP_SENSOR_1_AS_REDUNDANT, temp_redundant.celsius = analog_to_celsius_hotend(temp_redundant.raw, 1));
1911
   TERN_(HAS_HEATED_BED, temp_bed.celsius = analog_to_celsius_bed(temp_bed.raw));
1911
   TERN_(HAS_HEATED_BED, temp_bed.celsius = analog_to_celsius_bed(temp_bed.raw));
1912
   TERN_(HAS_TEMP_CHAMBER, temp_chamber.celsius = analog_to_celsius_chamber(temp_chamber.raw));
1912
   TERN_(HAS_TEMP_CHAMBER, temp_chamber.celsius = analog_to_celsius_chamber(temp_chamber.raw));
1913
   TERN_(HAS_TEMP_COOLER, temp_cooler.celsius = analog_to_celsius_cooler(temp_cooler.raw));
1913
   TERN_(HAS_TEMP_COOLER, temp_cooler.celsius = analog_to_celsius_cooler(temp_cooler.raw));
1914
   TERN_(HAS_TEMP_PROBE, temp_probe.celsius = analog_to_celsius_probe(temp_probe.raw));
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
   TERN_(FILAMENT_WIDTH_SENSOR, filwidth.update_measured_mm());
1915
   TERN_(FILAMENT_WIDTH_SENSOR, filwidth.update_measured_mm());
1917
   TERN_(HAS_POWER_MONITOR, power_monitor.capture_values());
1916
   TERN_(HAS_POWER_MONITOR, power_monitor.capture_values());
1918
 
1917
 
2707
 
2706
 
2708
   #if HAS_TEMP_ADC_1
2707
   #if HAS_TEMP_ADC_1
2709
     #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
2708
     #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
2710
-      redundant_temperature_raw = temp_hotend[1].acc;
2709
+      temp_redundant.update();
2711
     #elif !TEMP_SENSOR_1_IS_MAX_TC
2710
     #elif !TEMP_SENSOR_1_IS_MAX_TC
2712
       temp_hotend[1].update();
2711
       temp_hotend[1].update();
2713
     #endif
2712
     #endif
2741
 
2740
 
2742
   #if HAS_HOTEND
2741
   #if HAS_HOTEND
2743
     HOTEND_LOOP() temp_hotend[e].reset();
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
   #endif
2744
   #endif
2746
 
2745
 
2747
   TERN_(HAS_HEATED_BED, temp_bed.reset());
2746
   TERN_(HAS_HEATED_BED, temp_bed.reset());
3245
 
3244
 
3246
     #if HAS_TEMP_ADC_1
3245
     #if HAS_TEMP_ADC_1
3247
       case PrepareTemp_1: HAL_START_ADC(TEMP_1_PIN); break;
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
     #endif
3248
     #endif
3250
 
3249
 
3251
     #if HAS_TEMP_ADC_2
3250
     #if HAS_TEMP_ADC_2
3443
         #endif
3442
         #endif
3444
       );
3443
       );
3445
       #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
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
           #if ENABLED(SHOW_TEMP_ADC_VALUES)
3446
           #if ENABLED(SHOW_TEMP_ADC_VALUES)
3448
-            , redundant_temperature_raw
3447
+            , rawHotendTempRedundant()
3449
           #endif
3448
           #endif
3450
           , H_REDUNDANT
3449
           , H_REDUNDANT
3451
         );
3450
         );

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

321
   public:
321
   public:
322
 
322
 
323
     #if HAS_HOTEND
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
       static const celsius_t hotend_maxtemp[HOTENDS];
328
       static const celsius_t hotend_maxtemp[HOTENDS];
327
       static inline celsius_t hotend_max_target(const uint8_t e) { return hotend_maxtemp[e] - (HOTEND_OVERSHOOT); }
329
       static inline celsius_t hotend_max_target(const uint8_t e) { return hotend_maxtemp[e] - (HOTEND_OVERSHOOT); }
328
     #endif
330
     #endif
423
       static hotend_watch_t watch_hotend[HOTENDS];
425
       static hotend_watch_t watch_hotend[HOTENDS];
424
     #endif
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
     #if ENABLED(PID_EXTRUSION_SCALING)
428
     #if ENABLED(PID_EXTRUSION_SCALING)
432
       static int32_t last_e_position, lpq[LPQ_MAX_LEN];
429
       static int32_t last_e_position, lpq[LPQ_MAX_LEN];
433
       static lpq_ptr_t lpq_ptr;
430
       static lpq_ptr_t lpq_ptr;
501
       static user_thermistor_t user_thermistor[USER_THERMISTORS];
498
       static user_thermistor_t user_thermistor[USER_THERMISTORS];
502
       static void log_user_thermistor(const uint8_t t_index, const bool eprom=false);
499
       static void log_user_thermistor(const uint8_t t_index, const bool eprom=false);
503
       static void reset_user_thermistors();
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
       static inline bool set_pull_up_res(int8_t t_index, float value) {
502
       static inline bool set_pull_up_res(int8_t t_index, float value) {
506
         //if (!WITHIN(t_index, 0, USER_THERMISTORS - 1)) return false;
503
         //if (!WITHIN(t_index, 0, USER_THERMISTORS - 1)) return false;
507
         if (!WITHIN(value, 1, 1000000)) return false;
504
         if (!WITHIN(value, 1, 1000000)) return false;
529
     #endif
526
     #endif
530
 
527
 
531
     #if HAS_HOTEND
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
     #endif
530
     #endif
534
     #if HAS_HEATED_BED
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
     #endif
533
     #endif
537
     #if HAS_TEMP_PROBE
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
     #endif
536
     #endif
540
     #if HAS_TEMP_CHAMBER
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
     #endif
539
     #endif
543
     #if HAS_TEMP_COOLER
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
     #endif
542
     #endif
546
 
543
 
547
     #if HAS_FAN
544
     #if HAS_FAN
631
       return TERN0(HAS_HOTEND, temp_hotend[HOTEND_INDEX].celsius);
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
     static inline celsius_t wholeDegHotend(const uint8_t E_NAME) {
635
     static inline celsius_t wholeDegHotend(const uint8_t E_NAME) {
635
       return TERN0(HAS_HOTEND, static_cast<celsius_t>(temp_hotend[HOTEND_INDEX].celsius + 0.5f));
636
       return TERN0(HAS_HOTEND, static_cast<celsius_t>(temp_hotend[HOTEND_INDEX].celsius + 0.5f));
636
     }
637
     }
639
       static inline int16_t rawHotendTemp(const uint8_t E_NAME) {
640
       static inline int16_t rawHotendTemp(const uint8_t E_NAME) {
640
         return TERN0(HAS_HOTEND, temp_hotend[HOTEND_INDEX].raw);
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
     #endif
646
     #endif
643
 
647
 
644
     static inline celsius_t degTargetHotend(const uint8_t E_NAME) {
648
     static inline celsius_t degTargetHotend(const uint8_t E_NAME) {

Loading…
Cancel
Save