From f42b81fa38be4b994cec2af582d74bf2494a89b6 Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Thu, 19 Oct 2017 16:50:49 +0200 Subject: [PATCH 1/4] linear advance fix: advance_isr and plan_set_e_position --- Firmware/Marlin_main.cpp | 4 ++-- Firmware/planner.cpp | 3 +++ Firmware/stepper.cpp | 9 ++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index faff31e85..dcea522d5 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -5764,7 +5764,9 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp else if(code_seen('T')) { + #ifdef SNMM int index; + st_synchronize(); for (index = 1; *(strchr_pointer + index) == ' ' || *(strchr_pointer + index) == '\t'; index++); if ((*(strchr_pointer + index) < '0' || *(strchr_pointer + index) > '9') && *(strchr_pointer + index) != '?') { @@ -5778,7 +5780,6 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp tmp_extruder = code_value(); } snmm_filaments_used |= (1 << tmp_extruder); //for stop print -#ifdef SNMM #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. @@ -5786,7 +5787,6 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp snmm_extruder = tmp_extruder; - st_synchronize(); delay(100); disable_e0(); diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index d6d70fb4c..c5a8f5b2f 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -1294,6 +1294,9 @@ void plan_set_z_position(const float &z) void plan_set_e_position(const float &e) { + #ifdef LIN_ADVANCE + position_float[E_AXIS] = e; + #endif position[E_AXIS] = lround(e*axis_steps_per_unit[E_AXIS]); st_set_e_position(position[E_AXIS]); } diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 0f3f65aaa..bfcf1f723 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -735,7 +735,7 @@ void isr() { void advance_isr() { - nextAdvanceISR = eISR_Rate; + nextAdvanceISR = eISR_Rate; if (e_steps) { bool dir = @@ -752,7 +752,10 @@ void isr() { e_steps < 0 ? ++e_steps : --e_steps; WRITE(E0_STEP_PIN, INVERT_E_STEP_PIN); } - } + } + else if(eISR_Rate == 0) { + nextAdvanceISR = ADV_NEVER; + } } void advance_isr_scheduler() { @@ -782,7 +785,7 @@ void isr() { } // Don't run the ISR faster than possible - if (OCR1A < TCNT1 + 16) OCR1A = TCNT1 + 16; + if (OCR1A < TCNT1 + 16) OCR1A = TCNT1 + 16; } void clear_current_adv_vars() { From 5c118a7fac50583e514e874f0a5c6b932135f07d Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Thu, 19 Oct 2017 16:53:07 +0200 Subject: [PATCH 2/4] whitespace --- Firmware/stepper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index bfcf1f723..a9c2784ee 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -735,7 +735,7 @@ void isr() { void advance_isr() { - nextAdvanceISR = eISR_Rate; + nextAdvanceISR = eISR_Rate; if (e_steps) { bool dir = @@ -785,7 +785,7 @@ void isr() { } // Don't run the ISR faster than possible - if (OCR1A < TCNT1 + 16) OCR1A = TCNT1 + 16; + if (OCR1A < TCNT1 + 16) OCR1A = TCNT1 + 16; } void clear_current_adv_vars() { From ce04b518cc8ff3c60834d2b7a667c1a8d7814488 Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Thu, 19 Oct 2017 17:21:56 +0200 Subject: [PATCH 3/4] plan_set_z_position updated --- Firmware/planner.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index c5a8f5b2f..7dd79903a 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -1288,6 +1288,9 @@ void plan_set_position(float x, float y, float z, const float &e) // Only useful in the bed leveling routine, when the mesh bed leveling is off. void plan_set_z_position(const float &z) { + #ifdef LIN_ADVANCE + position_float[Z_AXIS] = z; + #endif position[Z_AXIS] = lround(z*axis_steps_per_unit[Z_AXIS]); st_set_position(position[X_AXIS], position[Y_AXIS], position[Z_AXIS], position[E_AXIS]); } From 997937bd4c82bfe287406a9389918c8ae40d0809 Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Fri, 20 Oct 2017 09:16:30 +0200 Subject: [PATCH 4/4] advance_isr changed --- Firmware/stepper.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index a9c2784ee..0605e3abb 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -735,8 +735,6 @@ void isr() { void advance_isr() { - nextAdvanceISR = eISR_Rate; - if (e_steps) { bool dir = #ifdef SNMM @@ -753,9 +751,10 @@ void isr() { WRITE(E0_STEP_PIN, INVERT_E_STEP_PIN); } } - else if(eISR_Rate == 0) { - nextAdvanceISR = ADV_NEVER; + else{ + eISR_Rate = ADV_NEVER; } + nextAdvanceISR = eISR_Rate; } void advance_isr_scheduler() {