diff --git a/Firmware/Configuration_adv.h b/Firmware/Configuration_adv.h index 306496fa0..1bc928a10 100644 --- a/Firmware/Configuration_adv.h +++ b/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. diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index f2aaa8ff7..8c91d877f 100644 --- a/Firmware/Marlin_main.cpp +++ b/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); diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index f39a9f0f6..7c6a23397 100644 --- a/Firmware/stepper.cpp +++ b/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 diff --git a/Firmware/stepper.h b/Firmware/stepper.h index 39c14abba..3427f12fa 100644 --- a/Firmware/stepper.h +++ b/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