Browse Source

Add SNMM functionality to LIN_ADVANCE

Sebastianv650 6 years ago
parent
commit
d1d3949717
4 changed files with 27 additions and 19 deletions
  1. 1 1
      Firmware/Configuration_adv.h
  2. 6 1
      Firmware/Marlin_main.cpp
  3. 19 17
      Firmware/stepper.cpp
  4. 1 0
      Firmware/stepper.h

+ 1 - 1
Firmware/Configuration_adv.h

@@ -275,7 +275,7 @@
 //#define LIN_ADVANCE
 
 #ifdef LIN_ADVANCE
-  #define LIN_ADVANCE_K 0 //Try around 45 for PLA
+  #define LIN_ADVANCE_K 0 //Try around 45 for PLA, around 25 for ABS.
 
   /**
    * Some Slicers produce Gcode with randomly jumping extrusion widths occasionally.

+ 6 - 1
Firmware/Marlin_main.cpp

@@ -5549,7 +5549,12 @@ case 404:  //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
 		  }
 		  snmm_filaments_used |= (1 << tmp_extruder); //for stop print
 #ifdef SNMM
-		  snmm_extruder = tmp_extruder;
+      #ifdef LIN_ADVANCE
+        if (snmm_extruder != tmp_extruder)
+          clear_current_adv_vars(); //Check if the selected extruder is not the active one and reset LIN_ADVANCE variables if so.
+      #endif
+      
+      snmm_extruder = tmp_extruder;
 
 		  st_synchronize();
 		  delay(100);

+ 19 - 17
Firmware/stepper.cpp

@@ -730,24 +730,21 @@ void isr() {
 
     nextAdvanceISR = eISR_Rate;
 
-    #define SET_E_STEP_DIR(INDEX) \
-      if (e_steps) WRITE(E## INDEX ##_DIR_PIN, e_steps < 0 ? INVERT_E## INDEX ##_DIR : !INVERT_E## INDEX ##_DIR)
-
-    #define START_E_PULSE(INDEX) \
-      if (e_steps) WRITE(E## INDEX ##_STEP_PIN, !INVERT_E_STEP_PIN)
-
-    #define STOP_E_PULSE(INDEX) \
-      if (e_steps) { \
-        e_steps < 0 ? ++e_steps : --e_steps; \
-        WRITE(E## INDEX ##_STEP_PIN, INVERT_E_STEP_PIN); \
+    if (e_steps) {
+      bool dir =
+      #ifdef SNMM
+        ((e_steps < 0) == (snmm_extruder & 1))
+      #else
+        (e_steps < 0)
+      #endif
+      ? INVERT_E0_DIR : !INVERT_E0_DIR; //If we have SNMM, reverse every second extruder.
+      WRITE(E0_DIR_PIN, dir);
+  
+      for (uint8_t i = step_loops; e_steps && i--;) {
+        WRITE(E0_STEP_PIN, !INVERT_E_STEP_PIN);
+        e_steps < 0 ? ++e_steps : --e_steps;
+        WRITE(E0_STEP_PIN, INVERT_E_STEP_PIN);
       }
-
-    SET_E_STEP_DIR(0);
-
-    for (uint8_t i = step_loops; i--;) {
-      START_E_PULSE(0);
-
-      STOP_E_PULSE(0);
     }
   }
 
@@ -780,6 +777,11 @@ void isr() {
     // Don't run the ISR faster than possible
     if (OCR1A < TCNT1 + 16) OCR1A = TCNT1 + 16;
   }
+  
+  void clear_current_adv_vars() {
+    e_steps = 0; //Should be already 0 at an filament change event, but just to be sure..
+    current_adv_steps = 0;
+  }
 
 #endif // LIN_ADVANCE
 

+ 1 - 0
Firmware/stepper.h

@@ -51,6 +51,7 @@ void isr();
 #ifdef LIN_ADVANCE
   void advance_isr();
   void advance_isr_scheduler();
+  void clear_current_adv_vars(); //Used to reset the built up pretension and remaining esteps on filament change.
 #endif
 
 // Block until all buffered steps are executed