Browse Source

Optimize stepper advance_isr

Scott Lahteine 8 years ago
parent
commit
8c7ee4599e
1 changed files with 36 additions and 15 deletions
  1. 36
    15
      Marlin/stepper.cpp

+ 36
- 15
Marlin/stepper.cpp View File

@@ -683,29 +683,50 @@ void Stepper::isr() {
683 683
     old_OCR0A += eISR_Rate;
684 684
     OCR0A = old_OCR0A;
685 685
 
686
-    #define STEP_E_ONCE(INDEX) \
687
-      if (e_steps[INDEX] != 0) { \
688
-        E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN); \
689
-        if (e_steps[INDEX] < 0) { \
690
-          E## INDEX ##_DIR_WRITE(INVERT_E## INDEX ##_DIR); \
691
-          e_steps[INDEX]++; \
692
-        } \
693
-        else { \
694
-          E## INDEX ##_DIR_WRITE(!INVERT_E## INDEX ##_DIR); \
695
-          e_steps[INDEX]--; \
696
-        } \
686
+    #define SET_E_STEP_DIR(INDEX) \
687
+      E## INDEX ##_DIR_WRITE(e_steps[INDEX] <= 0 ? INVERT_E## INDEX ##_DIR : !INVERT_E## INDEX ##_DIR)
688
+
689
+    #define START_E_PULSE(INDEX) \
690
+      if (e_steps[INDEX]) E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN)
691
+
692
+    #define STOP_E_PULSE(INDEX) \
693
+      if (e_steps[INDEX]) { \
694
+        e_steps[INDEX] < 0 ? ++e_steps[INDEX] : --e_steps[INDEX]; \
697 695
         E## INDEX ##_STEP_WRITE(!INVERT_E_STEP_PIN); \
698 696
       }
699 697
 
698
+    SET_E_STEP_DIR(0);
699
+    #if E_STEPPERS > 1
700
+      SET_E_STEP_DIR(1);
701
+      #if E_STEPPERS > 2
702
+        SET_E_STEP_DIR(2);
703
+        #if E_STEPPERS > 3
704
+          SET_E_STEP_DIR(3);
705
+        #endif
706
+      #endif
707
+    #endif
708
+
700 709
     // Step all E steppers that have steps
701 710
     for (uint8_t i = 0; i < step_loops; i++) {
702
-      STEP_E_ONCE(0);
711
+
712
+      START_E_PULSE(0);
713
+      #if E_STEPPERS > 1
714
+        START_E_PULSE(1);
715
+        #if E_STEPPERS > 2
716
+          START_E_PULSE(2);
717
+          #if E_STEPPERS > 3
718
+            START_E_PULSE(3);
719
+          #endif
720
+        #endif
721
+      #endif
722
+
723
+      STOP_E_PULSE(0);
703 724
       #if E_STEPPERS > 1
704
-        STEP_E_ONCE(1);
725
+        STOP_E_PULSE(1);
705 726
         #if E_STEPPERS > 2
706
-          STEP_E_ONCE(2);
727
+          STOP_E_PULSE(2);
707 728
           #if E_STEPPERS > 3
708
-            STEP_E_ONCE(3);
729
+            STOP_E_PULSE(3);
709 730
           #endif
710 731
         #endif
711 732
       #endif

Loading…
Cancel
Save