Skip to content
This repository has been archived by the owner on Aug 27, 2023. It is now read-only.

Commit

Permalink
DDA: Move axis calculations into loops, part 6a.
Browse files Browse the repository at this point in the history
Clean up code to reduce duplication by consolidating code into
loops for per-axis actions.

Part 6a is putting stuff inside the step interrupt into a loop,
too. do_step() is put into the "tidiest" place. Binary size goes
down a remarkable 374 bytes, but stepping performance suffers by
almost 30%.

Traumflug's performance measurements:

    SIZES             ATmega...  '168    '328(P)    '644(P)    '1280
    FLASH : 19908 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: 354537 clock cycles.
LED on time minimum: 390 clock cycles.
LED on time maximum: 806 clock cycles.
LED on time average: 399.253 clock cycles.

smooth-curves.gcode
Statistics (assuming a 20 MHz clock):
LED on occurences: 9124.
Sum of all LED on time: 4268896 clock cycles.
LED on time minimum: 395 clock cycles.
LED on time maximum: 807 clock cycles.
LED on time average: 467.875 clock cycles.

triangle-odd.gcode
Statistics (assuming a 20 MHz clock):
LED on occurences: 1636.
Sum of all LED on time: 706846 clock cycles.
LED on time minimum: 390 clock cycles.
LED on time maximum: 807 clock cycles.
LED on time average: 432.057 clock cycles.
  • Loading branch information
phord authored and Traumflug committed Aug 31, 2014
1 parent ad82907 commit b83449d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 71 deletions.
90 changes: 19 additions & 71 deletions dda.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,78 +482,26 @@ void dda_start(DDA *dda) {
Finally we de-assert any asserted step pins.
*/
void dda_step(DDA *dda) {
enum axis_e i;

#if ! defined ACCELERATION_TEMPORAL
if (move_state.steps[X]) {
move_state.counter[X] -= dda->delta[X];
if (move_state.counter[X] < 0) {
x_step();
move_state.steps[X]--;
move_state.counter[X] += dda->total_steps;
}
}
#else // ACCELERATION_TEMPORAL
if (dda->axis_to_step == X) {
x_step();
move_state.steps[X]--;
move_state.time[X] += dda->step_interval[X];
move_state.all_time = move_state.time[X];
}
#endif

#if ! defined ACCELERATION_TEMPORAL
if (move_state.steps[Y]) {
move_state.counter[Y] -= dda->delta[Y];
if (move_state.counter[Y] < 0) {
y_step();
move_state.steps[Y]--;
move_state.counter[Y] += dda->total_steps;
}
}
#else // ACCELERATION_TEMPORAL
if (dda->axis_to_step == Y) {
y_step();
move_state.steps[Y]--;
move_state.time[Y] += dda->step_interval[Y];
move_state.all_time = move_state.time[Y];
}
#endif

#if ! defined ACCELERATION_TEMPORAL
if (move_state.steps[Z]) {
move_state.counter[Z] -= dda->delta[Z];
if (move_state.counter[Z] < 0) {
z_step();
move_state.steps[Z]--;
move_state.counter[Z] += dda->total_steps;
}
}
#else // ACCELERATION_TEMPORAL
if (dda->axis_to_step == Z) {
z_step();
move_state.steps[Z]--;
move_state.time[Z] += dda->step_interval[Z];
move_state.all_time = move_state.time[Z];
}
#endif

#if ! defined ACCELERATION_TEMPORAL
if (move_state.steps[E]) {
move_state.counter[E] -= dda->delta[E];
if (move_state.counter[E] < 0) {
e_step();
move_state.steps[E]--;
move_state.counter[E] += dda->total_steps;
}
}
#else // ACCELERATION_TEMPORAL
if (dda->axis_to_step == E) {
e_step();
move_state.steps[E]--;
move_state.time[E] += dda->step_interval[E];
move_state.all_time = move_state.time[E];
}
#endif
#if ! defined ACCELERATION_TEMPORAL
for (i = X; i < AXIS_COUNT; i++) {
if (move_state.steps[i]) {
move_state.counter[i] -= dda->delta[i];
if (move_state.counter[i] < 0) {
do_step(i);
move_state.steps[i]--;
move_state.counter[i] += dda->total_steps;
}
}
}
#else // ACCELERATION_TEMPORAL
i = dda->axis_to_step;
do_step(i);
move_state.steps[i]--;
move_state.time[i] += dda->step_interval[i];
move_state.all_time = move_state.time[i];
#endif

#if STEP_INTERRUPT_INTERRUPTIBLE && ! defined ACCELERATION_RAMPING
// Since we have sent steps to all the motors that will be stepping
Expand Down
13 changes: 13 additions & 0 deletions pinio.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,16 @@ void power_off() {

ps_is_on = 0;
}

// step the 'n' axis
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();
}

3 changes: 3 additions & 0 deletions pinio.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define _PINIO_H

#include "config_wrapper.h"
#include "dda.h"

#ifdef SIMULATOR
#include "simulator.h"
Expand Down Expand Up @@ -33,6 +34,8 @@ inline void power_init(void) {
void power_on(void);
void power_off(void);

void do_step(enum axis_e n);

/*
X Stepper
*/
Expand Down

0 comments on commit b83449d

Please sign in to comment.