Fix TMC_HOME_PHASE divide by zero (#20368)

This commit is contained in:
Jason Smith 2020-12-04 21:58:39 -08:00 committed by GitHub
parent 5fdd949115
commit 21ee7b1c86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1490,10 +1490,12 @@ void set_axis_never_homed(const AxisEnum axis) {
effectorBackoutDir, // Direction in which the effector mm coordinates move away from endstop. effectorBackoutDir, // Direction in which the effector mm coordinates move away from endstop.
stepperBackoutDir; // Direction in which the TMC µstep count(phase) move away from endstop. stepperBackoutDir; // Direction in which the TMC µstep count(phase) move away from endstop.
#define PHASE_PER_MICROSTEP(N) (256 / _MAX(1, N##_MICROSTEPS))
switch (axis) { switch (axis) {
#ifdef X_MICROSTEPS #ifdef X_MICROSTEPS
case X_AXIS: case X_AXIS:
phasePerUStep = 256 / (X_MICROSTEPS); phasePerUStep = PHASE_PER_MICROSTEP(X);
phaseCurrent = stepperX.get_microstep_counter(); phaseCurrent = stepperX.get_microstep_counter();
effectorBackoutDir = -X_HOME_DIR; effectorBackoutDir = -X_HOME_DIR;
stepperBackoutDir = INVERT_X_DIR ? effectorBackoutDir : -effectorBackoutDir; stepperBackoutDir = INVERT_X_DIR ? effectorBackoutDir : -effectorBackoutDir;
@ -1501,7 +1503,7 @@ void set_axis_never_homed(const AxisEnum axis) {
#endif #endif
#ifdef Y_MICROSTEPS #ifdef Y_MICROSTEPS
case Y_AXIS: case Y_AXIS:
phasePerUStep = 256 / (Y_MICROSTEPS); phasePerUStep = PHASE_PER_MICROSTEP(Y);
phaseCurrent = stepperY.get_microstep_counter(); phaseCurrent = stepperY.get_microstep_counter();
effectorBackoutDir = -Y_HOME_DIR; effectorBackoutDir = -Y_HOME_DIR;
stepperBackoutDir = INVERT_Y_DIR ? effectorBackoutDir : -effectorBackoutDir; stepperBackoutDir = INVERT_Y_DIR ? effectorBackoutDir : -effectorBackoutDir;
@ -1509,7 +1511,7 @@ void set_axis_never_homed(const AxisEnum axis) {
#endif #endif
#ifdef Z_MICROSTEPS #ifdef Z_MICROSTEPS
case Z_AXIS: case Z_AXIS:
phasePerUStep = 256 / (Z_MICROSTEPS); phasePerUStep = PHASE_PER_MICROSTEP(Z);
phaseCurrent = stepperZ.get_microstep_counter(); phaseCurrent = stepperZ.get_microstep_counter();
effectorBackoutDir = -Z_HOME_DIR; effectorBackoutDir = -Z_HOME_DIR;
stepperBackoutDir = INVERT_Z_DIR ? effectorBackoutDir : -effectorBackoutDir; stepperBackoutDir = INVERT_Z_DIR ? effectorBackoutDir : -effectorBackoutDir;