From 5ef0475dc5cd8caecaef7e4fe5398b49b8558874 Mon Sep 17 00:00:00 2001 From: wilbur4321 Date: Tue, 5 Jan 2021 15:03:45 -0800 Subject: [PATCH] Multi-Z stepper inverting (#20678) Co-authored-by: Scott Lahteine --- Marlin/Configuration.h | 4 ++-- Marlin/Configuration_adv.h | 9 +++++++-- Marlin/src/inc/Conditionals_adv.h | 16 ++++++++++------ Marlin/src/libs/L64XX/L64XX_Marlin.cpp | 15 +++++---------- Marlin/src/module/stepper.cpp | 11 ++++++++--- 5 files changed, 32 insertions(+), 23 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index c283c86dd..ab112894b 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -1089,7 +1089,7 @@ //#define PROBING_STEPPERS_OFF // Turn steppers off (unless needed to hold position) when probing //#define DELAY_BEFORE_PROBING 200 // (ms) To prevent vibrations from triggering piezo sensors -// Require minimum nozzle and/or bed temperature for probing. +// Require minimum nozzle and/or bed temperature for probing //#define PREHEAT_BEFORE_PROBING #if ENABLED(PREHEAT_BEFORE_PROBING) #define PROBING_NOZZLE_TEMP 120 // (°C) Only applies to E0 at this time @@ -2428,7 +2428,7 @@ //#define TOUCH_CALIBRATION_Y -8981 //#define TOUCH_OFFSET_X -43 //#define TOUCH_OFFSET_Y 257 - //#define TOUCH_ORIENTATION TOUCH_LANDSCAPE + //#define TOUCH_ORIENTATION TOUCH_LANDSCAPE #if ENABLED(TFT_COLOR_UI) //#define SINGLE_TOUCH_NAVIGATION diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 0a51c795d..c17606469 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -552,7 +552,7 @@ //#define X_DUAL_STEPPER_DRIVERS #if ENABLED(X_DUAL_STEPPER_DRIVERS) - #define INVERT_X2_VS_X_DIR true // Set 'true' if X motors should rotate in opposite directions + //#define INVERT_X2_VS_X_DIR // Enable if X2 direction signal is opposite to X //#define X_DUAL_ENDSTOPS #if ENABLED(X_DUAL_ENDSTOPS) #define X2_USE_ENDSTOP _XMAX_ @@ -562,7 +562,7 @@ //#define Y_DUAL_STEPPER_DRIVERS #if ENABLED(Y_DUAL_STEPPER_DRIVERS) - #define INVERT_Y2_VS_Y_DIR true // Set 'true' if Y motors should rotate in opposite directions + //#define INVERT_Y2_VS_Y_DIR // Enable if Y2 direction signal is opposite to Y //#define Y_DUAL_ENDSTOPS #if ENABLED(Y_DUAL_ENDSTOPS) #define Y2_USE_ENDSTOP _YMAX_ @@ -576,6 +576,11 @@ #define NUM_Z_STEPPER_DRIVERS 1 // (1-4) Z options change based on how many #if NUM_Z_STEPPER_DRIVERS > 1 + // Enable if Z motor direction signals are the opposite of Z1 + //#define INVERT_Z2_VS_Z_DIR + //#define INVERT_Z3_VS_Z_DIR + //#define INVERT_Z4_VS_Z_DIR + //#define Z_MULTI_ENDSTOPS #if ENABLED(Z_MULTI_ENDSTOPS) #define Z2_USE_ENDSTOP _XMAX_ diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index dda029874..d650d3221 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/Marlin/src/inc/Conditionals_adv.h @@ -211,14 +211,18 @@ #if DISABLED(Y_DUAL_STEPPER_DRIVERS) #undef Y2_DRIVER_TYPE #endif -#if NUM_Z_STEPPER_DRIVERS < 2 - #undef Z2_DRIVER_TYPE -#endif -#if NUM_Z_STEPPER_DRIVERS < 3 - #undef Z3_DRIVER_TYPE -#endif + #if NUM_Z_STEPPER_DRIVERS < 4 #undef Z4_DRIVER_TYPE + #undef INVERT_Z4_VS_Z_DIR + #if NUM_Z_STEPPER_DRIVERS < 3 + #undef Z3_DRIVER_TYPE + #undef INVERT_Z3_VS_Z_DIR + #if NUM_Z_STEPPER_DRIVERS < 2 + #undef Z2_DRIVER_TYPE + #undef INVERT_Z2_VS_Z_DIR + #endif + #endif #endif // diff --git a/Marlin/src/libs/L64XX/L64XX_Marlin.cpp b/Marlin/src/libs/L64XX/L64XX_Marlin.cpp index 8914bc560..7d36a02d6 100644 --- a/Marlin/src/libs/L64XX/L64XX_Marlin.cpp +++ b/Marlin/src/libs/L64XX/L64XX_Marlin.cpp @@ -60,16 +60,11 @@ uint8_t L64XX_Marlin::dir_commands[MAX_L64XX]; // array to hold direction comma const uint8_t L64XX_Marlin::index_to_dir[MAX_L64XX] = { INVERT_X_DIR, INVERT_Y_DIR, INVERT_Z_DIR - , (INVERT_X_DIR) // X2 - #if ENABLED(X_DUAL_STEPPER_DRIVERS) - ^ ENABLED(INVERT_X2_VS_X_DIR) - #endif - , (INVERT_Y_DIR) // Y2 - #if ENABLED(Y_DUAL_STEPPER_DRIVERS) - ^ ENABLED(INVERT_Y2_VS_Y_DIR) - #endif - , INVERT_Z_DIR, INVERT_Z_DIR, INVERT_Z_DIR // Z2,Z3,Z4 - + , (INVERT_X_DIR) ^ BOTH(X_DUAL_STEPPER_DRIVERS, INVERT_X2_VS_X_DIR) // X2 + , (INVERT_Y_DIR) ^ BOTH(Y_DUAL_STEPPER_DRIVERS, INVERT_Y2_VS_Y_DIR) // Y2 + , (INVERT_Z_DIR) ^ ENABLED(INVERT_Z2_VS_Z_DIR) // Z2 + , (INVERT_Z_DIR) ^ ENABLED(INVERT_Z3_VS_Z_DIR) // Z3 + , (INVERT_Z_DIR) ^ ENABLED(INVERT_Z4_VS_Z_DIR) // Z4 , INVERT_E0_DIR, INVERT_E1_DIR, INVERT_E2_DIR, INVERT_E3_DIR , INVERT_E4_DIR, INVERT_E5_DIR, INVERT_E6_DIR, INVERT_E7_DIR }; diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index 8b4bc23cb..c92dd4512 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -381,7 +381,10 @@ xyze_int8_t Stepper::count_direction{0}; #endif #if NUM_Z_STEPPER_DRIVERS == 4 - #define Z_APPLY_DIR(v,Q) do{ Z_DIR_WRITE(v); Z2_DIR_WRITE(v); Z3_DIR_WRITE(v); Z4_DIR_WRITE(v); }while(0) + #define Z_APPLY_DIR(v,Q) do{ \ + Z_DIR_WRITE(v); Z2_DIR_WRITE((v) ^ ENABLED(INVERT_Z2_VS_Z_DIR)); \ + Z3_DIR_WRITE((v) ^ ENABLED(INVERT_Z3_VS_Z_DIR)); Z4_DIR_WRITE((v) ^ ENABLED(INVERT_Z4_VS_Z_DIR)); \ + }while(0) #if ENABLED(Z_MULTI_ENDSTOPS) #define Z_APPLY_STEP(v,Q) QUAD_ENDSTOP_APPLY_STEP(Z,v) #elif ENABLED(Z_STEPPER_AUTO_ALIGN) @@ -390,7 +393,9 @@ xyze_int8_t Stepper::count_direction{0}; #define Z_APPLY_STEP(v,Q) do{ Z_STEP_WRITE(v); Z2_STEP_WRITE(v); Z3_STEP_WRITE(v); Z4_STEP_WRITE(v); }while(0) #endif #elif NUM_Z_STEPPER_DRIVERS == 3 - #define Z_APPLY_DIR(v,Q) do{ Z_DIR_WRITE(v); Z2_DIR_WRITE(v); Z3_DIR_WRITE(v); }while(0) + #define Z_APPLY_DIR(v,Q) do{ \ + Z_DIR_WRITE(v); Z2_DIR_WRITE((v) ^ ENABLED(INVERT_Z2_VS_Z_DIR)); Z3_DIR_WRITE((v) ^ ENABLED(INVERT_Z3_VS_Z_DIR)); \ + }while(0) #if ENABLED(Z_MULTI_ENDSTOPS) #define Z_APPLY_STEP(v,Q) TRIPLE_ENDSTOP_APPLY_STEP(Z,v) #elif ENABLED(Z_STEPPER_AUTO_ALIGN) @@ -399,7 +404,7 @@ xyze_int8_t Stepper::count_direction{0}; #define Z_APPLY_STEP(v,Q) do{ Z_STEP_WRITE(v); Z2_STEP_WRITE(v); Z3_STEP_WRITE(v); }while(0) #endif #elif NUM_Z_STEPPER_DRIVERS == 2 - #define Z_APPLY_DIR(v,Q) do{ Z_DIR_WRITE(v); Z2_DIR_WRITE(v); }while(0) + #define Z_APPLY_DIR(v,Q) do{ Z_DIR_WRITE(v); Z2_DIR_WRITE((v) ^ ENABLED(INVERT_Z2_VS_Z_DIR)); }while(0) #if ENABLED(Z_MULTI_ENDSTOPS) #define Z_APPLY_STEP(v,Q) DUAL_ENDSTOP_APPLY_STEP(Z,v) #elif ENABLED(Z_STEPPER_AUTO_ALIGN)