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

LIN_ADVANCE bug fix and optimization

.) long to int: Extruder stalls at 10kHz / 20kHz step limits with long.
.) Take the delta_adv_steps calculation out of the step_loops loop. Wasted calculation performance if done inside.
.) >> 2 replaced by 3: Is divide by 8. Reason: Timer 0 runs at 16/8=2MHz, Timer 1 at 16/64=0.25MHz. ==> 2/0.25=8.
Sebastianv650 преди 7 години
родител
ревизия
a448cedbc5
променени са 2 файла, в които са добавени 22 реда и са изтрити 23 реда
  1. 21
    22
      Marlin/stepper.cpp
  2. 1
    1
      Marlin/stepper.h

+ 21
- 22
Marlin/stepper.cpp Целия файл

@@ -95,7 +95,7 @@ volatile uint32_t Stepper::step_events_completed = 0; // The number of step even
95 95
   volatile unsigned char Stepper::eISR_Rate = 200; // Keep the ISR at a low rate until needed
96 96
 
97 97
   #if ENABLED(LIN_ADVANCE)
98
-    volatile long Stepper::e_steps[E_STEPPERS];
98
+    volatile int Stepper::e_steps[E_STEPPERS];
99 99
     int Stepper::extruder_advance_k = LIN_ADVANCE_K,
100 100
         Stepper::final_estep_rate,
101 101
         Stepper::current_estep_rate[E_STEPPERS],
@@ -391,7 +391,7 @@ void Stepper::isr() {
391 391
 
392 392
       #if ENABLED(MIXING_EXTRUDER)
393 393
         // Step mixing steppers proportionally
394
-        bool dir = motor_direction(E_AXIS);
394
+        const bool dir = motor_direction(E_AXIS);
395 395
         MIXING_STEPPERS_LOOP(j) {
396 396
           counter_m[j] += current_block->steps[E_AXIS];
397 397
           if (counter_m[j] > 0) {
@@ -401,22 +401,6 @@ void Stepper::isr() {
401 401
         }
402 402
       #endif
403 403
 
404
-      if (current_block->use_advance_lead) {
405
-        int delta_adv_steps = (((long)extruder_advance_k * current_estep_rate[TOOL_E_INDEX]) >> 9) - current_adv_steps[TOOL_E_INDEX];
406
-        #if ENABLED(MIXING_EXTRUDER)
407
-          // Mixing extruders apply advance lead proportionally
408
-          MIXING_STEPPERS_LOOP(j) {
409
-            int steps = delta_adv_steps * current_block->step_event_count / current_block->mix_event_count[j];
410
-            e_steps[j] += steps;
411
-            current_adv_steps[j] += steps;
412
-          }
413
-        #else
414
-          // For most extruders, advance the single E stepper
415
-          e_steps[TOOL_E_INDEX] += delta_adv_steps;
416
-          current_adv_steps[TOOL_E_INDEX] += delta_adv_steps;
417
-        #endif
418
-      }
419
-
420 404
     #elif ENABLED(ADVANCE)
421 405
 
422 406
       // Always count the unified E axis
@@ -432,7 +416,7 @@ void Stepper::isr() {
432 416
       #if ENABLED(MIXING_EXTRUDER)
433 417
 
434 418
         // Step mixing steppers proportionally
435
-        bool dir = motor_direction(E_AXIS);
419
+        const bool dir = motor_direction(E_AXIS);
436 420
         MIXING_STEPPERS_LOOP(j) {
437 421
           counter_m[j] += current_block->steps[E_AXIS];
438 422
           if (counter_m[j] > 0) {
@@ -536,6 +520,21 @@ void Stepper::isr() {
536 520
     }
537 521
   }
538 522
 
523
+  #if ENABLED(LIN_ADVANCE)
524
+    if (current_block->use_advance_lead) {
525
+      int delta_adv_steps = (((long)extruder_advance_k * current_estep_rate[TOOL_E_INDEX]) >> 9) - current_adv_steps[TOOL_E_INDEX];
526
+      current_adv_steps[TOOL_E_INDEX] += delta_adv_steps;
527
+      #if ENABLED(MIXING_EXTRUDER)
528
+        // Mixing extruders apply advance lead proportionally
529
+        MIXING_STEPPERS_LOOP(j)
530
+          e_steps[j] += delta_adv_steps * current_block->step_event_count / current_block->mix_event_count[j];
531
+      #else
532
+        // For most extruders, advance the single E stepper
533
+        e_steps[TOOL_E_INDEX] += delta_adv_steps;
534
+      #endif
535
+   }
536
+  #endif
537
+  
539 538
   #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
540 539
     // If we have esteps to execute, fire the next advance_isr "now"
541 540
     if (e_steps[TOOL_E_INDEX]) OCR0A = TCNT0 + 2;
@@ -593,7 +592,7 @@ void Stepper::isr() {
593 592
     #endif // ADVANCE or LIN_ADVANCE
594 593
 
595 594
     #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
596
-      eISR_Rate = (timer >> 2) * step_loops / abs(e_steps[TOOL_E_INDEX]);
595
+      eISR_Rate = (timer >> 3) * step_loops / abs(e_steps[TOOL_E_INDEX]); //>> 3 is divide by 8. Reason: Timer 0 runs at 16/8=2MHz, Timer 1 at 16/64=0.25MHz. ==> 2/0.25=8.
597 596
     #endif
598 597
   }
599 598
   else if (step_events_completed > (uint32_t)current_block->decelerate_after) {
@@ -643,7 +642,7 @@ void Stepper::isr() {
643 642
     #endif // ADVANCE or LIN_ADVANCE
644 643
 
645 644
     #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
646
-      eISR_Rate = (timer >> 2) * step_loops / abs(e_steps[TOOL_E_INDEX]);
645
+      eISR_Rate = (timer >> 3) * step_loops / abs(e_steps[TOOL_E_INDEX]);
647 646
     #endif
648 647
   }
649 648
   else {
@@ -653,7 +652,7 @@ void Stepper::isr() {
653 652
       if (current_block->use_advance_lead)
654 653
         current_estep_rate[TOOL_E_INDEX] = final_estep_rate;
655 654
 
656
-      eISR_Rate = (OCR1A_nominal >> 2) * step_loops_nominal / abs(e_steps[TOOL_E_INDEX]);
655
+      eISR_Rate = (OCR1A_nominal >> 3) * step_loops_nominal / abs(e_steps[TOOL_E_INDEX]);
657 656
 
658 657
     #endif
659 658
 

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

@@ -108,7 +108,7 @@ class Stepper {
108 108
       static unsigned char old_OCR0A;
109 109
       static volatile unsigned char eISR_Rate;
110 110
       #if ENABLED(LIN_ADVANCE)
111
-        static volatile long e_steps[E_STEPPERS];
111
+        static volatile int e_steps[E_STEPPERS];
112 112
         static int extruder_advance_k;
113 113
         static int final_estep_rate;
114 114
         static int current_estep_rate[E_STEPPERS]; // Actual extruder speed [steps/s]

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