diff --git a/dda.c b/dda.c index d76d9af..b962445 100644 --- a/dda.c +++ b/dda.c @@ -173,6 +173,7 @@ void dda_init(void) { #ifdef ACCELERATION_RAMPING move_state.n = 1; + move_state.c = ((uint32_t)((double)F_CPU / sqrt((double)(STEPS_PER_MM_X * ACCELERATION)))) << 8; #endif } @@ -356,8 +357,6 @@ void dda_create(DDA *dda, TARGET *target) { #endif // c is initial step time in IOclk ticks (currently, IOclk ticks = F_CPU) // yes, this assumes always the x axis as the critical one regarding acceleration. If we want to implement per-axis acceleration, things get tricky ... - // TODO: as this number ends exactly where it starts, move it out into a state variable - dda->c = ((uint32_t)((double)F_CPU / sqrt((double)(STEPS_PER_MM_X * ACCELERATION)))) << 8; dda->c_min = (move_duration / target->F) << 8; if (dda->c_min < c_limit) dda->c_min = c_limit; @@ -431,7 +430,14 @@ void dda_start(DDA *dda) { dda->live = 1; // set timeout for first step + #ifdef ACCELERATION_RAMPING + if (dda->c_min > move_state.c) // can be true when look-ahead removed all deceleration steps + setTimer(dda->c_min >> 8); + else + setTimer(move_state.c >> 8); + #else setTimer(dda->c >> 8); + #endif } } @@ -553,7 +559,7 @@ void dda_step(DDA *dda) { if (recalc_speed) { move_state.n += 4; // be careful of signedness! - dda->c = (int32_t)dda->c - ((int32_t)(dda->c * 2) / move_state.n); + move_state.c = (int32_t)move_state.c - ((int32_t)(move_state.c * 2) / move_state.n); } dda->step_no++; @@ -593,10 +599,10 @@ void dda_step(DDA *dda) { // we don't hit maximum speed exactly with acceleration calculation, so limit it here // the nice thing about _not_ setting dda->c to dda->c_min is, the move stops at the exact same c as it started, so we have to calculate c only once for the time being // TODO: set timer only if dda->c has changed - if (dda->c_min > dda->c) + if (dda->c_min > move_state.c) setTimer(dda->c_min >> 8); else - setTimer(dda->c >> 8); + setTimer(move_state.c >> 8); #else setTimer(dda->c >> 8); #endif diff --git a/dda.h b/dda.h index 3dbb748..5012e61 100644 --- a/dda.h +++ b/dda.h @@ -54,10 +54,10 @@ typedef struct { // uint32_t e_steps; ///< number of steps on E axis #ifdef ACCELERATION_RAMPING -// /// time until next step -// uint32_t c; // /// counts actual steps done // uint32_t step_no; + /// time until next step + uint32_t c; /// tracking variable int32_t n; #endif @@ -117,7 +117,9 @@ typedef struct { uint32_t total_steps; // linear acceleration variables: c and end_c are 24.8 fixed point timer values, n is the tracking variable + #ifndef ACCELERATION_RAMPING uint32_t c; ///< time until next step + #endif #ifdef ACCELERATION_REPRAP uint32_t end_c; ///< time between 2nd last step and last step int32_t n; ///< precalculated step time offset variable. At every step we calculate \f$c = c - (2 c / n)\f$; \f$n+=4\f$. See http://www.embedded.com/columns/technicalinsights/56800129?printable=true for full description diff --git a/dda_queue.c b/dda_queue.c index a7cbbca..cf76980 100644 --- a/dda_queue.c +++ b/dda_queue.c @@ -64,7 +64,7 @@ void queue_step() { DDA* current_movebuffer = &movebuffer[mb_tail]; if (current_movebuffer->live) { if (current_movebuffer->waitfor_temp) { - setTimer(current_movebuffer->c >> 8); + setTimer(HEATER_WAIT_TIMEOUT); if (temp_achieved()) { current_movebuffer->live = current_movebuffer->waitfor_temp = 0; serial_writestr_P(PSTR("Temp achieved\n")); @@ -106,13 +106,6 @@ void enqueue(TARGET *t) { // it's a wait for temp new_movebuffer->waitfor_temp = 1; new_movebuffer->nullmove = 0; - #if (F_CPU & 0xFF000000) == 0 - // set "step" timeout to 1 second - new_movebuffer->c = F_CPU << 8; - #else - // set "step" timeout to maximum - new_movebuffer->c = 0xFFFFFF00; - #endif } // make certain all writes to global memory @@ -163,13 +156,13 @@ void next_move() { // tail must be set before setTimer call as setTimer // reenables the timer interrupt, potentially exposing // mb_tail to the timer interrupt routine. - mb_tail = t; + mb_tail = t; if (current_movebuffer->waitfor_temp) { #ifndef REPRAP_HOST_COMPATIBILITY serial_writestr_P(PSTR("Waiting for target temp\n")); #endif current_movebuffer->live = 1; - setTimer(current_movebuffer->c >> 8); + setTimer(HEATER_WAIT_TIMEOUT); } else { dda_start(current_movebuffer); @@ -177,7 +170,7 @@ void next_move() { } if (queue_empty()) setTimer(0); - + } /// DEBUG - print queue. diff --git a/dda_queue.h b/dda_queue.h index 26f0aa2..275ca5f 100644 --- a/dda_queue.h +++ b/dda_queue.h @@ -3,6 +3,14 @@ #include "dda.h" +#if (F_CPU & 0xFF000000) == 0 + // set timeout to 1 second + #define HEATER_WAIT_TIMEOUT (F_CPU << 8) +#else + // set timeout to maximum + #define HEATER_WAIT_TIMEOUT 0xFFFFFF00 +#endif + /* variables */