DDA: get rid of fast_spm.

We need the fastest axis instead of its steps.

Eleminates also an overflow when ACCELERATION > 596.

We save 118 bytes program and 2 bytes data.

Reviewer Traumflug's note: I see 100 bytes program and 32 bytes
RAM saving on ATmegas here. 16 and 32 on the LPC 1114. Either way:
great stuff!
This commit is contained in:
wurstnase 2016-07-05 08:16:21 +02:00 committed by Markus Hitter
parent 39cababb07
commit 2b1f3371c7
4 changed files with 18 additions and 20 deletions

12
dda.c
View File

@ -49,15 +49,6 @@ TARGET BSS current_position;
/// \brief numbers for tracking the current state of movement /// \brief numbers for tracking the current state of movement
MOVE_STATE BSS move_state; MOVE_STATE BSS move_state;
/// \var steps_per_m_P
/// \brief motor steps required to advance one meter on each axis
static const axes_uint32_t PROGMEM steps_per_m_P = {
STEPS_PER_M_X,
STEPS_PER_M_Y,
STEPS_PER_M_Z,
STEPS_PER_M_E
};
/// \var maximum_feedrate_P /// \var maximum_feedrate_P
/// \brief maximum allowed feedrate on each axis /// \brief maximum allowed feedrate on each axis
static const axes_uint32_t PROGMEM maximum_feedrate_P = { static const axes_uint32_t PROGMEM maximum_feedrate_P = {
@ -279,7 +270,6 @@ void dda_create(DDA *dda, const TARGET *target) {
dda->fast_axis = i; dda->fast_axis = i;
dda->total_steps = dda->delta[i]; dda->total_steps = dda->delta[i];
dda->fast_um = delta_um[i]; dda->fast_um = delta_um[i];
dda->fast_spm = pgm_read_dword(&steps_per_m_P[i]);
} }
} }
@ -428,7 +418,7 @@ void dda_create(DDA *dda, const TARGET *target) {
// Acceleration ramps are based on the fast axis, not the combined speed. // Acceleration ramps are based on the fast axis, not the combined speed.
dda->rampup_steps = dda->rampup_steps =
acc_ramp_len(muldiv(dda->fast_um, dda->endpoint.F, distance), acc_ramp_len(muldiv(dda->fast_um, dda->endpoint.F, distance),
dda->fast_spm); dda->fast_axis);
if (dda->rampup_steps > dda->total_steps / 2) if (dda->rampup_steps > dda->total_steps / 2)
dda->rampup_steps = dda->total_steps / 2; dda->rampup_steps = dda->total_steps / 2;

1
dda.h
View File

@ -115,7 +115,6 @@ typedef struct {
// uint8_t fast_axis; (see below) // uint8_t fast_axis; (see below)
uint32_t total_steps; ///< steps of the "fast" axis uint32_t total_steps; ///< steps of the "fast" axis
uint32_t fast_um; ///< movement length of this fast axis uint32_t fast_um; ///< movement length of this fast axis
uint32_t fast_spm; ///< steps per meter of the fast axis
uint32_t c; ///< time until next step, 24.8 fixed point uint32_t c; ///< time until next step, 24.8 fixed point

View File

@ -70,7 +70,7 @@ const int32_t muldivQR(int32_t multiplicand, uint32_t qn, uint32_t rn,
qn <<= 1; qn <<= 1;
rn <<= 1; rn <<= 1;
if (rn >= divisor) { if (rn >= divisor) {
qn++; qn++;
rn -= divisor; rn -= divisor;
} }
} }
@ -177,7 +177,7 @@ uint16_t int_sqrt(uint32_t a) {
if (y2 > c) if (y2 > c)
z ^= j; z ^= j;
} }
x = z << 4; x = z << 4;
for(i = 0x8; i; i >>= 1) { for(i = 0x8; i; i >>= 1) {
uint16_t y2; uint16_t y2;
@ -187,7 +187,7 @@ uint16_t int_sqrt(uint32_t a) {
if (y2 > b) if (y2 > b)
x ^= i; x ^= i;
} }
x <<= 8; x <<= 8;
for(i = 0x80; i; i >>= 1) { for(i = 0x80; i; i >>= 1) {
uint32_t y2; uint32_t y2;
@ -256,9 +256,19 @@ const uint8_t msbloc (uint32_t v) {
return 0; return 0;
} }
/*!
Pre-calculated constant values for acceleration ramp calculations.
*/
static const axes_uint32_t PROGMEM acc_ramp_div_P = {
(uint32_t)((7200000.0f * ACCELERATION) / STEPS_PER_M_X),
(uint32_t)((7200000.0f * ACCELERATION) / STEPS_PER_M_Y),
(uint32_t)((7200000.0f * ACCELERATION) / STEPS_PER_M_Z),
(uint32_t)((7200000.0f * ACCELERATION) / STEPS_PER_M_E)
};
/*! Acceleration ramp length in steps. /*! Acceleration ramp length in steps.
* \param feedrate Target feedrate of the accelerateion. * \param feedrate Target feedrate of the accelerateion.
* \param steps_per_m Steps/m of the axis. * \param fast_axis Number of the fastest axis.
* \return Accelerating steps neccessary to achieve target feedrate. * \return Accelerating steps neccessary to achieve target feedrate.
* *
* s = 1/2 * a * t^2, v = a * t ==> s = v^2 / (2 * a) * s = 1/2 * a * t^2, v = a * t ==> s = v^2 / (2 * a)
@ -268,8 +278,7 @@ const uint8_t msbloc (uint32_t v) {
* 2000 to 4096000 steps/m (and higher). The numbers are a few percent * 2000 to 4096000 steps/m (and higher). The numbers are a few percent
* too high at very low acceleration. Test code see commit message. * too high at very low acceleration. Test code see commit message.
*/ */
uint32_t acc_ramp_len(uint32_t feedrate, uint32_t steps_per_m) { uint32_t acc_ramp_len(uint32_t feedrate, uint8_t fast_axis) {
return (feedrate * feedrate) / return (feedrate * feedrate) / pgm_read_dword(&acc_ramp_div_P[fast_axis]);
(((uint32_t)7200000UL * ACCELERATION) / steps_per_m);
} }

View File

@ -51,7 +51,7 @@ uint16_t int_inv_sqrt(uint16_t a);
const uint8_t msbloc (uint32_t v); const uint8_t msbloc (uint32_t v);
// Calculates acceleration ramp length in steps. // Calculates acceleration ramp length in steps.
uint32_t acc_ramp_len(uint32_t feedrate, uint32_t steps_per_m); uint32_t acc_ramp_len(uint32_t feedrate, uint8_t fast_axis);
// For X axis only, should become obsolete: // For X axis only, should become obsolete:
#define ACCELERATE_RAMP_LEN(speed) (((speed)*(speed)) / (uint32_t)((7200000.0f * ACCELERATION) / (float)STEPS_PER_M_X)) #define ACCELERATE_RAMP_LEN(speed) (((speed)*(speed)) / (uint32_t)((7200000.0f * ACCELERATION) / (float)STEPS_PER_M_X))