From 4fa0937a552b796f8e4731a5bb0c7931fe50f581 Mon Sep 17 00:00:00 2001 From: Sebastianv650 Date: Sun, 14 Jan 2018 16:29:19 +0100 Subject: [PATCH] Fix missing deceleration steps Marlin never reached final_speed after deceleration. --- Marlin/planner.cpp | 2 +- Marlin/stepper.cpp | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index adbf14250..c222da669 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -218,7 +218,7 @@ void Planner::calculate_trapezoid_for_block(block_t* const block, const float &e // Steps required for acceleration, deceleration to/from nominal rate int32_t accelerate_steps = CEIL(estimate_acceleration_distance(initial_rate, block->nominal_rate, accel)), - decelerate_steps = FLOOR(estimate_acceleration_distance(block->nominal_rate, final_rate, -accel)), + decelerate_steps = CEIL(estimate_acceleration_distance(block->nominal_rate, final_rate, -accel)), // Steps between acceleration and deceleration, if any plateau_steps = block->step_event_count - accelerate_steps - decelerate_steps; diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 664022b64..438fca62e 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -733,8 +733,11 @@ void Stepper::isr() { #endif // LIN_ADVANCE } - else if (step_events_completed > (uint32_t)current_block->decelerate_after) { + else if (step_events_completed >= (uint32_t)current_block->decelerate_after && current_block->step_event_count != (uint32_t)current_block->decelerate_after) { uint16_t step_rate; + // If we are entering the deceleration phase for the first time, we have to see how long we have been decelerating up to now. Equals last acceleration time interval. + if (!deceleration_time) + deceleration_time = calc_timer_interval(acc_step_rate); MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate); if (step_rate < acc_step_rate) { // Still decelerating?