From fa1a7d4ef70919c4e2cf9ff5b0bcbd1dfb9caff8 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Wed, 30 Oct 2013 20:09:00 +0100 Subject: [PATCH] dda.c: deal with endstop hits while still accelerating. Also, move_state.step_no must be read atomically. --- dda.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dda.c b/dda.c index 6078f0e..fedaff8 100644 --- a/dda.c +++ b/dda.c @@ -765,11 +765,15 @@ void dda_clock() { // but start deceleration here. ATOMIC_START move_state.endstop_stop = 1; - // A "-=" would cause an overflow. - dda->total_steps = dda->total_steps - dda->rampdown_steps + move_state.step_no; + if (move_state.step_no < dda->rampup_steps) // still accelerating + dda->total_steps = move_state.step_no * 2; + else + // A "-=" would overflow earlier. + dda->total_steps = dda->total_steps - dda->rampdown_steps + + move_state.step_no; + dda->rampdown_steps = move_state.step_no; ATOMIC_END // Not atomic, because not used in dda_step(). - dda->rampdown_steps = move_state.step_no; dda->rampup_steps = 0; // in case we're still accelerating #else dda->live = 0;