Move dda->c out of DDA into move_state as well.

This also required to get rid of the usage of this variable
when waiting for temperature in dda_queue.*. Hope I got this
later part right.
This commit is contained in:
Markus Hitter 2011-05-15 20:31:45 +02:00
parent 51be23177a
commit 2421b788b9
4 changed files with 27 additions and 18 deletions

16
dda.c
View File

@ -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

6
dda.h
View File

@ -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

View File

@ -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
@ -169,7 +162,7 @@ void next_move() {
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);

View File

@ -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
*/