From 6429ceec9a2abe8d2a9d185d4fc58888a67e2246 Mon Sep 17 00:00:00 2001 From: Vedran <36977084+vedransi@users.noreply.github.com> Date: Wed, 11 Dec 2024 21:27:30 +1100 Subject: [PATCH 1/5] Update Configuration.h Added two code blocks for Differential extruder --- Marlin/Configuration.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index c45c75a39d96..4bcd24d6e60f 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -222,6 +222,20 @@ // :[0, 1, 2, 3, 4, 5, 6, 7, 8] #define EXTRUDERS 1 +/// Beginning of a Differential Extruder block 1/5 //// +// This is defined when a differential extruder is present +#define DIFFERENTIAL_EXTRUDER +// +// Differential Extruder currently works only for single-extruder RepRap 32-bit platforms. +// Otherwise, disable Differential Extruder +#if ENABLED(DIFFERENTIAL_EXTRUDER) + #if !((EXTRUDERS == 1) && (MOTHERBOARD == BOARD_CREALITY_V4)) + #undef DIFFERENTIAL_EXTRUDER + #endif +#endif +//// End of a Differential Extruder block 1/5 //// + + // Generally expected filament diameter (1.75, 2.85, 3.0, ...). Used for Volumetric, Filament Width Sensor, etc. #define DEFAULT_NOMINAL_FILAMENT_DIA 1.75 @@ -3656,6 +3670,17 @@ #define PRINTER_EVENT_LEDS #endif +/// Beginning of a Differential Extruder block 2/5 //// +// Differential Extruder currently works only for single-extruder RepRap 32-bit platforms. +// Otherwise, disable Differential Extruder +#if ENABLED(DIFFERENTIAL_EXTRUDER) + #if !((EXTRUDERS == 1) && (MOTHERBOARD == BOARD_CREALITY_V4)) + #undef DIFFERENTIAL_EXTRUDER + #endif +#endif +//// End of a Differential Extruder block 2/5 //// + + // @section servos /** From aeb176b5298715e42da0981910f0c8d1c723ecaf Mon Sep 17 00:00:00 2001 From: Vedran <36977084+vedransi@users.noreply.github.com> Date: Wed, 11 Dec 2024 21:32:41 +1100 Subject: [PATCH 2/5] Update planner.cpp Added the Differential Extruder block --- Marlin/src/module/planner.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp index 630557180ba2..1899a428dbf0 100644 --- a/Marlin/src/module/planner.cpp +++ b/Marlin/src/module/planner.cpp @@ -77,6 +77,10 @@ #include "../MarlinCore.h" +#if ENABLED(DIFFERENTIAL_EXTRUDER) + #include "printcounter.h" +#endif + #if HAS_LEVELING #include "../feature/bedlevel/bedlevel.h" #endif @@ -3053,6 +3057,22 @@ bool Planner::buffer_line(const xyze_pos_t &cart, const_feedRate_t fr_mm_s #else // !IS_KINEMATIC + //// Beginning of a Differential Extruder block 3/5 //// + // When a differential extruder is present, planner.cpp adds the X movement to the E movement and send the sum to the E stepper. + // This addition is performed only when a print job is running. When a print job is not running, the differential extruder is handled by stepper.cpp + #if ENABLED(DIFFERENTIAL_EXTRUDER) + if (print_job_timer.isRunning()) { + // Calculate the steps for X and E + long x_steps = lround(machine.x / mm_per_step[X_AXIS]); + long e_steps = lround(machine.e / mm_per_step[E_AXIS]); + // Calculate the differential steps for the extruder + e_steps += x_steps; + // Update the machine position with the differential steps + machine.e = e_steps * mm_per_step[E_AXIS]; + } + #endif + //// End of a Differential Extruder block 3/5 //// + return buffer_segment(machine, fr_mm_s, extruder, hints); #endif From 4606d523af3bdeceeb6e6e6cb92fbd346c22e36f Mon Sep 17 00:00:00 2001 From: Vedran <36977084+vedransi@users.noreply.github.com> Date: Wed, 11 Dec 2024 21:40:02 +1100 Subject: [PATCH 3/5] Update stepper.cpp Added the fourth and fifth code blocks for Differential Extruder --- Marlin/src/module/stepper.cpp | 71 +++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index 5083c0a4d28d..3c41dcf9f07b 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -98,6 +98,10 @@ Stepper stepper; // Singleton #include "planner.h" #include "motion.h" +#if ENABLED(DIFFERENTIAL_EXTRUDER) + #include "printcounter.h" +#endif + #if ENABLED(FT_MOTION) #include "ft_motion.h" #endif @@ -1846,19 +1850,64 @@ void Stepper::pulse_phase_isr() { }while(0) // Start an active pulse if needed - #define PULSE_START(AXIS) do{ \ - if (step_needed.test(_AXIS(AXIS))) { \ - count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \ - _APPLY_STEP(AXIS, _STEP_STATE(AXIS), 0); \ - } \ - }while(0) + #if ENABLED(DIFFERENTIAL_EXTRUDER) + #define PULSE_START(AXIS) do{ \ + if (step_needed.test(_AXIS(AXIS))) { \ + count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \ + _APPLY_STEP(AXIS, _STEP_STATE(AXIS), 0); \ + /* Beginning of a Differential Extruder block 4/5 */ \ + if (!print_job_timer.isRunning()) { \ + if (_AXIS(AXIS) == X_AXIS) { \ + /* Set the direction of the E stepper to match the X stepper */ \ + if (count_direction[X_AXIS] > 0) { \ + FWD_E_DIR(stepper_extruder); \ + } else { \ + REV_E_DIR(stepper_extruder); \ + } \ + /* Add the pulse to the E stepper */ \ + E_APPLY_STEP(HIGH, 0); \ + } \ + } \ + /* End of a Differential Extruder block 4/5 */ \ + } \ + }while(0) + #else + #define PULSE_START(AXIS) do{ \ + if (step_needed.test(_AXIS(AXIS))) { \ + count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \ + _APPLY_STEP(AXIS, _STEP_STATE(AXIS), 0); \ + } \ + }while(0) + #endif // Stop an active pulse if needed - #define PULSE_STOP(AXIS) do { \ - if (step_needed.test(_AXIS(AXIS))) { \ - _APPLY_STEP(AXIS, !_STEP_STATE(AXIS), 0); \ - } \ - }while(0) + #if ENABLED(DIFFERENTIAL_EXTRUDER) + #define PULSE_STOP(AXIS) do { \ + if (step_needed.test(_AXIS(AXIS))) { \ + _APPLY_STEP(AXIS, !_STEP_STATE(AXIS), 0); \ + /* Beginning of a Differential Extruder block 5/5 */ \ + if (!print_job_timer.isRunning()) { \ + if (_AXIS(AXIS) == X_AXIS) { \ + /* Set the direction of the E stepper to match the X stepper */ \ + if (count_direction[X_AXIS] > 0) { \ + FWD_E_DIR(stepper_extruder); \ + } else { \ + REV_E_DIR(stepper_extruder); \ + } \ + /* Stop the Differential pulse to the E stepper */ \ + E_APPLY_STEP(LOW, 0); \ + } \ + } \ + /* End of a Differential Extruder block 5/5 */ \ + } \ + }while(0) + #else + #define PULSE_STOP(AXIS) do { \ + if (step_needed.test(_AXIS(AXIS))) { \ + _APPLY_STEP(AXIS, !_STEP_STATE(AXIS), 0); \ + } \ + }while(0) + #endif #if ENABLED(DIRECT_STEPPING) // Direct stepping is currently not ready for HAS_I_AXIS From 812e2e43555561d749a6253eb9cec4f633a84cfd Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 12 Dec 2024 14:22:54 -0600 Subject: [PATCH 4/5] clean up and optimize --- Marlin/Configuration.h | 29 +++---------- Marlin/src/inc/SanityCheck.h | 5 +++ Marlin/src/module/planner.cpp | 13 +++--- Marlin/src/module/stepper.cpp | 82 ++++++++++++----------------------- 4 files changed, 42 insertions(+), 87 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 4bcd24d6e60f..2a189964c780 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -222,19 +222,11 @@ // :[0, 1, 2, 3, 4, 5, 6, 7, 8] #define EXTRUDERS 1 -/// Beginning of a Differential Extruder block 1/5 //// -// This is defined when a differential extruder is present -#define DIFFERENTIAL_EXTRUDER -// -// Differential Extruder currently works only for single-extruder RepRap 32-bit platforms. -// Otherwise, disable Differential Extruder -#if ENABLED(DIFFERENTIAL_EXTRUDER) - #if !((EXTRUDERS == 1) && (MOTHERBOARD == BOARD_CREALITY_V4)) - #undef DIFFERENTIAL_EXTRUDER - #endif -#endif -//// End of a Differential Extruder block 1/5 //// - +/** + * Differential Extruder + * Currently works only for single-extruder RepRap 32-bit. + */ +//#define DIFFERENTIAL_EXTRUDER // Generally expected filament diameter (1.75, 2.85, 3.0, ...). Used for Volumetric, Filament Width Sensor, etc. #define DEFAULT_NOMINAL_FILAMENT_DIA 1.75 @@ -3670,17 +3662,6 @@ #define PRINTER_EVENT_LEDS #endif -/// Beginning of a Differential Extruder block 2/5 //// -// Differential Extruder currently works only for single-extruder RepRap 32-bit platforms. -// Otherwise, disable Differential Extruder -#if ENABLED(DIFFERENTIAL_EXTRUDER) - #if !((EXTRUDERS == 1) && (MOTHERBOARD == BOARD_CREALITY_V4)) - #undef DIFFERENTIAL_EXTRUDER - #endif -#endif -//// End of a Differential Extruder block 2/5 //// - - // @section servos /** diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 9c21c4fd2960..e11018410409 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -4503,6 +4503,11 @@ static_assert(WITHIN(MULTISTEPPING_LIMIT, 1, 128) && IS_POWER_OF_2(MULTISTEPPING #error "Only enable ULTIPANEL_FEEDMULTIPLY or ULTIPANEL_FLOWPERCENT, but not both." #endif +// Differential Extruder requires the magic of Creality V4 +#if ENABLED(DIFFERENTIAL_EXTRUDER) && !(EXTRUDERS == 1 && MB(CREALITY_V4)) + #error "DIFFERENTIAL_EXTRUDER requires MOTHERBOARD BOARD_CREALITY_V4 and EXTRUDERS 1." +#endif + // Misc. Cleanup #undef _TEST_PWM #undef _NUM_AXES_STR diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp index 1899a428dbf0..726e7e9dfa1d 100644 --- a/Marlin/src/module/planner.cpp +++ b/Marlin/src/module/planner.cpp @@ -3057,21 +3057,18 @@ bool Planner::buffer_line(const xyze_pos_t &cart, const_feedRate_t fr_mm_s #else // !IS_KINEMATIC - //// Beginning of a Differential Extruder block 3/5 //// - // When a differential extruder is present, planner.cpp adds the X movement to the E movement and send the sum to the E stepper. - // This addition is performed only when a print job is running. When a print job is not running, the differential extruder is handled by stepper.cpp + // Differential Extruder + // The sum of X and E movement is applied to the E stepper. + // Outside of a print job, the differential extruder is handled by stepper.cpp. #if ENABLED(DIFFERENTIAL_EXTRUDER) if (print_job_timer.isRunning()) { - // Calculate the steps for X and E - long x_steps = lround(machine.x / mm_per_step[X_AXIS]); - long e_steps = lround(machine.e / mm_per_step[E_AXIS]); // Calculate the differential steps for the extruder - e_steps += x_steps; + const int32_t e_steps = lround(machine.e * steps_per_mm[E_AXIS]) + + lround(machine.x * steps_per_mm[X_AXIS]); // Update the machine position with the differential steps machine.e = e_steps * mm_per_step[E_AXIS]; } #endif - //// End of a Differential Extruder block 3/5 //// return buffer_segment(machine, fr_mm_s, extruder, hints); diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index 3c41dcf9f07b..fe3d64d5dafa 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -1787,6 +1787,10 @@ void Stepper::pulse_phase_isr() { // Direct Stepping page? const bool is_page = current_block->is_page(); + #if ENABLED(DIFFERENTIAL_EXTRUDER) + const bool is_print_job = print_job_timer.isRunning(); + #endif + do { AxisFlags step_needed{0}; @@ -1849,65 +1853,33 @@ void Stepper::pulse_phase_isr() { DELTA_ERROR = de; \ }while(0) - // Start an active pulse if needed - #if ENABLED(DIFFERENTIAL_EXTRUDER) - #define PULSE_START(AXIS) do{ \ - if (step_needed.test(_AXIS(AXIS))) { \ - count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \ - _APPLY_STEP(AXIS, _STEP_STATE(AXIS), 0); \ - /* Beginning of a Differential Extruder block 4/5 */ \ - if (!print_job_timer.isRunning()) { \ - if (_AXIS(AXIS) == X_AXIS) { \ - /* Set the direction of the E stepper to match the X stepper */ \ - if (count_direction[X_AXIS] > 0) { \ - FWD_E_DIR(stepper_extruder); \ - } else { \ - REV_E_DIR(stepper_extruder); \ - } \ - /* Add the pulse to the E stepper */ \ - E_APPLY_STEP(HIGH, 0); \ - } \ - } \ - /* End of a Differential Extruder block 4/5 */ \ - } \ - }while(0) + // Differential Extruder moves E along with X + #if ENABLED(DIFFERENTIAL_EXTRUDER) + #define DIFFERENTIAL_E_PULSE(AXIS, ONSTEP) \ + if (!is_print_job && _AXIS(AXIS) == X_AXIS) { \ + E_APPLY_DIR(count_direction[X_AXIS] > 0, false); /* Match E direction to X */ \ + E_APPLY_STEP(ONSTEP ? _STEP_STATE(E) : !_STEP_STATE(E), false); /* Add the pulse to the E stepper */ \ + } #else - #define PULSE_START(AXIS) do{ \ - if (step_needed.test(_AXIS(AXIS))) { \ - count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \ - _APPLY_STEP(AXIS, _STEP_STATE(AXIS), 0); \ - } \ - }while(0) + #define DIFFERENTIAL_E_PULSE(...) NOOP #endif + // Start an active pulse if needed + #define PULSE_START(AXIS) do{ \ + if (step_needed.test(_AXIS(AXIS))) { \ + count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \ + _APPLY_STEP(AXIS, _STEP_STATE(AXIS), false); \ + DIFFERENTIAL_E_PULSE(AXIS, true); \ + } \ + }while(0) + // Stop an active pulse if needed - #if ENABLED(DIFFERENTIAL_EXTRUDER) - #define PULSE_STOP(AXIS) do { \ - if (step_needed.test(_AXIS(AXIS))) { \ - _APPLY_STEP(AXIS, !_STEP_STATE(AXIS), 0); \ - /* Beginning of a Differential Extruder block 5/5 */ \ - if (!print_job_timer.isRunning()) { \ - if (_AXIS(AXIS) == X_AXIS) { \ - /* Set the direction of the E stepper to match the X stepper */ \ - if (count_direction[X_AXIS] > 0) { \ - FWD_E_DIR(stepper_extruder); \ - } else { \ - REV_E_DIR(stepper_extruder); \ - } \ - /* Stop the Differential pulse to the E stepper */ \ - E_APPLY_STEP(LOW, 0); \ - } \ - } \ - /* End of a Differential Extruder block 5/5 */ \ - } \ - }while(0) - #else - #define PULSE_STOP(AXIS) do { \ - if (step_needed.test(_AXIS(AXIS))) { \ - _APPLY_STEP(AXIS, !_STEP_STATE(AXIS), 0); \ - } \ - }while(0) - #endif + #define PULSE_STOP(AXIS) do { \ + if (step_needed.test(_AXIS(AXIS))) { \ + _APPLY_STEP(AXIS, !_STEP_STATE(AXIS), false); \ + DIFFERENTIAL_E_PULSE(AXIS, false); \ + } \ + }while(0) #if ENABLED(DIRECT_STEPPING) // Direct stepping is currently not ready for HAS_I_AXIS From 99d821da142e5ef658d37f05d4dc671dd9f94535 Mon Sep 17 00:00:00 2001 From: Vedran <36977084+vedransi@users.noreply.github.com> Date: Sat, 14 Dec 2024 14:32:13 +1100 Subject: [PATCH 5/5] Updated planner.cpp I was getting a "red wavy underline" warning that steps_per_mm variable was not defined. Edited the name of the variable as per Copilot's suggestion. Compiled, uploaded, printer prints ok, so it's probably all good. --- Marlin/src/module/planner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp index 726e7e9dfa1d..5c596311f41f 100644 --- a/Marlin/src/module/planner.cpp +++ b/Marlin/src/module/planner.cpp @@ -3063,8 +3063,8 @@ bool Planner::buffer_line(const xyze_pos_t &cart, const_feedRate_t fr_mm_s #if ENABLED(DIFFERENTIAL_EXTRUDER) if (print_job_timer.isRunning()) { // Calculate the differential steps for the extruder - const int32_t e_steps = lround(machine.e * steps_per_mm[E_AXIS]) - + lround(machine.x * steps_per_mm[X_AXIS]); + const int32_t e_steps = lround(machine.e * settings.axis_steps_per_mm[E_AXIS]) + + lround(machine.x * settings.axis_steps_per_mm[X_AXIS]); // Update the machine position with the differential steps machine.e = e_steps * mm_per_step[E_AXIS]; }