dda.c: don't bit-shift c0.

While this shifting meant to increase accuracy, there's no actual
use of it, other than that this value gets shifted back and forth.
Let's start to get rid of it.

Performance stays exactly the same:

    SIZES             ATmega...  '168    '328(P)    '644(P)    '1280
    FLASH : 20188 bytes          141%       66%        32%       16%
    RAM   :  2318 bytes          227%      114%        57%       29%
    EEPROM:    32 bytes            4%        2%         2%        1%

short-moves.gcode statistics:
LED on occurences: 888.
LED on time minimum: 306 clock cycles.
LED on time maximum: 722 clock cycles.
LED on time average: 315.253 clock cycles.

smooth-curves.gcode statistics:
LED on occurences: 9124.
LED on time minimum: 311 clock cycles.
LED on time maximum: 712 clock cycles.
LED on time average: 361.416 clock cycles.

triangle-odd.gcode statistics:
LED on occurences: 1636.
LED on time minimum: 306 clock cycles.
LED on time maximum: 712 clock cycles.
LED on time average: 334.319 clock cycles.
This commit is contained in:
Markus Hitter 2014-07-10 00:14:40 +02:00
parent ec937adde2
commit 4fa755daef
1 changed files with 9 additions and 9 deletions

18
dda.c
View File

@ -75,10 +75,10 @@ static const axes_uint32_t PROGMEM maximum_feedrate_P = {
/// \brief Initialization constant for the ramping algorithm. Timer cycles for /// \brief Initialization constant for the ramping algorithm. Timer cycles for
/// first step interval. /// first step interval.
static const axes_uint32_t PROGMEM c0_P = { static const axes_uint32_t PROGMEM c0_P = {
((uint32_t)((double)F_CPU / SQRT((double)(STEPS_PER_M_X * ACCELERATION / 2000.)))) << 8, (uint32_t)((double)F_CPU / SQRT((double)(STEPS_PER_M_X * ACCELERATION / 2000.))),
((uint32_t)((double)F_CPU / SQRT((double)(STEPS_PER_M_Y * ACCELERATION / 2000.)))) << 8, (uint32_t)((double)F_CPU / SQRT((double)(STEPS_PER_M_Y * ACCELERATION / 2000.))),
((uint32_t)((double)F_CPU / SQRT((double)(STEPS_PER_M_Z * ACCELERATION / 2000.)))) << 8, (uint32_t)((double)F_CPU / SQRT((double)(STEPS_PER_M_Z * ACCELERATION / 2000.))),
((uint32_t)((double)F_CPU / SQRT((double)(STEPS_PER_M_E * ACCELERATION / 2000.)))) << 8 (uint32_t)((double)F_CPU / SQRT((double)(STEPS_PER_M_E * ACCELERATION / 2000.)))
}; };
/*! Set the direction of the 'n' axis /*! Set the direction of the 'n' axis
@ -395,15 +395,15 @@ void dda_create(DDA *dda, TARGET *target) {
dda_join_moves(prev_dda, dda); dda_join_moves(prev_dda, dda);
dda->n = dda->start_steps; dda->n = dda->start_steps;
if (dda->n == 0) if (dda->n == 0)
dda->c = pgm_read_dword(&c0_P[dda->fast_axis]); dda->c = pgm_read_dword(&c0_P[dda->fast_axis]) << 8;
else else
dda->c = ((pgm_read_dword(&c0_P[dda->fast_axis]) >> 8) * dda->c = (pgm_read_dword(&c0_P[dda->fast_axis]) *
int_inv_sqrt(dda->n)) >> 5; int_inv_sqrt(dda->n)) >> 5;
if (dda->c < dda->c_min) if (dda->c < dda->c_min)
dda->c = dda->c_min; dda->c = dda->c_min;
#else #else
dda->n = 0; dda->n = 0;
dda->c = pgm_read_dword(&c0_P[dda->fast_axis]); dda->c = pgm_read_dword(&c0_P[dda->fast_axis]) << 8;
#endif #endif
#elif defined ACCELERATION_TEMPORAL #elif defined ACCELERATION_TEMPORAL
@ -866,11 +866,11 @@ void dda_clock() {
} }
if (recalc_speed) { if (recalc_speed) {
if (dda->n == 0) if (dda->n == 0)
move_c = pgm_read_dword(&c0_P[dda->fast_axis]); move_c = pgm_read_dword(&c0_P[dda->fast_axis]) << 8;
else else
// Explicit formula: c0 * (sqrt(n + 1) - sqrt(n)), // Explicit formula: c0 * (sqrt(n + 1) - sqrt(n)),
// approximation here: c0 * (1 / (2 * sqrt(n))). // approximation here: c0 * (1 / (2 * sqrt(n))).
move_c = ((pgm_read_dword(&c0_P[dda->fast_axis]) >> 8) * move_c = (pgm_read_dword(&c0_P[dda->fast_axis]) *
int_inv_sqrt(dda->n)) >> 5; int_inv_sqrt(dda->n)) >> 5;
// TODO: most likely this whole check is obsolete. It was left as a // TODO: most likely this whole check is obsolete. It was left as a