|
@@ -128,7 +128,7 @@ volatile bool Temperature::temp_meas_ready = false;
|
128
|
128
|
|
129
|
129
|
#if ENABLED(PID_ADD_EXTRUSION_RATE)
|
130
|
130
|
float Temperature::cTerm[HOTENDS];
|
131
|
|
- long Temperature::last_position[HOTENDS];
|
|
131
|
+ long Temperature::last_e_position;
|
132
|
132
|
long Temperature::lpq[LPQ_MAX_LEN];
|
133
|
133
|
int Temperature::lpq_ptr = 0;
|
134
|
134
|
#endif
|
|
@@ -444,11 +444,11 @@ Temperature::Temperature() { }
|
444
|
444
|
|
445
|
445
|
void Temperature::updatePID() {
|
446
|
446
|
#if ENABLED(PIDTEMP)
|
|
447
|
+ #if ENABLED(PID_ADD_EXTRUSION_RATE)
|
|
448
|
+ last_e_position = 0;
|
|
449
|
+ #endif
|
447
|
450
|
HOTEND_LOOP() {
|
448
|
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
|
453
|
#endif
|
454
|
454
|
#if ENABLED(PIDTEMPBED)
|
|
@@ -531,10 +531,8 @@ float Temperature::get_pid_output(int e) {
|
531
|
531
|
#if HOTENDS == 1
|
532
|
532
|
UNUSED(e);
|
533
|
533
|
#define _HOTEND_TEST true
|
534
|
|
- #define _HOTEND_EXTRUDER active_extruder
|
535
|
534
|
#else
|
536
|
535
|
#define _HOTEND_TEST e == active_extruder
|
537
|
|
- #define _HOTEND_EXTRUDER e
|
538
|
536
|
#endif
|
539
|
537
|
float pid_output;
|
540
|
538
|
#if ENABLED(PIDTEMP)
|
|
@@ -566,14 +564,14 @@ float Temperature::get_pid_output(int e) {
|
566
|
564
|
cTerm[HOTEND_INDEX] = 0;
|
567
|
565
|
if (_HOTEND_TEST) {
|
568
|
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
|
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
|
575
|
cTerm[HOTEND_INDEX] = (lpq[lpq_ptr] / planner.axis_steps_per_mm[E_AXIS]) * PID_PARAM(Kc, HOTEND_INDEX);
|
578
|
576
|
pid_output += cTerm[HOTEND_INDEX];
|
579
|
577
|
}
|
|
@@ -952,7 +950,7 @@ void Temperature::init() {
|
952
|
950
|
temp_iState_min[e] = 0.0;
|
953
|
951
|
temp_iState_max[e] = (PID_INTEGRAL_DRIVE_MAX) / PID_PARAM(Ki, e);
|
954
|
952
|
#if ENABLED(PID_ADD_EXTRUSION_RATE)
|
955
|
|
- last_position[e] = 0;
|
|
953
|
+ last_e_position = 0;
|
956
|
954
|
#endif
|
957
|
955
|
#endif //PIDTEMP
|
958
|
956
|
#if ENABLED(PIDTEMPBED)
|
|
@@ -961,6 +959,10 @@ void Temperature::init() {
|
961
|
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
|
966
|
#if HAS_HEATER_0
|
965
|
967
|
SET_OUTPUT(HEATER_0_PIN);
|
966
|
968
|
#endif
|