Browse Source

Merge pull request #9971 from thinkyhead/bf2_lin_advance_duplication

[2.0.x] Support duplication mode in LIN_ADVANCE
Scott Lahteine 6 years ago
parent
commit
d7aed2fe4f
No account linked to committer's email address
2 changed files with 34 additions and 28 deletions
  1. 22
    19
      Marlin/src/module/stepper.cpp
  2. 12
    9
      Marlin/src/module/stepper.h

+ 22
- 19
Marlin/src/module/stepper.cpp View File

@@ -122,8 +122,13 @@ volatile uint32_t Stepper::step_events_completed = 0; // The number of step even
122 122
            Stepper::final_adv_steps,
123 123
            Stepper::max_adv_steps;
124 124
 
125
-  int8_t Stepper::e_steps = 0,
126
-         Stepper::LA_active_extruder; // Copy from current executed block. Needed because current_block is set to NULL "too early".
125
+  int8_t Stepper::e_steps = 0;
126
+
127
+  #if E_STEPPERS > 1
128
+    int8_t Stepper::LA_active_extruder; // Copy from current executed block. Needed because current_block is set to NULL "too early".
129
+  #else
130
+    constexpr int8_t Stepper::LA_active_extruder;
131
+  #endif
127 132
 
128 133
   bool Stepper::use_advance_lead;
129 134
 
@@ -755,23 +760,21 @@ void Stepper::isr() {
755 760
 
756 761
   void Stepper::advance_isr() {
757 762
 
758
-    #if ENABLED(MK2_MULTIPLEXER)
759
-      // Even-numbered steppers are reversed
760
-      #define SET_E_STEP_DIR(INDEX) \
761
-        if (e_steps) E## INDEX ##_DIR_WRITE(e_steps < 0 ? !INVERT_E## INDEX ##_DIR ^ TEST(INDEX, 0) : INVERT_E## INDEX ##_DIR ^ TEST(INDEX, 0))
763
+    #if ENABLED(MK2_MULTIPLEXER) // For SNMM even-numbered steppers are reversed
764
+      #define SET_E_STEP_DIR(INDEX) do{ if (e_steps) E## INDEX ##_DIR_WRITE(e_steps < 0 ? !INVERT_E## INDEX ##_DIR ^ TEST(INDEX, 0) : INVERT_E## INDEX ##_DIR ^ TEST(INDEX, 0)); }while(0)
765
+    #elif ENABLED(DUAL_X_CARRIAGE) || ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
766
+      #define SET_E_STEP_DIR(INDEX) do{ if (e_steps) { e_steps < 0 ? REV_E_DIR() : NORM_E_DIR(); } }while(0)
762 767
     #else
763
-      #define SET_E_STEP_DIR(INDEX) \
764
-        if (e_steps) E## INDEX ##_DIR_WRITE(e_steps < 0 ? INVERT_E## INDEX ##_DIR : !INVERT_E## INDEX ##_DIR)
768
+      #define SET_E_STEP_DIR(INDEX) do{ if (e_steps) E## INDEX ##_DIR_WRITE(e_steps < 0 ? INVERT_E## INDEX ##_DIR : !INVERT_E## INDEX ##_DIR); }while(0)
765 769
     #endif
766 770
 
767
-    #define START_E_PULSE(INDEX) \
768
-      if (e_steps) E## INDEX ##_STEP_WRITE(!INVERT_E_STEP_PIN)
769
-
770
-    #define STOP_E_PULSE(INDEX) \
771
-      if (e_steps) { \
772
-        e_steps < 0 ? ++e_steps : --e_steps; \
773
-        E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN); \
774
-      }
771
+    #if ENABLED(DUAL_X_CARRIAGE) || ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
772
+      #define START_E_PULSE(INDEX) do{ if (e_steps) E_STEP_WRITE(!INVERT_E_STEP_PIN); }while(0)
773
+      #define STOP_E_PULSE(INDEX) do{ if (e_steps) { E_STEP_WRITE(INVERT_E_STEP_PIN); e_steps < 0 ? ++e_steps : --e_steps; } }while(0)
774
+    #else
775
+      #define START_E_PULSE(INDEX) do{ if (e_steps) E## INDEX ##_STEP_WRITE(!INVERT_E_STEP_PIN); }while(0)
776
+      #define STOP_E_PULSE(INDEX) do { if (e_steps) { E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN); e_steps < 0 ? ++e_steps : --e_steps; } }while(0)
777
+    #endif
775 778
 
776 779
     if (current_block->use_advance_lead) {
777 780
       if (step_events_completed > LA_decelerate_after && current_adv_steps > final_adv_steps) {
@@ -793,7 +796,7 @@ void Stepper::isr() {
793 796
     else
794 797
       nextAdvanceISR = ADV_NEVER;
795 798
 
796
-    switch(LA_active_extruder) {
799
+    switch (LA_active_extruder) {
797 800
       case 0: SET_E_STEP_DIR(0); break;
798 801
       #if EXTRUDERS > 1
799 802
         case 1: SET_E_STEP_DIR(1); break;
@@ -816,7 +819,7 @@ void Stepper::isr() {
816 819
         hal_timer_t pulse_start = HAL_timer_get_count(PULSE_TIMER_NUM);
817 820
       #endif
818 821
 
819
-      switch(LA_active_extruder) {
822
+      switch (LA_active_extruder) {
820 823
         case 0: START_E_PULSE(0); break;
821 824
         #if EXTRUDERS > 1
822 825
           case 1: START_E_PULSE(1); break;
@@ -840,7 +843,7 @@ void Stepper::isr() {
840 843
         DELAY_NOPS(EXTRA_CYCLES_E);
841 844
       #endif
842 845
 
843
-      switch(LA_active_extruder) {
846
+      switch (LA_active_extruder) {
844 847
         case 0: STOP_E_PULSE(0); break;
845 848
         #if EXTRUDERS > 1
846 849
           case 1: STOP_E_PULSE(1); break;

+ 12
- 9
Marlin/src/module/stepper.h View File

@@ -104,8 +104,12 @@ class Stepper {
104 104
       static uint16_t current_adv_steps, final_adv_steps, max_adv_steps; // Copy from current executed block. Needed because current_block is set to NULL "too early".
105 105
       #define _NEXT_ISR(T) nextMainISR = T
106 106
       static int8_t e_steps;
107
-      static int8_t LA_active_extruder; // Copy from current executed block. Needed because current_block is set to NULL "too early".
108 107
       static bool use_advance_lead;
108
+      #if E_STEPPERS > 1
109
+        static int8_t LA_active_extruder; // Copy from current executed block. Needed because current_block is set to NULL "too early".
110
+      #else
111
+        constexpr int8_t LA_active_extruder = 0;
112
+      #endif
109 113
 
110 114
     #else // !LIN_ADVANCE
111 115
 
@@ -352,19 +356,18 @@ class Stepper {
352 356
       static int8_t last_extruder = -1;
353 357
 
354 358
       #if ENABLED(LIN_ADVANCE)
355
-        if (current_block->active_extruder != last_extruder) {
356
-          current_adv_steps = 0; // If the now active extruder wasn't in use during the last move, its pressure is most likely gone.
357
-          LA_active_extruder = current_block->active_extruder;
358
-        }
359
+        #if E_STEPPERS > 1
360
+          if (current_block->active_extruder != last_extruder) {
361
+            current_adv_steps = 0; // If the now active extruder wasn't in use during the last move, its pressure is most likely gone.
362
+            LA_active_extruder = current_block->active_extruder;
363
+          }
364
+        #endif
359 365
 
360
-        if (current_block->use_advance_lead) {
366
+        if ((use_advance_lead = current_block->use_advance_lead)) {
361 367
           LA_decelerate_after = current_block->decelerate_after;
362 368
           final_adv_steps = current_block->final_adv_steps;
363 369
           max_adv_steps = current_block->max_adv_steps;
364
-          use_advance_lead = true;
365 370
         }
366
-        else
367
-          use_advance_lead = false;
368 371
       #endif
369 372
 
370 373
       if (current_block->direction_bits != last_direction_bits || current_block->active_extruder != last_extruder) {

Loading…
Cancel
Save