From ec47633794a4494618d0d79c6e218e84038585af Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Fri, 13 May 2011 00:36:32 +0200 Subject: [PATCH] ACCELERATION_RAMPING: precalculate number of acceleration steps. These numbers aren't used, yet, but they can be compared with the numbers calculated by the traditional method. --- dda.c | 9 +++++++++ dda.h | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/dda.c b/dda.c index e776ad5..4e7faa5 100644 --- a/dda.c +++ b/dda.c @@ -346,6 +346,13 @@ void dda_create(DDA *dda, TARGET *target) { dda->c_min = (move_duration / target->F) << 8; if (dda->c_min < c_limit) dda->c_min = c_limit; + // overflows at target->F > 65535; factor 16. found by try-and-error + dda->rampup_steps = target->F * target->F / (uint32_t)(STEPS_PER_MM_X * ACCELERATION / 16.); + if (dda->rampup_steps > dda->total_steps / 2) + dda->rampup_steps = dda->total_steps / 2; + dda->rampdown_steps = dda->total_steps - dda->rampup_steps; + if (dda->rampup_steps == 0) + dda->rampup_steps = 1; dda->n = 1; dda->ramp_state = RAMP_UP; #else @@ -534,7 +541,9 @@ void dda_step(DDA *dda) { // maximum speed reached dda->c = dda->c_min; dda->ramp_state = RAMP_MAX; +//sersendf_P(PSTR("real:%lu up:%lu "), dda->step_no, dda->rampup_steps); dda->ramp_steps = dda->total_steps - dda->step_no; +//sersendf_P(PSTR("real:%lu down:%lu\n"), dda->ramp_steps, dda->rampdown_steps); } break; } diff --git a/dda.h b/dda.h index 6699d27..9364e82 100644 --- a/dda.h +++ b/dda.h @@ -106,6 +106,10 @@ typedef struct { #ifdef ACCELERATION_RAMPING /// start of down-ramp, intitalized with total_steps / 2 uint32_t ramp_steps; + /// number of steps accelerating + uint32_t rampup_steps; + /// number of last step before decelerating + uint32_t rampdown_steps; /// counts actual steps done uint32_t step_no; /// 24.8 fixed point timer value, maximum speed