@@ -75,7 +75,7 @@ xyze_pos_t FTMotion::startPos, // (mm) Start position of bl
7575xyze_float_t FTMotion::ratio; // (ratio) Axis move ratio of block
7676float FTMotion::tau = 0 .0f ; // (s) Time since start of block
7777bool FTMotion::fastForwardUntilMotion = false ; // Fast forward time if there is no motion
78- #if ANY(APPLY_TIMING_HACK_ON_X, APPLY_TIMING_HACK_ON_Y, APPLY_TIMING_HACK_ON_Z, APPLY_TIMING_HACK_ON_E)
78+ #if HAS_FTM_DIR_CHANGE_HOLD
7979 xyze_uint_t FTMotion::hold_frames; // Briefly hold motion after direction changes to fix TMC2208 bug
8080 AxisBits FTMotion::last_traj_dir; // Direction of the last trajectory point after shaping, smoothing, ...
8181#endif
@@ -250,7 +250,7 @@ void FTMotion::reset() {
250250
251251 moving_axis_flags.reset ();
252252 last_target_traj.reset ();
253- #if ANY(APPLY_TIMING_HACK_ON_X, APPLY_TIMING_HACK_ON_Y, APPLY_TIMING_HACK_ON_Z, APPLY_TIMING_HACK_ON_E)
253+ #if HAS_FTM_DIR_CHANGE_HOLD
254254 last_traj_dir.reset ();
255255 hold_frames.reset ();
256256 #endif
@@ -620,32 +620,38 @@ void FTMotion::fill_stepper_plan_buffer() {
620620 // It eliminates idle time when changing smoothing time or shapers and speeds up homing and bed leveling.
621621 }
622622 else {
623- #if ANY(APPLY_TIMING_HACK_ON_X, APPLY_TIMING_HACK_ON_Y, APPLY_TIMING_HACK_ON_Z, APPLY_TIMING_HACK_ON_E)
623+
624+ #if HAS_FTM_DIR_CHANGE_HOLD
625+
624626 // When a flip is detected (and the axis is in stealthChop or is standalone),
625627 // hold that axis' trajectory coordinate constant for at least 750µs.
626628
627629 #define DIR_FLIP_HOLD_S 0.000' 750f
628- static constexpr uint32_t DIR_FLIP_HOLD_FRAMES = DIR_FLIP_HOLD_S / FTM_TS + 1 ;
629-
630- #define START_HOLD_IF_DIR_FLIP (A ) \
631- if (ENABLED (APPLY_TIMING_HACK_ON_##A)) { \
632- const bool direction = traj_coords.A > last_target_traj.A ; \
633- const bool moved = traj_coords.A != last_target_traj.A ; \
634- const bool flipped = moved && (direction != last_traj_dir.A ); \
635- const bool hold = !moved || (flipped && hold_frames.A > 0 ); \
636- if (hold) { \
637- if (hold_frames.A ) hold_frames.A --; \
638- traj_coords.A = last_target_traj.A ; \
639- } else { \
640- last_traj_dir.A = direction; \
641- hold_frames.A = DIR_FLIP_HOLD_FRAMES; \
642- } \
630+ static constexpr uint32_t dir_flip_hold_frames = DIR_FLIP_HOLD_S / (FTM_TS + 1 );
631+
632+ auto start_hold_if_dir_flip = [](const AxisEnum a) {
633+ const bool dir = traj_coords[a] > last_target_traj[a],
634+ moved = traj_coords[a] != last_target_traj[a],
635+ flipped = moved && (dir != last_traj_dir[a]),
636+ hold = !moved || (flipped && hold_frames[a] > 0 );
637+ if (hold) {
638+ if (hold_frames[a]) hold_frames[a]--;
639+ traj_coords[a] = last_target_traj[a];
643640 }
641+ else {
642+ last_traj_dir[a] = dir;
643+ hold_frames[a] = dir_flip_hold_frames;
644+ }
645+ };
646+
647+ #define START_HOLD_IF_DIR_FLIP (A ) TERN_(FTM_DIR_CHANGE_HOLD_##A, start_hold_if_dir_flip(_AXIS(A)));
648+
644649 LOGICAL_AXIS_MAP (START_HOLD_IF_DIR_FLIP);
645650
646- # undef START_HOLD_IF_DIR_FLIP
647- # endif
651+ # endif // HAS_FTM_DIR_CHANGE_HOLD
652+
648653 fastForwardUntilMotion = false ;
654+
649655 // Calculate and store stepper plan in buffer
650656 stepping_enqueue (traj_coords);
651657 }
0 commit comments