Browse Source

Fix TMC_HOME_PHASE divide by zero (#20368)

Jason Smith 4 years ago
parent
commit
21ee7b1c86
No account linked to committer's email address
1 changed files with 5 additions and 3 deletions
  1. 5
    3
      Marlin/src/module/motion.cpp

+ 5
- 3
Marlin/src/module/motion.cpp View File

@@ -1490,10 +1490,12 @@ void set_axis_never_homed(const AxisEnum axis) {
1490 1490
             effectorBackoutDir, // Direction in which the effector mm coordinates move away from endstop.
1491 1491
             stepperBackoutDir;  // Direction in which the TMC µstep count(phase) move away from endstop.
1492 1492
 
1493
+    #define PHASE_PER_MICROSTEP(N) (256 / _MAX(1, N##_MICROSTEPS))
1494
+
1493 1495
     switch (axis) {
1494 1496
       #ifdef X_MICROSTEPS
1495 1497
         case X_AXIS:
1496
-          phasePerUStep = 256 / (X_MICROSTEPS);
1498
+          phasePerUStep = PHASE_PER_MICROSTEP(X);
1497 1499
           phaseCurrent = stepperX.get_microstep_counter();
1498 1500
           effectorBackoutDir = -X_HOME_DIR;
1499 1501
           stepperBackoutDir = INVERT_X_DIR ? effectorBackoutDir : -effectorBackoutDir;
@@ -1501,7 +1503,7 @@ void set_axis_never_homed(const AxisEnum axis) {
1501 1503
       #endif
1502 1504
       #ifdef Y_MICROSTEPS
1503 1505
         case Y_AXIS:
1504
-          phasePerUStep = 256 / (Y_MICROSTEPS);
1506
+          phasePerUStep = PHASE_PER_MICROSTEP(Y);
1505 1507
           phaseCurrent = stepperY.get_microstep_counter();
1506 1508
           effectorBackoutDir = -Y_HOME_DIR;
1507 1509
           stepperBackoutDir = INVERT_Y_DIR ? effectorBackoutDir : -effectorBackoutDir;
@@ -1509,7 +1511,7 @@ void set_axis_never_homed(const AxisEnum axis) {
1509 1511
       #endif
1510 1512
       #ifdef Z_MICROSTEPS
1511 1513
         case Z_AXIS:
1512
-          phasePerUStep = 256 / (Z_MICROSTEPS);
1514
+          phasePerUStep = PHASE_PER_MICROSTEP(Z);
1513 1515
           phaseCurrent = stepperZ.get_microstep_counter();
1514 1516
           effectorBackoutDir = -Z_HOME_DIR;
1515 1517
           stepperBackoutDir = INVERT_Z_DIR ? effectorBackoutDir : -effectorBackoutDir;

Loading…
Cancel
Save