소스 검색

Fix TMC homing phase coils alignment (#18528)

Co-authored-by: Fabio Santos <fabiosan@live.com>
Giuliano Zaro 4 년 전
부모
커밋
9ee891c4a6
No account linked to committer's email address
2개의 변경된 파일57개의 추가작업 그리고 36개의 파일을 삭제
  1. 20
    2
      Marlin/src/feature/tmc_util.cpp
  2. 37
    34
      Marlin/src/module/motion.cpp

+ 20
- 2
Marlin/src/feature/tmc_util.cpp 파일 보기

@@ -480,6 +480,10 @@
480 480
     TMC_GLOBAL_SCALER,
481 481
     TMC_CS_ACTUAL,
482 482
     TMC_PWM_SCALE,
483
+    TMC_PWM_SCALE_SUM,
484
+    TMC_PWM_SCALE_AUTO,
485
+    TMC_PWM_OFS_AUTO,
486
+    TMC_PWM_GRAD_AUTO,
483 487
     TMC_VSENSE,
484 488
     TMC_STEALTHCHOP,
485 489
     TMC_MICROSTEPS,
@@ -492,7 +496,8 @@
492 496
     TMC_TBL,
493 497
     TMC_HEND,
494 498
     TMC_HSTRT,
495
-    TMC_SGT
499
+    TMC_SGT,
500
+    TMC_MSCNT
496 501
   };
497 502
   enum TMC_drv_status_enum : char {
498 503
     TMC_DRV_CODES,
@@ -591,7 +596,10 @@
591 596
   #if HAS_TMC220x
592 597
     static void _tmc_status(TMC2208Stepper &st, const TMC_debug_enum i) {
593 598
       switch (i) {
594
-        case TMC_PWM_SCALE: SERIAL_PRINT(st.pwm_scale_sum(), DEC); break;
599
+        case TMC_PWM_SCALE_SUM: SERIAL_PRINT(st.pwm_scale_sum(), DEC); break;
600
+        case TMC_PWM_SCALE_AUTO: SERIAL_PRINT(st.pwm_scale_auto(), DEC); break;
601
+        case TMC_PWM_OFS_AUTO: SERIAL_PRINT(st.pwm_ofs_auto(), DEC); break;
602
+        case TMC_PWM_GRAD_AUTO: SERIAL_PRINT(st.pwm_grad_auto(), DEC); break;
595 603
         case TMC_STEALTHCHOP: serialprint_truefalse(st.stealth()); break;
596 604
         case TMC_S2VSA: if (st.s2vsa()) SERIAL_CHAR('*'); break;
597 605
         case TMC_S2VSB: if (st.s2vsb()) SERIAL_CHAR('*'); break;
@@ -680,6 +688,7 @@
680 688
       case TMC_TBL: SERIAL_PRINT(st.blank_time(), DEC); break;
681 689
       case TMC_HEND: SERIAL_PRINT(st.hysteresis_end(), DEC); break;
682 690
       case TMC_HSTRT: SERIAL_PRINT(st.hysteresis_start(), DEC); break;
691
+      case TMC_MSCNT: SERIAL_PRINT(st.get_microstep_counter(), DEC); break;
683 692
       default: _tmc_status(st, i); break;
684 693
     }
685 694
   }
@@ -900,11 +909,20 @@
900 909
     #if ENABLED(MONITOR_DRIVER_STATUS)
901 910
       TMC_REPORT("triggered\n OTP\t", TMC_OTPW_TRIGGERED);
902 911
     #endif
912
+
913
+    #if HAS_TMC220x
914
+      TMC_REPORT("pwm scale sum",     TMC_PWM_SCALE_SUM);
915
+      TMC_REPORT("pwm scale auto",    TMC_PWM_SCALE_AUTO);
916
+      TMC_REPORT("pwm offset auto",   TMC_PWM_OFS_AUTO);
917
+      TMC_REPORT("pwm grad auto",     TMC_PWM_GRAD_AUTO);
918
+    #endif
919
+
903 920
     TMC_REPORT("off time",           TMC_TOFF);
904 921
     TMC_REPORT("blank time",         TMC_TBL);
905 922
     TMC_REPORT("hysteresis\n -end\t", TMC_HEND);
906 923
     TMC_REPORT(" -start\t",          TMC_HSTRT);
907 924
     TMC_REPORT("Stallguard thrs",    TMC_SGT);
925
+    TMC_REPORT("uStep count",        TMC_MSCNT);
908 926
     DRV_REPORT("DRVSTATUS",          TMC_DRV_CODES);
909 927
     #if HAS_TMCX1X0 || HAS_TMC220x
910 928
       DRV_REPORT("sg_result",        TMC_SG_RESULT);

+ 37
- 34
Marlin/src/module/motion.cpp 파일 보기

@@ -1443,65 +1443,69 @@ void set_axis_not_trusted(const AxisEnum axis) {
1443 1443
   TERN_(I2C_POSITION_ENCODERS, I2CPEM.unhomed(axis));
1444 1444
 }
1445 1445
 
1446
-/**
1447
- * Move the axis back to its home_phase if set and driver is capable (TMC)
1448
- *
1449
- * Improves homing repeatability by homing to stepper coil's nearest absolute
1450
- * phase position. Trinamic drivers use a stepper phase table with 1024 values
1451
- * spanning 4 full steps with 256 positions each (ergo, 1024 positions).
1452
- */
1453
-void backout_to_tmc_homing_phase(const AxisEnum axis) {
1454
-  #ifdef TMC_HOME_PHASE
1455
-    const abc_long_t home_phase = TMC_HOME_PHASE;
1446
+#ifdef TMC_HOME_PHASE
1447
+  /**
1448
+   * Move the axis back to its home_phase if set and driver is capable (TMC)
1449
+   *
1450
+   * Improves homing repeatability by homing to stepper coil's nearest absolute
1451
+   * phase position. Trinamic drivers use a stepper phase table with 1024 values
1452
+   * spanning 4 full steps with 256 positions each (ergo, 1024 positions).
1453
+   */
1454
+  void backout_to_tmc_homing_phase(const AxisEnum axis) {
1455
+    const xyz_long_t home_phase = TMC_HOME_PHASE;
1456 1456
 
1457 1457
     // check if home phase is disabled for this axis.
1458 1458
     if (home_phase[axis] < 0) return;
1459 1459
 
1460
-    int16_t axisMicrostepSize;
1461
-    int16_t phaseCurrent;
1462
-    bool invertDir;
1460
+    int16_t phasePerUStep,      // TMC µsteps(phase) per Marlin µsteps
1461
+            phaseCurrent,       // The TMC µsteps(phase) count of the current position
1462
+            effectorBackoutDir, // Direction in which the effector mm coordinates move away from endstop.
1463
+            stepperBackoutDir;  // Direction in which the TMC µstep count(phase) move away from endstop.
1463 1464
 
1464 1465
     switch (axis) {
1465 1466
       #ifdef X_MICROSTEPS
1466 1467
         case X_AXIS:
1467
-          axisMicrostepSize = 256 / (X_MICROSTEPS);
1468
+          phasePerUStep = 256 / (X_MICROSTEPS);
1468 1469
           phaseCurrent = stepperX.get_microstep_counter();
1469
-          invertDir = INVERT_X_DIR;
1470
+          effectorBackoutDir = -X_HOME_DIR;
1471
+          stepperBackoutDir = INVERT_X_DIR ? effectorBackoutDir : -effectorBackoutDir;
1470 1472
           break;
1471 1473
       #endif
1472 1474
       #ifdef Y_MICROSTEPS
1473 1475
         case Y_AXIS:
1474
-          axisMicrostepSize = 256 / (Y_MICROSTEPS);
1476
+          phasePerUStep = 256 / (Y_MICROSTEPS);
1475 1477
           phaseCurrent = stepperY.get_microstep_counter();
1476
-          invertDir = INVERT_Y_DIR;
1478
+          effectorBackoutDir = -Y_HOME_DIR;
1479
+          stepperBackoutDir = INVERT_Y_DIR ? effectorBackoutDir : -effectorBackoutDir;
1477 1480
           break;
1478 1481
       #endif
1479 1482
       #ifdef Z_MICROSTEPS
1480 1483
         case Z_AXIS:
1481
-          axisMicrostepSize = 256 / (Z_MICROSTEPS);
1484
+          phasePerUStep = 256 / (Z_MICROSTEPS);
1482 1485
           phaseCurrent = stepperZ.get_microstep_counter();
1483
-          invertDir = INVERT_Z_DIR;
1486
+          effectorBackoutDir = -Z_HOME_DIR;
1487
+          stepperBackoutDir = INVERT_Z_DIR ? effectorBackoutDir : -effectorBackoutDir;
1484 1488
           break;
1485 1489
       #endif
1486 1490
       default: return;
1487 1491
     }
1488 1492
 
1489
-    // Depending on invert dir measure the distance to nearest home phase.
1490
-    int16_t phaseDelta = (invertDir ? -1 : 1) * (home_phase[axis] - phaseCurrent);
1493
+    // Phase distance to nearest home phase position when moving in the backout direction from endstop(may be negative).
1494
+    int16_t phaseDelta = (home_phase[axis] - phaseCurrent) * stepperBackoutDir;
1491 1495
 
1492 1496
     // Check if home distance within endstop assumed repeatability noise of .05mm and warn.
1493
-    if (ABS(phaseDelta) * planner.steps_to_mm[axis] / axisMicrostepSize < 0.05f)
1494
-      DEBUG_ECHOLNPAIR("Selected home phase ", home_phase[axis],
1497
+    if (ABS(phaseDelta) * planner.steps_to_mm[axis] / phasePerUStep < 0.05f)
1498
+      SERIAL_ECHOLNPAIR("Selected home phase ", home_phase[axis],
1495 1499
                        " too close to endstop trigger phase ", phaseCurrent,
1496 1500
                        ". Pick a different phase for ", axis_codes[axis]);
1497 1501
 
1498 1502
     // Skip to next if target position is behind current. So it only moves away from endstop.
1499 1503
     if (phaseDelta < 0) phaseDelta += 1024;
1500 1504
 
1501
-    // Get the integer µsteps to target. Unreachable phase? Consistently stop at the µstep before / after based on invertDir.
1502
-    const float mmDelta = -(int16_t(phaseDelta / axisMicrostepSize) * planner.steps_to_mm[axis] * (Z_HOME_DIR));
1505
+    // Convert TMC µsteps(phase) to whole Marlin µsteps to effector backout direction to mm 
1506
+    const float mmDelta = int16_t(phaseDelta / phasePerUStep) * effectorBackoutDir * planner.steps_to_mm[axis];
1503 1507
 
1504
-    // optional debug messages.
1508
+    // Optional debug messages
1505 1509
     if (DEBUGGING(LEVELING)) {
1506 1510
       DEBUG_ECHOLNPAIR(
1507 1511
         "Endstop ", axis_codes[axis], " hit at Phase:", phaseCurrent,
@@ -1510,14 +1514,11 @@ void backout_to_tmc_homing_phase(const AxisEnum axis) {
1510 1514
     }
1511 1515
 
1512 1516
     if (mmDelta != 0) {
1513
-      // retrace by the amount computed in mmDelta.
1517
+      // Retrace by the amount computed in mmDelta.
1514 1518
       do_homing_move(axis, mmDelta, get_homing_bump_feedrate(axis));
1515 1519
     }
1516
-  #else
1517
-    UNUSED(axis);
1518
-  #endif
1519
-}
1520
-
1520
+  }
1521
+#endif
1521 1522
 
1522 1523
 /**
1523 1524
  * Home an individual "raw axis" to its endstop.
@@ -1748,8 +1749,10 @@ void homeaxis(const AxisEnum axis) {
1748 1749
     }
1749 1750
   #endif
1750 1751
 
1751
-  // move back to homing phase if configured and capable
1752
-  backout_to_tmc_homing_phase(axis);
1752
+  #ifdef TMC_HOME_PHASE
1753
+    // move back to homing phase if configured and capable
1754
+    backout_to_tmc_homing_phase(axis);
1755
+  #endif
1753 1756
 
1754 1757
   #if IS_SCARA
1755 1758
 

Loading…
취소
저장