DDA: Move axis calculations into loops, part 6c.

Clean up code to reduce duplication by consolidating code into
loops for per-axis actions.

Part 6c removes do_step(), but still tries to keep a loop. This
about the maximum of performance I (Traumflug) can think of.
Binary size is as good as with the former attempt, but performance
is actually pretty bad, 45% worse than without looping:

    SIZES             ATmega...  '168    '328(P)    '644(P)    '1280
    FLASH : 19876 bytes          139%       65%        32%       16%
    RAM   :  2302 bytes          225%      113%        57%       29%
    EEPROM:    32 bytes            4%        2%         2%        1%

short-moves.gcode
Statistics (assuming a 20 MHz clock):
LED on occurences: 888.
Sum of all LED on time: 406041 clock cycles.
LED on time minimum: 448 clock cycles.
LED on time maximum: 864 clock cycles.
LED on time average: 457.253 clock cycles.

smooth-curves.gcode
Statistics (assuming a 20 MHz clock):
LED on occurences: 9124.
Sum of all LED on time: 4791132 clock cycles.
LED on time minimum: 453 clock cycles.
LED on time maximum: 867 clock cycles.
LED on time average: 525.113 clock cycles.

triangle-odd.gcode
Statistics (assuming a 20 MHz clock):
LED on occurences: 1636.
Sum of all LED on time: 800586 clock cycles.
LED on time minimum: 448 clock cycles.
LED on time maximum: 867 clock cycles.
LED on time average: 489.356 clock cycles.
This commit is contained in:
Markus Hitter 2014-06-17 23:40:45 +02:00
parent 808f5dcfca
commit 1fc4a26ccd
1 changed files with 12 additions and 14 deletions

26
dda.c
View File

@ -471,18 +471,6 @@ void dda_start(DDA *dda) {
current_position.F = dda->endpoint.F; current_position.F = dda->endpoint.F;
} }
// step the 'n' axis
static void do_step(enum axis_e n) {
if (n == X)
x_step();
else if (n == Y)
y_step();
else if (n == Z)
z_step();
else if (n == E)
e_step();
}
/*! STEP /*! STEP
\param *dda the current move \param *dda the current move
@ -495,13 +483,14 @@ static void do_step(enum axis_e n) {
*/ */
void dda_step(DDA *dda) { void dda_step(DDA *dda) {
enum axis_e i; enum axis_e i;
char to_step_flags = 0;
#if ! defined ACCELERATION_TEMPORAL #if ! defined ACCELERATION_TEMPORAL
for (i = X; i < AXIS_COUNT; i++) { for (i = X; i < AXIS_COUNT; i++) {
if (move_state.steps[i]) { if (move_state.steps[i]) {
move_state.counter[i] -= dda->delta[i]; move_state.counter[i] -= dda->delta[i];
if (move_state.counter[i] < 0) { if (move_state.counter[i] < 0) {
do_step(i); to_step_flags |= (0x01 << i);
move_state.steps[i]--; move_state.steps[i]--;
move_state.counter[i] += dda->total_steps; move_state.counter[i] += dda->total_steps;
} }
@ -509,12 +498,21 @@ void dda_step(DDA *dda) {
} }
#else // ACCELERATION_TEMPORAL #else // ACCELERATION_TEMPORAL
i = dda->axis_to_step; i = dda->axis_to_step;
do_step(i); to_step_flags |= (0x01 << i);
move_state.steps[i]--; move_state.steps[i]--;
move_state.time[i] += dda->step_interval[i]; move_state.time[i] += dda->step_interval[i];
move_state.all_time = move_state.time[i]; move_state.all_time = move_state.time[i];
#endif #endif
if (to_step_flags & (0x01 << X))
x_step();
if (to_step_flags & (0x01 << Y))
y_step();
if (to_step_flags & (0x01 << Z))
z_step();
if (to_step_flags & (0x01 << E))
e_step();
#if STEP_INTERRUPT_INTERRUPTIBLE && ! defined ACCELERATION_RAMPING #if STEP_INTERRUPT_INTERRUPTIBLE && ! defined ACCELERATION_RAMPING
// Since we have sent steps to all the motors that will be stepping // Since we have sent steps to all the motors that will be stepping
// and the rest of this function isn't so time critical, this interrupt // and the rest of this function isn't so time critical, this interrupt