From 18565b776f3768772c3bb574a53be09d974ed7cd Mon Sep 17 00:00:00 2001 From: Michael Moon Date: Wed, 20 Oct 2010 17:22:39 +1100 Subject: [PATCH] attempt to fix precision underflow in UM_PER_STEP macros --- dda.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/dda.c b/dda.c index 762fc46..a4bb7dd 100644 --- a/dda.c +++ b/dda.c @@ -70,10 +70,10 @@ /* Used in distance calculation during DDA setup */ -#define UM_PER_STEP_X ((uint32_t) ((1000.0 / STEPS_PER_MM_X) + 0.5)) -#define UM_PER_STEP_Y ((uint32_t) ((1000.0 / STEPS_PER_MM_Y) + 0.5)) -#define UM_PER_STEP_Z ((uint32_t) ((1000.0 / STEPS_PER_MM_Z) + 0.5)) -#define UM_PER_STEP_E ((uint32_t) ((1000.0 / STEPS_PER_MM_E) + 0.5)) +#define UM_PER_STEP_X 1000.0 / STEPS_PER_MM_X +#define UM_PER_STEP_Y 1000.0 / STEPS_PER_MM_Y +#define UM_PER_STEP_Z 1000.0 / STEPS_PER_MM_Z +#define UM_PER_STEP_E 1000.0 / STEPS_PER_MM_E /* Maths @@ -271,16 +271,16 @@ void dda_create(DDA *dda, TARGET *target) { // similarly, find out how fast we can run our axes. // do this for each axis individually, as the combined speed of two or more axes can be higher than the capabilities of a single one. c_limit = 0; - c_limit_calc = ((dda->x_delta * UM_PER_STEP_X * 2400) / dda->total_steps * (F_CPU / 40000) / MAXIMUM_FEEDRATE_X) << 8; + c_limit_calc = ((uint32_t) ((dda->x_delta * UM_PER_STEP_X * 2400) / dda->total_steps * (F_CPU / 40000) / MAXIMUM_FEEDRATE_X)) << 8; if (c_limit_calc > c_limit) c_limit = c_limit_calc; - c_limit_calc = ((dda->y_delta * UM_PER_STEP_Y * 2400) / dda->total_steps * (F_CPU / 40000) / MAXIMUM_FEEDRATE_Y) << 8; + c_limit_calc = ((uint32_t) ((dda->y_delta * UM_PER_STEP_Y * 2400) / dda->total_steps * (F_CPU / 40000) / MAXIMUM_FEEDRATE_Y)) << 8; if (c_limit_calc > c_limit) c_limit = c_limit_calc; - c_limit_calc = ((dda->z_delta * UM_PER_STEP_Z * 2400) / dda->total_steps * (F_CPU / 40000) / MAXIMUM_FEEDRATE_Z) << 8; + c_limit_calc = ((uint32_t) ((dda->z_delta * UM_PER_STEP_Z * 2400) / dda->total_steps * (F_CPU / 40000) / MAXIMUM_FEEDRATE_Z)) << 8; if (c_limit_calc > c_limit) c_limit = c_limit_calc; - c_limit_calc = ((dda->e_delta * UM_PER_STEP_E * 2400) / dda->total_steps * (F_CPU / 40000) / MAXIMUM_FEEDRATE_E) << 8; + c_limit_calc = ((uint32_t) ((dda->e_delta * UM_PER_STEP_E * 2400) / dda->total_steps * (F_CPU / 40000) / MAXIMUM_FEEDRATE_E)) << 8; if (c_limit_calc > c_limit) c_limit = c_limit_calc;