From ed77abba312f570c02c3611de75bff79c7004cc0 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Sun, 15 May 2011 20:59:28 +0200 Subject: [PATCH] Move dda->step_no into move_state as well. --- dda.c | 16 ++++++++++------ dda.h | 6 ++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/dda.c b/dda.c index 3844eff..dd8e2b8 100644 --- a/dda.c +++ b/dda.c @@ -350,7 +350,6 @@ void dda_create(DDA *dda, TARGET *target) { else dda->accel = 0; #elif defined ACCELERATION_RAMPING - dda->step_no = 0; // remove this when people have swallowed the new config item #ifdef ACCELERATION_STEEPNESS #error ACCELERATION_STEEPNESS is gone, review your config.h and use ACCELERATION @@ -417,6 +416,11 @@ void dda_start(DDA *dda) { heater_set(DC_EXTRUDER, DC_EXTRUDER_PWM); #endif + // initialise state variable + #ifdef ACCELERATION_RAMPING + move_state.step_no = 0; + #endif + // ensure this dda starts dda->live = 1; @@ -531,17 +535,17 @@ void dda_step(DDA *dda) { uint8_t recalc_speed; // debug ramping algorithm - //if (dda->step_no == 0) { + //if (move_state.step_no == 0) { // sersendf_P(PSTR("\r\nc %lu c_min %lu n %d"), dda->c, dda->c_min, move_state.n); //} recalc_speed = 0; - if (dda->step_no < dda->rampup_steps) { + if (move_state.step_no < dda->rampup_steps) { if (move_state.n < 0) // wrong ramp direction move_state.n = -((int32_t)2) - move_state.n; recalc_speed = 1; } - else if (dda->step_no > dda->rampdown_steps) { + else if (move_state.step_no > dda->rampdown_steps) { if (move_state.n > 0) // wrong ramp direction move_state.n = -((int32_t)2) - move_state.n; recalc_speed = 1; @@ -551,11 +555,11 @@ void dda_step(DDA *dda) { // be careful of signedness! move_state.c = (int32_t)move_state.c - ((int32_t)(move_state.c * 2) / (int32_t)move_state.n); } - dda->step_no++; + move_state.step_no++; // debug ramping algorithm // for very low speeds like 10 mm/min, only - //if (dda->step_no % 10 /* 10, 100, ...*/ == 0) + //if (move_state.step_no % 10 /* 10, 100, ...*/ == 0) // sersendf_P(PSTR("\r\nc %lu c_min %lu n %d"), dda->c, dda->c_min, move_state.n); #endif diff --git a/dda.h b/dda.h index dd9fe97..a787b7c 100644 --- a/dda.h +++ b/dda.h @@ -54,8 +54,8 @@ typedef struct { // uint32_t e_steps; ///< number of steps on E axis #ifdef ACCELERATION_RAMPING -// /// counts actual steps done -// uint32_t step_no; + /// counts actual steps done + uint32_t step_no; /// time until next step uint32_t c; /// tracking variable @@ -129,8 +129,6 @@ typedef struct { 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 uint32_t c_min; #endif