diff --git a/dda.c b/dda.c index be43087..65dae85 100644 --- a/dda.c +++ b/dda.c @@ -187,6 +187,7 @@ void dda_create(DDA *dda, const TARGET *target) { dda->id = idcnt++; #endif + dda->active_axes = 0; // Handle bot axes. They're subject to kinematics considerations. code_axes_to_stepper_axes(&startpoint, target, delta_um, steps); for (i = X; i < E; i++) { @@ -194,6 +195,8 @@ void dda_create(DDA *dda, const TARGET *target) { delta_steps = steps[i] - startpoint_steps.axis[i]; dda->delta[i] = (uint32_t)labs(delta_steps); + if (delta_steps) + dda->active_axes |= 1 << i; startpoint_steps.axis[i] = steps[i]; set_direction(dda, i, delta_steps); @@ -255,6 +258,9 @@ void dda_create(DDA *dda, const TARGET *target) { dda->e_direction = (target->axis[E] >= 0)?1:0; } + if (dda->delta[E]) + dda->active_axes |= 1 << E; + if (DEBUG_DDA && (debug_flags & DEBUG_DDA)) sersendf_P(PSTR("[%ld,%ld,%ld,%ld]"), target->axis[X] - startpoint.axis[X], target->axis[Y] - startpoint.axis[Y], @@ -566,28 +572,28 @@ void dda_start(DDA *dda) { void dda_step(DDA *dda) { #if ! defined ACCELERATION_TEMPORAL - if (dda->delta[X]) { + if (dda->active_axes & (1 << X)) { move_state.counter[X] -= dda->delta[X]; if (move_state.counter[X] < 0) { x_step(); move_state.counter[X] += dda->total_steps; } } - if (dda->delta[Y]) { + if (dda->active_axes & (1 << Y)) { move_state.counter[Y] -= dda->delta[Y]; if (move_state.counter[Y] < 0) { y_step(); move_state.counter[Y] += dda->total_steps; } } - if (dda->delta[Z]) { + if (dda->active_axes & (1 << Z)) { move_state.counter[Z] -= dda->delta[Z]; if (move_state.counter[Z] < 0) { z_step(); move_state.counter[Z] += dda->total_steps; } } - if (dda->delta[E]) { + if (dda->active_axes & (1 << E)) { move_state.counter[E] -= dda->delta[E]; if (move_state.counter[E] < 0) { e_step(); diff --git a/dda.h b/dda.h index 0aa853f..dfa70c7 100644 --- a/dda.h +++ b/dda.h @@ -156,6 +156,7 @@ typedef struct { /// word boundaries only and fill smaller variables in between with gaps, /// so keep small variables grouped together to reduce the amount of these /// gaps. See e.g. NXP application note AN10963, page 10f. + uint8_t active_axes; ///< Bit mask of moving axes uint8_t fast_axis; ///< number of the fast axis /// Endstop homing