Browse Source

Merge pull request #4278 from thinkyhead/rc_more_hotends_1

Fixups for PID_ADD_EXTRUSION_RATE and HOTENDS==1
Scott Lahteine 9 years ago
parent
commit
a1de96d152
2 changed files with 38 additions and 23 deletions
  1. 14
    12
      Marlin/temperature.cpp
  2. 24
    11
      Marlin/temperature.h

+ 14
- 12
Marlin/temperature.cpp View File

128
 
128
 
129
   #if ENABLED(PID_ADD_EXTRUSION_RATE)
129
   #if ENABLED(PID_ADD_EXTRUSION_RATE)
130
     float Temperature::cTerm[HOTENDS];
130
     float Temperature::cTerm[HOTENDS];
131
-    long Temperature::last_position[HOTENDS];
131
+    long Temperature::last_e_position;
132
     long Temperature::lpq[LPQ_MAX_LEN];
132
     long Temperature::lpq[LPQ_MAX_LEN];
133
     int Temperature::lpq_ptr = 0;
133
     int Temperature::lpq_ptr = 0;
134
   #endif
134
   #endif
444
 
444
 
445
 void Temperature::updatePID() {
445
 void Temperature::updatePID() {
446
   #if ENABLED(PIDTEMP)
446
   #if ENABLED(PIDTEMP)
447
+    #if ENABLED(PID_ADD_EXTRUSION_RATE)
448
+      last_e_position = 0;
449
+    #endif
447
     HOTEND_LOOP() {
450
     HOTEND_LOOP() {
448
       temp_iState_max[e] = (PID_INTEGRAL_DRIVE_MAX) / PID_PARAM(Ki, e);
451
       temp_iState_max[e] = (PID_INTEGRAL_DRIVE_MAX) / PID_PARAM(Ki, e);
449
-      #if ENABLED(PID_ADD_EXTRUSION_RATE)
450
-        last_position[e] = 0;
451
-      #endif
452
     }
452
     }
453
   #endif
453
   #endif
454
   #if ENABLED(PIDTEMPBED)
454
   #if ENABLED(PIDTEMPBED)
531
   #if HOTENDS == 1
531
   #if HOTENDS == 1
532
     UNUSED(e);
532
     UNUSED(e);
533
     #define _HOTEND_TEST     true
533
     #define _HOTEND_TEST     true
534
-    #define _HOTEND_EXTRUDER active_extruder
535
   #else
534
   #else
536
     #define _HOTEND_TEST     e == active_extruder
535
     #define _HOTEND_TEST     e == active_extruder
537
-    #define _HOTEND_EXTRUDER e
538
   #endif
536
   #endif
539
   float pid_output;
537
   float pid_output;
540
   #if ENABLED(PIDTEMP)
538
   #if ENABLED(PIDTEMP)
566
           cTerm[HOTEND_INDEX] = 0;
564
           cTerm[HOTEND_INDEX] = 0;
567
           if (_HOTEND_TEST) {
565
           if (_HOTEND_TEST) {
568
             long e_position = stepper.position(E_AXIS);
566
             long e_position = stepper.position(E_AXIS);
569
-            if (e_position > last_position[_HOTEND_EXTRUDER]) {
570
-              lpq[lpq_ptr++] = e_position - last_position[_HOTEND_EXTRUDER];
571
-              last_position[_HOTEND_EXTRUDER] = e_position;
567
+            if (e_position > last_e_position) {
568
+              lpq[lpq_ptr] = e_position - last_e_position;
569
+              last_e_position = e_position;
572
             }
570
             }
573
             else {
571
             else {
574
-              lpq[lpq_ptr++] = 0;
572
+              lpq[lpq_ptr] = 0;
575
             }
573
             }
576
-            if (lpq_ptr >= lpq_len) lpq_ptr = 0;
574
+            if (++lpq_ptr >= lpq_len) lpq_ptr = 0;
577
             cTerm[HOTEND_INDEX] = (lpq[lpq_ptr] / planner.axis_steps_per_mm[E_AXIS]) * PID_PARAM(Kc, HOTEND_INDEX);
575
             cTerm[HOTEND_INDEX] = (lpq[lpq_ptr] / planner.axis_steps_per_mm[E_AXIS]) * PID_PARAM(Kc, HOTEND_INDEX);
578
             pid_output += cTerm[HOTEND_INDEX];
576
             pid_output += cTerm[HOTEND_INDEX];
579
           }
577
           }
952
       temp_iState_min[e] = 0.0;
950
       temp_iState_min[e] = 0.0;
953
       temp_iState_max[e] = (PID_INTEGRAL_DRIVE_MAX) / PID_PARAM(Ki, e);
951
       temp_iState_max[e] = (PID_INTEGRAL_DRIVE_MAX) / PID_PARAM(Ki, e);
954
       #if ENABLED(PID_ADD_EXTRUSION_RATE)
952
       #if ENABLED(PID_ADD_EXTRUSION_RATE)
955
-        last_position[e] = 0;
953
+        last_e_position = 0;
956
       #endif
954
       #endif
957
     #endif //PIDTEMP
955
     #endif //PIDTEMP
958
     #if ENABLED(PIDTEMPBED)
956
     #if ENABLED(PIDTEMPBED)
961
     #endif //PIDTEMPBED
959
     #endif //PIDTEMPBED
962
   }
960
   }
963
 
961
 
962
+  #if ENABLED(PIDTEMP) && ENABLED(PID_ADD_EXTRUSION_RATE)
963
+    last_e_position = 0;
964
+  #endif
965
+
964
   #if HAS_HEATER_0
966
   #if HAS_HEATER_0
965
     SET_OUTPUT(HEATER_0_PIN);
967
     SET_OUTPUT(HEATER_0_PIN);
966
   #endif
968
   #endif

+ 24
- 11
Marlin/temperature.h View File

76
 
76
 
77
     #if ENABLED(PIDTEMP)
77
     #if ENABLED(PIDTEMP)
78
 
78
 
79
-      #if ENABLED(PID_PARAMS_PER_HOTEND)
79
+      #if ENABLED(PID_PARAMS_PER_HOTEND) && HOTENDS > 1
80
 
80
 
81
         static float Kp[HOTENDS], Ki[HOTENDS], Kd[HOTENDS];
81
         static float Kp[HOTENDS], Ki[HOTENDS], Kd[HOTENDS];
82
         #if ENABLED(PID_ADD_EXTRUSION_RATE)
82
         #if ENABLED(PID_ADD_EXTRUSION_RATE)
83
           static float Kc[HOTENDS];
83
           static float Kc[HOTENDS];
84
         #endif
84
         #endif
85
-        #define PID_PARAM(param, e) Temperature::param[e]
85
+        #define PID_PARAM(param, h) Temperature::param[h]
86
 
86
 
87
       #else
87
       #else
88
 
88
 
90
         #if ENABLED(PID_ADD_EXTRUSION_RATE)
90
         #if ENABLED(PID_ADD_EXTRUSION_RATE)
91
           static float Kc;
91
           static float Kc;
92
         #endif
92
         #endif
93
-        #define PID_PARAM(param, e) Temperature::param
93
+        #define PID_PARAM(param, h) Temperature::param
94
 
94
 
95
       #endif // PID_PARAMS_PER_HOTEND
95
       #endif // PID_PARAMS_PER_HOTEND
96
 
96
 
150
 
150
 
151
       #if ENABLED(PID_ADD_EXTRUSION_RATE)
151
       #if ENABLED(PID_ADD_EXTRUSION_RATE)
152
         static float cTerm[HOTENDS];
152
         static float cTerm[HOTENDS];
153
-        static long last_position[HOTENDS];
153
+        static long last_e_position;
154
         static long lpq[LPQ_MAX_LEN];
154
         static long lpq[LPQ_MAX_LEN];
155
         static int lpq_ptr;
155
         static int lpq_ptr;
156
       #endif
156
       #endif
247
      * Preheating hotends
247
      * Preheating hotends
248
      */
248
      */
249
     #ifdef MILLISECONDS_PREHEAT_TIME
249
     #ifdef MILLISECONDS_PREHEAT_TIME
250
-      static bool is_preheating(uint8_t hotend) {
251
-        return preheat_end_time[hotend] && PENDING(millis(), preheat_end_time[hotend]);
250
+      static bool is_preheating(uint8_t e) {
251
+        #if HOTENDS == 1
252
+          UNUSED(e);
253
+        #endif
254
+        return preheat_end_time[HOTEND_INDEX] && PENDING(millis(), preheat_end_time[HOTEND_INDEX]);
255
+      }
256
+      static void start_preheat_time(uint8_t e) {
257
+        #if HOTENDS == 1
258
+          UNUSED(e);
259
+        #endif
260
+        preheat_end_time[HOTEND_INDEX] = millis() + MILLISECONDS_PREHEAT_TIME;
261
+      }
262
+      static void reset_preheat_time(uint8_t e) {
263
+        #if HOTENDS == 1
264
+          UNUSED(e);
265
+        #endif
266
+        preheat_end_time[HOTEND_INDEX] = 0;
252
       }
267
       }
253
-      static void start_preheat_time(uint8_t hotend) { preheat_end_time[hotend] = millis() + MILLISECONDS_PREHEAT_TIME; }
254
-      static void reset_preheat_time(uint8_t hotend) { preheat_end_time[hotend] = 0; }
255
     #else
268
     #else
256
       #define is_preheating(n) (false)
269
       #define is_preheating(n) (false)
257
     #endif
270
     #endif
306
       #endif
319
       #endif
307
       #ifdef MILLISECONDS_PREHEAT_TIME
320
       #ifdef MILLISECONDS_PREHEAT_TIME
308
         if (celsius == 0.0f)
321
         if (celsius == 0.0f)
309
-          reset_preheat_time(hotend);
310
-        else if (target_temperature[hotend] == 0.0f)
311
-          start_preheat_time(hotend);
322
+          reset_preheat_time(HOTEND_INDEX);
323
+        else if (target_temperature[HOTEND_INDEX] == 0.0f)
324
+          start_preheat_time(HOTEND_INDEX);
312
       #endif
325
       #endif
313
       target_temperature[HOTEND_INDEX] = celsius;
326
       target_temperature[HOTEND_INDEX] = celsius;
314
       #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
327
       #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0

Loading…
Cancel
Save