Skip to content

Commit

Permalink
Fix TMC_HOME_PHASE divide by zero (MarlinFirmware#20368)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjasonsmith authored and Ramis84 committed Jan 27, 2021
1 parent ee92f9c commit 6ef485d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Marlin/src/module/motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1466,26 +1466,28 @@ void set_axis_never_homed(const AxisEnum axis) {
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.

#define PHASE_PER_MICROSTEP(N) (256 / _MAX(1, N##_MICROSTEPS))

switch (axis) {
#ifdef X_MICROSTEPS
case X_AXIS:
phasePerUStep = 256 / (X_MICROSTEPS);
phasePerUStep = PHASE_PER_MICROSTEP(X);
phaseCurrent = stepperX.get_microstep_counter();
effectorBackoutDir = -X_HOME_DIR;
stepperBackoutDir = INVERT_X_DIR ? effectorBackoutDir : -effectorBackoutDir;
break;
#endif
#ifdef Y_MICROSTEPS
case Y_AXIS:
phasePerUStep = 256 / (Y_MICROSTEPS);
phasePerUStep = PHASE_PER_MICROSTEP(Y);
phaseCurrent = stepperY.get_microstep_counter();
effectorBackoutDir = -Y_HOME_DIR;
stepperBackoutDir = INVERT_Y_DIR ? effectorBackoutDir : -effectorBackoutDir;
break;
#endif
#ifdef Z_MICROSTEPS
case Z_AXIS:
phasePerUStep = 256 / (Z_MICROSTEPS);
phasePerUStep = PHASE_PER_MICROSTEP(Z);
phaseCurrent = stepperZ.get_microstep_counter();
effectorBackoutDir = -Z_HOME_DIR;
stepperBackoutDir = INVERT_Z_DIR ? effectorBackoutDir : -effectorBackoutDir;
Expand Down

0 comments on commit 6ef485d

Please sign in to comment.