Преглед на файлове

Merge pull request #4256 from thinkyhead/rc_fix_singlenozzle_temp

Additional tweaks for HOTENDS == 1
Scott Lahteine преди 9 години
родител
ревизия
5b0e46c986
променени са 6 файла, в които са добавени 183 реда и са изтрити 169 реда
  1. 61
    64
      Marlin/M100_Free_Mem_Chk.cpp
  2. 10
    9
      Marlin/Marlin_main.cpp
  3. 8
    8
      Marlin/configuration_store.cpp
  4. 1
    1
      Marlin/dogm_lcd_implementation.h
  5. 65
    58
      Marlin/temperature.cpp
  6. 38
    29
      Marlin/temperature.h

+ 61
- 64
Marlin/M100_Free_Mem_Chk.cpp Целия файл

57
 void prt_hex_word(unsigned int);
57
 void prt_hex_word(unsigned int);
58
 int how_many_E5s_are_here(unsigned char*);
58
 int how_many_E5s_are_here(unsigned char*);
59
 
59
 
60
-
61
-
62
-
63
 void gcode_M100() {
60
 void gcode_M100() {
64
   static int m100_not_initialized = 1;
61
   static int m100_not_initialized = 1;
65
   unsigned char* sp, *ptr;
62
   unsigned char* sp, *ptr;
73
   // probably caused by bad pointers.  Any unexpected values will be flagged in
70
   // probably caused by bad pointers.  Any unexpected values will be flagged in
74
   // the right hand column to help spotting them.
71
   // the right hand column to help spotting them.
75
   //
72
   //
76
-#if ENABLED(M100_FREE_MEMORY_DUMPER) // Disable to remove Dump sub-command
77
-  if (code_seen('D')) {
78
-    ptr = (unsigned char*) __brkval;
79
-    //
80
-    // We want to start and end the dump on a nice 16 byte boundry even though
81
-    // the values we are using are not 16 byte aligned.
82
-    //
83
-    SERIAL_ECHOPGM("\n__brkval : ");
84
-    prt_hex_word((unsigned int) ptr);
85
-    ptr = (unsigned char*)((unsigned long) ptr & 0xfff0);
86
-    sp = top_of_stack();
87
-    SERIAL_ECHOPGM("\nStack Pointer : ");
88
-    prt_hex_word((unsigned int) sp);
89
-    SERIAL_EOL;
90
-    sp = (unsigned char*)((unsigned long) sp | 0x000f);
91
-    n = sp - ptr;
92
-    //
93
-    // This is the main loop of the Dump command.
94
-    //
95
-    while (ptr < sp) {
96
-      prt_hex_word((unsigned int) ptr); // Print the address
97
-      SERIAL_CHAR(':');
98
-      for (i = 0; i < 16; i++) {      // and 16 data bytes
99
-        prt_hex_byte(*(ptr + i));
100
-        SERIAL_CHAR(' ');
101
-        delay(2);
102
-      }
103
-      SERIAL_CHAR('|');         // now show where non 0xE5's are
104
-      for (i = 0; i < 16; i++) {
105
-        delay(2);
106
-        if (*(ptr + i) == 0xe5)
73
+  #if ENABLED(M100_FREE_MEMORY_DUMPER) // Disable to remove Dump sub-command
74
+    if (code_seen('D')) {
75
+      ptr = (unsigned char*) __brkval;
76
+      //
77
+      // We want to start and end the dump on a nice 16 byte boundry even though
78
+      // the values we are using are not 16 byte aligned.
79
+      //
80
+      SERIAL_ECHOPGM("\n__brkval : ");
81
+      prt_hex_word((unsigned int) ptr);
82
+      ptr = (unsigned char*)((unsigned long) ptr & 0xfff0);
83
+      sp = top_of_stack();
84
+      SERIAL_ECHOPGM("\nStack Pointer : ");
85
+      prt_hex_word((unsigned int) sp);
86
+      SERIAL_EOL;
87
+      sp = (unsigned char*)((unsigned long) sp | 0x000f);
88
+      n = sp - ptr;
89
+      //
90
+      // This is the main loop of the Dump command.
91
+      //
92
+      while (ptr < sp) {
93
+        prt_hex_word((unsigned int) ptr); // Print the address
94
+        SERIAL_CHAR(':');
95
+        for (i = 0; i < 16; i++) {      // and 16 data bytes
96
+          prt_hex_byte(*(ptr + i));
107
           SERIAL_CHAR(' ');
97
           SERIAL_CHAR(' ');
108
-        else
109
-          SERIAL_CHAR('?');
98
+          delay(2);
99
+        }
100
+        SERIAL_CHAR('|');         // now show where non 0xE5's are
101
+        for (i = 0; i < 16; i++) {
102
+          delay(2);
103
+          if (*(ptr + i) == 0xe5)
104
+            SERIAL_CHAR(' ');
105
+          else
106
+            SERIAL_CHAR('?');
107
+        }
108
+        SERIAL_EOL;
109
+        ptr += 16;
110
+        delay(2);
110
       }
111
       }
111
-      SERIAL_EOL;
112
-      ptr += 16;
113
-      delay(2);
112
+      SERIAL_ECHOLNPGM("Done.");
113
+      return;
114
     }
114
     }
115
-    SERIAL_ECHOLNPGM("Done.");
116
-    return;
117
-  }
118
-#endif
115
+  #endif
119
   //
116
   //
120
   // M100 F   requests the code to return the number of free bytes in the memory pool along with
117
   // M100 F   requests the code to return the number of free bytes in the memory pool along with
121
   // other vital statistics that define the memory pool.
118
   // other vital statistics that define the memory pool.
158
   // M100 C x  Corrupts x locations in the free memory pool and reports the locations of the corruption.
155
   // M100 C x  Corrupts x locations in the free memory pool and reports the locations of the corruption.
159
   // This is useful to check the correctness of the M100 D and the M100 F commands.
156
   // This is useful to check the correctness of the M100 D and the M100 F commands.
160
   //
157
   //
161
-#if ENABLED(M100_FREE_MEMORY_CORRUPTOR)
162
-  if (code_seen('C')) {
163
-    int x = code_value_int(); // x gets the # of locations to corrupt within the memory pool
164
-    SERIAL_ECHOLNPGM("Corrupting free memory block.\n");
165
-    ptr = (unsigned char*) __brkval;
166
-    SERIAL_ECHOPAIR("\n__brkval : ", ptr);
167
-    ptr += 8;
168
-    sp = top_of_stack();
169
-    SERIAL_ECHOPAIR("\nStack Pointer : ", sp);
170
-    SERIAL_ECHOLNPGM("\n");
171
-    n = sp - ptr - 64;    // -64 just to keep us from finding interrupt activity that
172
-    // has altered the stack.
173
-    j = n / (x + 1);
174
-    for (i = 1; i <= x; i++) {
175
-      *(ptr + (i * j)) = i;
176
-      SERIAL_ECHOPGM("\nCorrupting address: 0x");
177
-      prt_hex_word((unsigned int)(ptr + (i * j)));
158
+  #if ENABLED(M100_FREE_MEMORY_CORRUPTOR)
159
+    if (code_seen('C')) {
160
+      int x = code_value_int(); // x gets the # of locations to corrupt within the memory pool
161
+      SERIAL_ECHOLNPGM("Corrupting free memory block.\n");
162
+      ptr = (unsigned char*) __brkval;
163
+      SERIAL_ECHOPAIR("\n__brkval : ", ptr);
164
+      ptr += 8;
165
+      sp = top_of_stack();
166
+      SERIAL_ECHOPAIR("\nStack Pointer : ", sp);
167
+      SERIAL_ECHOLNPGM("\n");
168
+      n = sp - ptr - 64;    // -64 just to keep us from finding interrupt activity that
169
+      // has altered the stack.
170
+      j = n / (x + 1);
171
+      for (i = 1; i <= x; i++) {
172
+        *(ptr + (i * j)) = i;
173
+        SERIAL_ECHOPGM("\nCorrupting address: 0x");
174
+        prt_hex_word((unsigned int)(ptr + (i * j)));
175
+      }
176
+      SERIAL_ECHOLNPGM("\n");
177
+      return;
178
     }
178
     }
179
-    SERIAL_ECHOLNPGM("\n");
180
-    return;
181
-  }
182
-#endif
179
+  #endif
183
   //
180
   //
184
   // M100 I    Initializes the free memory pool so it can be watched and prints vital
181
   // M100 I    Initializes the free memory pool so it can be watched and prints vital
185
   // statistics that define the free memory pool.
182
   // statistics that define the free memory pool.

+ 10
- 9
Marlin/Marlin_main.cpp Целия файл

4365
       SERIAL_PROTOCOL_F(thermalManager.degTargetBed(), 1);
4365
       SERIAL_PROTOCOL_F(thermalManager.degTargetBed(), 1);
4366
     #endif
4366
     #endif
4367
     #if HOTENDS > 1
4367
     #if HOTENDS > 1
4368
-      for (int8_t e = 0; e < HOTENDS; ++e) {
4368
+      HOTEND_LOOP() {
4369
         SERIAL_PROTOCOLPGM(" T");
4369
         SERIAL_PROTOCOLPGM(" T");
4370
         SERIAL_PROTOCOL(e);
4370
         SERIAL_PROTOCOL(e);
4371
         SERIAL_PROTOCOLCHAR(':');
4371
         SERIAL_PROTOCOLCHAR(':');
4391
       SERIAL_PROTOCOL(thermalManager.getHeaterPower(target_extruder));
4391
       SERIAL_PROTOCOL(thermalManager.getHeaterPower(target_extruder));
4392
     #endif
4392
     #endif
4393
     #if HOTENDS > 1
4393
     #if HOTENDS > 1
4394
-      for (int8_t e = 0; e < HOTENDS; ++e) {
4394
+      HOTEND_LOOP() {
4395
         SERIAL_PROTOCOLPGM(" @");
4395
         SERIAL_PROTOCOLPGM(" @");
4396
         SERIAL_PROTOCOL(e);
4396
         SERIAL_PROTOCOL(e);
4397
         SERIAL_PROTOCOLCHAR(':');
4397
         SERIAL_PROTOCOLCHAR(':');
4410
         SERIAL_PROTOCOLPGM("C->");
4410
         SERIAL_PROTOCOLPGM("C->");
4411
         SERIAL_PROTOCOL_F(thermalManager.rawBedTemp() / OVERSAMPLENR, 0);
4411
         SERIAL_PROTOCOL_F(thermalManager.rawBedTemp() / OVERSAMPLENR, 0);
4412
       #endif
4412
       #endif
4413
-      for (int8_t cur_hotend = 0; cur_hotend < HOTENDS; ++cur_hotend) {
4413
+      HOTEND_LOOP() {
4414
         SERIAL_PROTOCOLPGM("  T");
4414
         SERIAL_PROTOCOLPGM("  T");
4415
-        SERIAL_PROTOCOL(cur_hotend);
4415
+        SERIAL_PROTOCOL(e);
4416
         SERIAL_PROTOCOLCHAR(':');
4416
         SERIAL_PROTOCOLCHAR(':');
4417
-        SERIAL_PROTOCOL_F(thermalManager.degHotend(cur_hotend), 1);
4417
+        SERIAL_PROTOCOL_F(thermalManager.degHotend(e), 1);
4418
         SERIAL_PROTOCOLPGM("C->");
4418
         SERIAL_PROTOCOLPGM("C->");
4419
-        SERIAL_PROTOCOL_F(thermalManager.rawHotendTemp(cur_hotend) / OVERSAMPLENR, 0);
4419
+        SERIAL_PROTOCOL_F(thermalManager.rawHotendTemp(e) / OVERSAMPLENR, 0);
4420
       }
4420
       }
4421
     #endif
4421
     #endif
4422
   }
4422
   }
5436
 
5436
 
5437
     SERIAL_ECHO_START;
5437
     SERIAL_ECHO_START;
5438
     SERIAL_ECHOPGM(MSG_HOTEND_OFFSET);
5438
     SERIAL_ECHOPGM(MSG_HOTEND_OFFSET);
5439
-    for (int e = 0; e < HOTENDS; e++) {
5439
+    HOTEND_LOOP() {
5440
       SERIAL_CHAR(' ');
5440
       SERIAL_CHAR(' ');
5441
       SERIAL_ECHO(hotend_offset[X_AXIS][e]);
5441
       SERIAL_ECHO(hotend_offset[X_AXIS][e]);
5442
       SERIAL_CHAR(',');
5442
       SERIAL_CHAR(',');
7968
     float max_temp = 0.0;
7968
     float max_temp = 0.0;
7969
     if (ELAPSED(millis(), next_status_led_update_ms)) {
7969
     if (ELAPSED(millis(), next_status_led_update_ms)) {
7970
       next_status_led_update_ms += 500; // Update every 0.5s
7970
       next_status_led_update_ms += 500; // Update every 0.5s
7971
-      for (int8_t cur_hotend = 0; cur_hotend < HOTENDS; ++cur_hotend)
7972
-        max_temp = max(max(max_temp, thermalManager.degHotend(cur_hotend)), thermalManager.degTargetHotend(cur_hotend));
7971
+      HOTEND_LOOP() {
7972
+        max_temp = max(max(max_temp, thermalManager.degHotend(e)), thermalManager.degTargetHotend(e));
7973
+      }
7973
       #if HAS_TEMP_BED
7974
       #if HAS_TEMP_BED
7974
         max_temp = max(max(max_temp, thermalManager.degTargetBed()), thermalManager.degBed());
7975
         max_temp = max(max(max_temp, thermalManager.degTargetBed()), thermalManager.degBed());
7975
       #endif
7976
       #endif

+ 8
- 8
Marlin/configuration_store.cpp Целия файл

618
 
618
 
619
   #if ENABLED(PIDTEMP)
619
   #if ENABLED(PIDTEMP)
620
     #if ENABLED(PID_PARAMS_PER_HOTEND)
620
     #if ENABLED(PID_PARAMS_PER_HOTEND)
621
-      for (uint8_t e = 0; e < HOTENDS; e++)
621
+      HOTEND_LOOP
622
     #else
622
     #else
623
       int e = 0; UNUSED(e); // only need to write once
623
       int e = 0; UNUSED(e); // only need to write once
624
     #endif
624
     #endif
834
     #if ENABLED(PIDTEMP)
834
     #if ENABLED(PIDTEMP)
835
       #if HOTENDS > 1
835
       #if HOTENDS > 1
836
         if (forReplay) {
836
         if (forReplay) {
837
-          for (uint8_t i = 0; i < HOTENDS; i++) {
837
+          HOTEND_LOOP() {
838
             CONFIG_ECHO_START;
838
             CONFIG_ECHO_START;
839
-            SERIAL_ECHOPAIR("  M301 E", i);
840
-            SERIAL_ECHOPAIR(" P", PID_PARAM(Kp, i));
841
-            SERIAL_ECHOPAIR(" I", unscalePID_i(PID_PARAM(Ki, i)));
842
-            SERIAL_ECHOPAIR(" D", unscalePID_d(PID_PARAM(Kd, i)));
839
+            SERIAL_ECHOPAIR("  M301 E", e);
840
+            SERIAL_ECHOPAIR(" P", PID_PARAM(Kp, e));
841
+            SERIAL_ECHOPAIR(" I", unscalePID_i(PID_PARAM(Ki, e)));
842
+            SERIAL_ECHOPAIR(" D", unscalePID_d(PID_PARAM(Kd, e)));
843
             #if ENABLED(PID_ADD_EXTRUSION_RATE)
843
             #if ENABLED(PID_ADD_EXTRUSION_RATE)
844
-              SERIAL_ECHOPAIR(" C", PID_PARAM(Kc, i));
845
-              if (i == 0) SERIAL_ECHOPAIR(" L", lpq_len);
844
+              SERIAL_ECHOPAIR(" C", PID_PARAM(Kc, e));
845
+              if (e == 0) SERIAL_ECHOPAIR(" L", lpq_len);
846
             #endif
846
             #endif
847
             SERIAL_EOL;
847
             SERIAL_EOL;
848
           }
848
           }

+ 1
- 1
Marlin/dogm_lcd_implementation.h Целия файл

392
   #endif
392
   #endif
393
 
393
 
394
   // Extruders
394
   // Extruders
395
-  for (int i = 0; i < HOTENDS; i++) _draw_heater_status(5 + i * 25, i);
395
+  HOTEND_LOOP() _draw_heater_status(5 + e * 25, e);
396
 
396
 
397
   // Heated bed
397
   // Heated bed
398
   #if HOTENDS < 4 && HAS_TEMP_BED
398
   #if HOTENDS < 4 && HAS_TEMP_BED

+ 65
- 58
Marlin/temperature.cpp Целия файл

436
 
436
 
437
 void Temperature::updatePID() {
437
 void Temperature::updatePID() {
438
   #if ENABLED(PIDTEMP)
438
   #if ENABLED(PIDTEMP)
439
-    for (int e = 0; e < HOTENDS; e++) {
439
+    HOTEND_LOOP() {
440
       temp_iState_max[e] = (PID_INTEGRAL_DRIVE_MAX) / PID_PARAM(Ki, e);
440
       temp_iState_max[e] = (PID_INTEGRAL_DRIVE_MAX) / PID_PARAM(Ki, e);
441
       #if ENABLED(PID_ADD_EXTRUSION_RATE)
441
       #if ENABLED(PID_ADD_EXTRUSION_RATE)
442
         last_position[e] = 0;
442
         last_position[e] = 0;
465
       EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN ? 2 : 3
465
       EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN ? 2 : 3
466
     };
466
     };
467
     uint8_t fanState = 0;
467
     uint8_t fanState = 0;
468
-    for (int f = 0; f < HOTENDS; f++) {
469
-      if (current_temperature[f] > EXTRUDER_AUTO_FAN_TEMPERATURE)
470
-        SBI(fanState, fanBit[f]);
468
+    HOTEND_LOOP() {
469
+      if (current_temperature[e] > EXTRUDER_AUTO_FAN_TEMPERATURE)
470
+        SBI(fanState, fanBit[e]);
471
     }
471
     }
472
     uint8_t fanDone = 0;
472
     uint8_t fanDone = 0;
473
-    for (int f = 0; f <= 3; f++) {
473
+    for (int8_t f = 0; f <= 3; f++) {
474
       int8_t pin = fanPin[f];
474
       int8_t pin = fanPin[f];
475
       if (pin >= 0 && !TEST(fanDone, fanBit[f])) {
475
       if (pin >= 0 && !TEST(fanDone, fanBit[f])) {
476
         unsigned char newFanSpeed = TEST(fanState, fanBit[f]) ? EXTRUDER_AUTO_FAN_SPEED : 0;
476
         unsigned char newFanSpeed = TEST(fanState, fanBit[f]) ? EXTRUDER_AUTO_FAN_SPEED : 0;
507
 }
507
 }
508
 
508
 
509
 void Temperature::max_temp_error(uint8_t e) {
509
 void Temperature::max_temp_error(uint8_t e) {
510
-  _temp_error(e, PSTR(MSG_T_MAXTEMP), PSTR(MSG_ERR_MAXTEMP));
510
+  #if HOTENDS == 1
511
+    UNUSED(e);
512
+  #endif
513
+  _temp_error(HOTEND_INDEX, PSTR(MSG_T_MAXTEMP), PSTR(MSG_ERR_MAXTEMP));
511
 }
514
 }
512
 void Temperature::min_temp_error(uint8_t e) {
515
 void Temperature::min_temp_error(uint8_t e) {
513
-  _temp_error(e, PSTR(MSG_T_MINTEMP), PSTR(MSG_ERR_MINTEMP));
516
+  #if HOTENDS == 1
517
+    UNUSED(e);
518
+  #endif
519
+  _temp_error(HOTEND_INDEX, PSTR(MSG_T_MINTEMP), PSTR(MSG_ERR_MINTEMP));
514
 }
520
 }
515
 
521
 
516
 float Temperature::get_pid_output(int e) {
522
 float Temperature::get_pid_output(int e) {
523
+  #if HOTENDS == 1
524
+    UNUSED(e);
525
+    #define _HOTEND_TEST     true
526
+    #define _HOTEND_EXTRUDER active_extruder
527
+  #else
528
+    #define _HOTEND_TEST     e == active_extruder
529
+    #define _HOTEND_EXTRUDER e
530
+  #endif
517
   float pid_output;
531
   float pid_output;
518
   #if ENABLED(PIDTEMP)
532
   #if ENABLED(PIDTEMP)
519
     #if DISABLED(PID_OPENLOOP)
533
     #if DISABLED(PID_OPENLOOP)
520
-      pid_error[e] = target_temperature[e] - current_temperature[e];
521
-      dTerm[e] = K2 * PID_PARAM(Kd, e) * (current_temperature[e] - temp_dState[e]) + K1 * dTerm[e];
522
-      temp_dState[e] = current_temperature[e];
523
-      if (pid_error[e] > PID_FUNCTIONAL_RANGE) {
534
+      pid_error[HOTEND_INDEX] = target_temperature[HOTEND_INDEX] - current_temperature[HOTEND_INDEX];
535
+      dTerm[HOTEND_INDEX] = K2 * PID_PARAM(Kd, HOTEND_INDEX) * (current_temperature[HOTEND_INDEX] - temp_dState[HOTEND_INDEX]) + K1 * dTerm[HOTEND_INDEX];
536
+      temp_dState[HOTEND_INDEX] = current_temperature[HOTEND_INDEX];
537
+      if (pid_error[HOTEND_INDEX] > PID_FUNCTIONAL_RANGE) {
524
         pid_output = BANG_MAX;
538
         pid_output = BANG_MAX;
525
-        pid_reset[e] = true;
539
+        pid_reset[HOTEND_INDEX] = true;
526
       }
540
       }
527
-      else if (pid_error[e] < -(PID_FUNCTIONAL_RANGE) || target_temperature[e] == 0) {
541
+      else if (pid_error[HOTEND_INDEX] < -(PID_FUNCTIONAL_RANGE) || target_temperature[HOTEND_INDEX] == 0) {
528
         pid_output = 0;
542
         pid_output = 0;
529
-        pid_reset[e] = true;
543
+        pid_reset[HOTEND_INDEX] = true;
530
       }
544
       }
531
       else {
545
       else {
532
-        if (pid_reset[e]) {
533
-          temp_iState[e] = 0.0;
534
-          pid_reset[e] = false;
546
+        if (pid_reset[HOTEND_INDEX]) {
547
+          temp_iState[HOTEND_INDEX] = 0.0;
548
+          pid_reset[HOTEND_INDEX] = false;
535
         }
549
         }
536
-        pTerm[e] = PID_PARAM(Kp, e) * pid_error[e];
537
-        temp_iState[e] += pid_error[e];
538
-        temp_iState[e] = constrain(temp_iState[e], temp_iState_min[e], temp_iState_max[e]);
539
-        iTerm[e] = PID_PARAM(Ki, e) * temp_iState[e];
550
+        pTerm[HOTEND_INDEX] = PID_PARAM(Kp, HOTEND_INDEX) * pid_error[HOTEND_INDEX];
551
+        temp_iState[HOTEND_INDEX] += pid_error[HOTEND_INDEX];
552
+        temp_iState[HOTEND_INDEX] = constrain(temp_iState[HOTEND_INDEX], temp_iState_min[HOTEND_INDEX], temp_iState_max[HOTEND_INDEX]);
553
+        iTerm[HOTEND_INDEX] = PID_PARAM(Ki, HOTEND_INDEX) * temp_iState[HOTEND_INDEX];
540
 
554
 
541
-        pid_output = pTerm[e] + iTerm[e] - dTerm[e];
542
-
543
-        #if ENABLED(SINGLENOZZLE)
544
-          #define _NOZZLE_TEST     true
545
-          #define _NOZZLE_EXTRUDER active_extruder
546
-          #define _CTERM_INDEX     0
547
-        #else
548
-          #define _NOZZLE_TEST     e == active_extruder
549
-          #define _NOZZLE_EXTRUDER e
550
-          #define _CTERM_INDEX     e
551
-        #endif
555
+        pid_output = pTerm[HOTEND_INDEX] + iTerm[HOTEND_INDEX] - dTerm[HOTEND_INDEX];
552
 
556
 
553
         #if ENABLED(PID_ADD_EXTRUSION_RATE)
557
         #if ENABLED(PID_ADD_EXTRUSION_RATE)
554
-          cTerm[_CTERM_INDEX] = 0;
555
-          if (_NOZZLE_TEST) {
558
+          cTerm[HOTEND_INDEX] = 0;
559
+          if (_HOTEND_TEST) {
556
             long e_position = stepper.position(E_AXIS);
560
             long e_position = stepper.position(E_AXIS);
557
-            if (e_position > last_position[_NOZZLE_EXTRUDER]) {
558
-              lpq[lpq_ptr++] = e_position - last_position[_NOZZLE_EXTRUDER];
559
-              last_position[_NOZZLE_EXTRUDER] = e_position;
561
+            if (e_position > last_position[_HOTEND_EXTRUDER]) {
562
+              lpq[lpq_ptr++] = e_position - last_position[_HOTEND_EXTRUDER];
563
+              last_position[_HOTEND_EXTRUDER] = e_position;
560
             }
564
             }
561
             else {
565
             else {
562
               lpq[lpq_ptr++] = 0;
566
               lpq[lpq_ptr++] = 0;
563
             }
567
             }
564
             if (lpq_ptr >= lpq_len) lpq_ptr = 0;
568
             if (lpq_ptr >= lpq_len) lpq_ptr = 0;
565
-            cTerm[_CTERM_INDEX] = (lpq[lpq_ptr] / planner.axis_steps_per_mm[E_AXIS]) * PID_PARAM(Kc, e);
566
-            pid_output += cTerm[e];
569
+            cTerm[HOTEND_INDEX] = (lpq[lpq_ptr] / planner.axis_steps_per_mm[E_AXIS]) * PID_PARAM(Kc, HOTEND_INDEX);
570
+            pid_output += cTerm[HOTEND_INDEX];
567
           }
571
           }
568
         #endif //PID_ADD_EXTRUSION_RATE
572
         #endif //PID_ADD_EXTRUSION_RATE
569
 
573
 
570
         if (pid_output > PID_MAX) {
574
         if (pid_output > PID_MAX) {
571
-          if (pid_error[e] > 0) temp_iState[e] -= pid_error[e]; // conditional un-integration
575
+          if (pid_error[HOTEND_INDEX] > 0) temp_iState[HOTEND_INDEX] -= pid_error[HOTEND_INDEX]; // conditional un-integration
572
           pid_output = PID_MAX;
576
           pid_output = PID_MAX;
573
         }
577
         }
574
         else if (pid_output < 0) {
578
         else if (pid_output < 0) {
575
-          if (pid_error[e] < 0) temp_iState[e] -= pid_error[e]; // conditional un-integration
579
+          if (pid_error[HOTEND_INDEX] < 0) temp_iState[HOTEND_INDEX] -= pid_error[HOTEND_INDEX]; // conditional un-integration
576
           pid_output = 0;
580
           pid_output = 0;
577
         }
581
         }
578
       }
582
       }
579
     #else
583
     #else
580
-      pid_output = constrain(target_temperature[e], 0, PID_MAX);
584
+      pid_output = constrain(target_temperature[HOTEND_INDEX], 0, PID_MAX);
581
     #endif //PID_OPENLOOP
585
     #endif //PID_OPENLOOP
582
 
586
 
583
     #if ENABLED(PID_DEBUG)
587
     #if ENABLED(PID_DEBUG)
584
       SERIAL_ECHO_START;
588
       SERIAL_ECHO_START;
585
-      SERIAL_ECHOPAIR(MSG_PID_DEBUG, e);
586
-      SERIAL_ECHOPAIR(MSG_PID_DEBUG_INPUT, current_temperature[e]);
589
+      SERIAL_ECHOPAIR(MSG_PID_DEBUG, HOTEND_INDEX);
590
+      SERIAL_ECHOPAIR(MSG_PID_DEBUG_INPUT, current_temperature[HOTEND_INDEX]);
587
       SERIAL_ECHOPAIR(MSG_PID_DEBUG_OUTPUT, pid_output);
591
       SERIAL_ECHOPAIR(MSG_PID_DEBUG_OUTPUT, pid_output);
588
-      SERIAL_ECHOPAIR(MSG_PID_DEBUG_PTERM, pTerm[e]);
589
-      SERIAL_ECHOPAIR(MSG_PID_DEBUG_ITERM, iTerm[e]);
590
-      SERIAL_ECHOPAIR(MSG_PID_DEBUG_DTERM, dTerm[e]);
592
+      SERIAL_ECHOPAIR(MSG_PID_DEBUG_PTERM, pTerm[HOTEND_INDEX]);
593
+      SERIAL_ECHOPAIR(MSG_PID_DEBUG_ITERM, iTerm[HOTEND_INDEX]);
594
+      SERIAL_ECHOPAIR(MSG_PID_DEBUG_DTERM, dTerm[HOTEND_INDEX]);
591
       #if ENABLED(PID_ADD_EXTRUSION_RATE)
595
       #if ENABLED(PID_ADD_EXTRUSION_RATE)
592
-        SERIAL_ECHOPAIR(MSG_PID_DEBUG_CTERM, cTerm[e]);
596
+        SERIAL_ECHOPAIR(MSG_PID_DEBUG_CTERM, cTerm[HOTEND_INDEX]);
593
       #endif
597
       #endif
594
       SERIAL_EOL;
598
       SERIAL_EOL;
595
     #endif //PID_DEBUG
599
     #endif //PID_DEBUG
596
 
600
 
597
   #else /* PID off */
601
   #else /* PID off */
598
-    pid_output = (current_temperature[e] < target_temperature[e]) ? PID_MAX : 0;
602
+    pid_output = (current_temperature[HOTEND_INDEX] < target_temperature[HOTEND_INDEX]) ? PID_MAX : 0;
599
   #endif
603
   #endif
600
 
604
 
601
   return pid_output;
605
   return pid_output;
672
   #endif
676
   #endif
673
 
677
 
674
   // Loop through all hotends
678
   // Loop through all hotends
675
-  for (int e = 0; e < HOTENDS; e++) {
679
+  HOTEND_LOOP() {
676
 
680
 
677
     #if ENABLED(THERMAL_PROTECTION_HOTENDS)
681
     #if ENABLED(THERMAL_PROTECTION_HOTENDS)
678
       thermal_runaway_protection(&thermal_runaway_state_machine[e], &thermal_runaway_timer[e], current_temperature[e], target_temperature[e], e, THERMAL_PROTECTION_PERIOD, THERMAL_PROTECTION_HYSTERESIS);
682
       thermal_runaway_protection(&thermal_runaway_state_machine[e], &thermal_runaway_timer[e], current_temperature[e], target_temperature[e], e, THERMAL_PROTECTION_PERIOD, THERMAL_PROTECTION_HYSTERESIS);
879
   #if ENABLED(HEATER_0_USES_MAX6675)
883
   #if ENABLED(HEATER_0_USES_MAX6675)
880
     current_temperature_raw[0] = read_max6675();
884
     current_temperature_raw[0] = read_max6675();
881
   #endif
885
   #endif
882
-  for (uint8_t e = 0; e < HOTENDS; e++) {
886
+  HOTEND_LOOP() {
883
     current_temperature[e] = Temperature::analog2temp(current_temperature_raw[e], e);
887
     current_temperature[e] = Temperature::analog2temp(current_temperature_raw[e], e);
884
   }
888
   }
885
   current_temperature_bed = Temperature::analog2tempBed(current_temperature_bed_raw);
889
   current_temperature_bed = Temperature::analog2tempBed(current_temperature_bed_raw);
933
   #endif
937
   #endif
934
 
938
 
935
   // Finish init of mult hotend arrays
939
   // Finish init of mult hotend arrays
936
-  for (int e = 0; e < HOTENDS; e++) {
940
+  HOTEND_LOOP() {
937
     // populate with the first value
941
     // populate with the first value
938
     maxttemp[e] = maxttemp[0];
942
     maxttemp[e] = maxttemp[0];
939
     #if ENABLED(PIDTEMP)
943
     #if ENABLED(PIDTEMP)
1140
    * their target temperature by a configurable margin.
1144
    * their target temperature by a configurable margin.
1141
    * This is called when the temperature is set. (M104, M109)
1145
    * This is called when the temperature is set. (M104, M109)
1142
    */
1146
    */
1143
-  void Temperature::start_watching_heater(int e) {
1144
-    if (degHotend(e) < degTargetHotend(e) - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1)) {
1145
-      watch_target_temp[e] = degHotend(e) + WATCH_TEMP_INCREASE;
1146
-      watch_heater_next_ms[e] = millis() + (WATCH_TEMP_PERIOD) * 1000UL;
1147
+  void Temperature::start_watching_heater(uint8_t e) {
1148
+    #if HOTENDS == 1
1149
+      UNUSED(e);
1150
+    #endif
1151
+    if (degHotend(HOTEND_INDEX) < degTargetHotend(HOTEND_INDEX) - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1)) {
1152
+      watch_target_temp[HOTEND_INDEX] = degHotend(HOTEND_INDEX) + WATCH_TEMP_INCREASE;
1153
+      watch_heater_next_ms[HOTEND_INDEX] = millis() + (WATCH_TEMP_PERIOD) * 1000UL;
1147
     }
1154
     }
1148
     else
1155
     else
1149
-      watch_heater_next_ms[e] = 0;
1156
+      watch_heater_next_ms[HOTEND_INDEX] = 0;
1150
   }
1157
   }
1151
 #endif
1158
 #endif
1152
 
1159
 
1224
 #endif // THERMAL_PROTECTION_HOTENDS || THERMAL_PROTECTION_BED
1231
 #endif // THERMAL_PROTECTION_HOTENDS || THERMAL_PROTECTION_BED
1225
 
1232
 
1226
 void Temperature::disable_all_heaters() {
1233
 void Temperature::disable_all_heaters() {
1227
-  for (int i = 0; i < HOTENDS; i++) setTargetHotend(0, i);
1234
+  HOTEND_LOOP() setTargetHotend(0, e);
1228
   setTargetBed(0);
1235
   setTargetBed(0);
1229
 
1236
 
1230
   // If all heaters go down then for sure our print job has stopped
1237
   // If all heaters go down then for sure our print job has stopped

+ 38
- 29
Marlin/temperature.h Целия файл

38
   #define SOFT_PWM_SCALE 0
38
   #define SOFT_PWM_SCALE 0
39
 #endif
39
 #endif
40
 
40
 
41
+#if HOTENDS == 1
42
+  #define HOTEND_LOOP() const uint8_t e = 0;
43
+  #define HOTEND_INDEX  0
44
+  #define EXTRUDER_IDX  0
45
+#else
46
+  #define HOTEND_LOOP() for (int8_t e = 0; e < HOTENDS; e++)
47
+  #define HOTEND_INDEX  e
48
+  #define EXTRUDER_IDX  active_extruder
49
+#endif
50
+
41
 class Temperature {
51
 class Temperature {
42
 
52
 
43
   public:
53
   public:
112
 
122
 
113
     #if ENABLED(PREVENT_DANGEROUS_EXTRUDE)
123
     #if ENABLED(PREVENT_DANGEROUS_EXTRUDE)
114
       static float extrude_min_temp;
124
       static float extrude_min_temp;
115
-      static bool tooColdToExtrude(uint8_t e) { return degHotend(e) < extrude_min_temp; }
125
+      static bool tooColdToExtrude(uint8_t e) {
126
+        #if HOTENDS == 1
127
+          UNUSED(e);
128
+        #endif
129
+        return degHotend(HOTEND_INDEX) < extrude_min_temp;
130
+      }
116
     #else
131
     #else
117
       static bool tooColdToExtrude(uint8_t e) { UNUSED(e); return false; }
132
       static bool tooColdToExtrude(uint8_t e) { UNUSED(e); return false; }
118
     #endif
133
     #endif
230
     //inline so that there is no performance decrease.
245
     //inline so that there is no performance decrease.
231
     //deg=degreeCelsius
246
     //deg=degreeCelsius
232
 
247
 
233
-    #if HOTENDS == 1
234
-      #define HOTEND_ARG 0
235
-    #else
236
-      #define HOTEND_ARG hotend
237
-    #endif
238
-
239
-    static float degHotend(uint8_t hotend) {
248
+    static float degHotend(uint8_t e) {
240
       #if HOTENDS == 1
249
       #if HOTENDS == 1
241
-        UNUSED(hotend);
250
+        UNUSED(e);
242
       #endif
251
       #endif
243
-      return current_temperature[HOTEND_ARG];
252
+      return current_temperature[HOTEND_INDEX];
244
     }
253
     }
245
     static float degBed() { return current_temperature_bed; }
254
     static float degBed() { return current_temperature_bed; }
246
 
255
 
247
     #if ENABLED(SHOW_TEMP_ADC_VALUES)
256
     #if ENABLED(SHOW_TEMP_ADC_VALUES)
248
-    static float rawHotendTemp(uint8_t hotend) {
257
+    static float rawHotendTemp(uint8_t e) {
249
       #if HOTENDS == 1
258
       #if HOTENDS == 1
250
-        UNUSED(hotend);
259
+        UNUSED(e);
251
       #endif
260
       #endif
252
-      return current_temperature_raw[HOTEND_ARG];
261
+      return current_temperature_raw[HOTEND_INDEX];
253
     }
262
     }
254
     static float rawBedTemp() { return current_temperature_bed_raw; }
263
     static float rawBedTemp() { return current_temperature_bed_raw; }
255
     #endif
264
     #endif
256
 
265
 
257
-    static float degTargetHotend(uint8_t hotend) {
266
+    static float degTargetHotend(uint8_t e) {
258
       #if HOTENDS == 1
267
       #if HOTENDS == 1
259
-        UNUSED(hotend);
268
+        UNUSED(e);
260
       #endif
269
       #endif
261
-      return target_temperature[HOTEND_ARG];
270
+      return target_temperature[HOTEND_INDEX];
262
     }
271
     }
263
     static float degTargetBed() { return target_temperature_bed; }
272
     static float degTargetBed() { return target_temperature_bed; }
264
 
273
 
265
     #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
274
     #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
266
-      static void start_watching_heater(int e = 0);
275
+      static void start_watching_heater(uint8_t e = 0);
267
     #endif
276
     #endif
268
 
277
 
269
     #if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
278
     #if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
270
       static void start_watching_bed();
279
       static void start_watching_bed();
271
     #endif
280
     #endif
272
 
281
 
273
-    static void setTargetHotend(const float& celsius, uint8_t hotend) {
282
+    static void setTargetHotend(const float& celsius, uint8_t e) {
274
       #if HOTENDS == 1
283
       #if HOTENDS == 1
275
-        UNUSED(hotend);
284
+        UNUSED(e);
276
       #endif
285
       #endif
277
-      target_temperature[HOTEND_ARG] = celsius;
286
+      target_temperature[HOTEND_INDEX] = celsius;
278
       #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
287
       #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
279
-        start_watching_heater(HOTEND_ARG);
288
+        start_watching_heater(HOTEND_INDEX);
280
       #endif
289
       #endif
281
     }
290
     }
282
 
291
 
287
       #endif
296
       #endif
288
     }
297
     }
289
 
298
 
290
-    static bool isHeatingHotend(uint8_t hotend) {
299
+    static bool isHeatingHotend(uint8_t e) {
291
       #if HOTENDS == 1
300
       #if HOTENDS == 1
292
-        UNUSED(hotend);
301
+        UNUSED(e);
293
       #endif
302
       #endif
294
-      return target_temperature[HOTEND_ARG] > current_temperature[HOTEND_ARG];
303
+      return target_temperature[HOTEND_INDEX] > current_temperature[HOTEND_INDEX];
295
     }
304
     }
296
     static bool isHeatingBed() { return target_temperature_bed > current_temperature_bed; }
305
     static bool isHeatingBed() { return target_temperature_bed > current_temperature_bed; }
297
 
306
 
298
-    static bool isCoolingHotend(uint8_t hotend) {
307
+    static bool isCoolingHotend(uint8_t e) {
299
       #if HOTENDS == 1
308
       #if HOTENDS == 1
300
-        UNUSED(hotend);
309
+        UNUSED(e);
301
       #endif
310
       #endif
302
-      return target_temperature[HOTEND_ARG] < current_temperature[HOTEND_ARG];
311
+      return target_temperature[HOTEND_INDEX] < current_temperature[HOTEND_INDEX];
303
     }
312
     }
304
     static bool isCoolingBed() { return target_temperature_bed < current_temperature_bed; }
313
     static bool isCoolingBed() { return target_temperature_bed < current_temperature_bed; }
305
 
314
 
329
       #if ENABLED(AUTOTEMP)
338
       #if ENABLED(AUTOTEMP)
330
         if (planner.autotemp_enabled) {
339
         if (planner.autotemp_enabled) {
331
           planner.autotemp_enabled = false;
340
           planner.autotemp_enabled = false;
332
-          if (degTargetHotend(active_extruder) > planner.autotemp_min)
333
-            setTargetHotend(0, active_extruder);
341
+          if (degTargetHotend(EXTRUDER_IDX) > planner.autotemp_min)
342
+            setTargetHotend(0, EXTRUDER_IDX);
334
         }
343
         }
335
       #endif
344
       #endif
336
     }
345
     }

Loading…
Отказ
Запис