From c1dbd869f5a2fa1d72a14a085a842053a65fec87 Mon Sep 17 00:00:00 2001 From: Michael Moon Date: Sat, 18 Sep 2010 08:08:31 +1000 Subject: [PATCH] minor fixes: comments, indenting, etc --- dda.c | 100 ++++++++++++++++++++++++++++---------------------------- temp.c | 2 +- timer.c | 4 +-- 3 files changed, 53 insertions(+), 53 deletions(-) diff --git a/dda.c b/dda.c index cc06f13..24b465b 100644 --- a/dda.c +++ b/dda.c @@ -252,15 +252,15 @@ void dda_create(DDA *dda, TARGET *target) { else dda->accel = 0; #elif defined ACCELERATION_RAMPING - dda->ramp_steps = dda->total_steps / 2; - dda->step_no = 0; - // c is initial step time in IOclk ticks - dda->c = ACCELERATION_STEEPNESS << 8; - dda->c_min = (move_duration / target->F) << 8; - dda->n = 1; - dda->ramp_state = RAMP_UP; + dda->ramp_steps = dda->total_steps / 2; + dda->step_no = 0; + // c is initial step time in IOclk ticks + dda->c = ACCELERATION_STEEPNESS << 8; + dda->c_min = (move_duration / target->F) << 8; + dda->n = 1; + dda->ramp_state = RAMP_UP; #else - dda->c = (move_duration / target->F) << 8; + dda->c = (move_duration / target->F) << 8; #endif } @@ -383,52 +383,52 @@ void dda_step(DDA *dda) { #endif #ifdef ACCELERATION_REPRAP - // linear acceleration magic, courtesy of http://www.embedded.com/columns/technicalinsights/56800129?printable=true - if (dda->accel) { - if ( - ((dda->n > 0) && (dda->c > dda->end_c)) || - ((dda->n < 0) && (dda->c < dda->end_c)) - ) { - dda->c = (int32_t) dda->c - ((int32_t) (dda->c * 2) / dda->n); - dda->n += 4; - setTimer(dda->c >> 8); + // linear acceleration magic, courtesy of http://www.embedded.com/columns/technicalinsights/56800129?printable=true + if (dda->accel) { + if ( + ((dda->n > 0) && (dda->c > dda->end_c)) || + ((dda->n < 0) && (dda->c < dda->end_c)) + ) { + dda->c = (int32_t) dda->c - ((int32_t) (dda->c * 2) / dda->n); + dda->n += 4; + setTimer(dda->c >> 8); + } + else if (dda->c != dda->end_c) { + dda->c = dda->end_c; + setTimer(dda->c >> 8); + } + // else we are already at target speed } - else if (dda->c != dda->end_c) { - dda->c = dda->end_c; - setTimer(dda->c >> 8); - } - // else we are already at target speed - } #endif #ifdef ACCELERATION_RAMPING - // - algorithm courtesy of http://www.embedded.com/columns/technicalinsights/56800129?printable=true - // - for simplicity, taking even/uneven number of steps into account dropped - // - number of steps moved is always accurate, speed might be one step off - switch (dda->ramp_state) { - case RAMP_UP: - case RAMP_MAX: - if (dda->step_no >= dda->ramp_steps) { - // RAMP_UP: time to decelerate before reaching maximum speed - // RAMP_MAX: time to decelerate - dda->ramp_state = RAMP_DOWN; - dda->n = -((int32_t)2) - dda->n; + // - algorithm courtesy of http://www.embedded.com/columns/technicalinsights/56800129?printable=true + // - for simplicity, taking even/uneven number of steps into account dropped + // - number of steps moved is always accurate, speed might be one step off + switch (dda->ramp_state) { + case RAMP_UP: + case RAMP_MAX: + if (dda->step_no >= dda->ramp_steps) { + // RAMP_UP: time to decelerate before reaching maximum speed + // RAMP_MAX: time to decelerate + dda->ramp_state = RAMP_DOWN; + dda->n = -((int32_t)2) - dda->n; + } + if (dda->ramp_state == RAMP_MAX) + break; + case RAMP_DOWN: + dda->n += 4; + // be careful of signedness! + dda->c = (int32_t)dda->c - ((int32_t)(dda->c * 2) / dda->n); + if (dda->c <= dda->c_min) { + // maximum speed reached + dda->c = dda->c_min; + dda->ramp_state = RAMP_MAX; + dda->ramp_steps = dda->total_steps - dda->step_no; + } + setTimer(dda->c >> 8); + break; } - if (dda->ramp_state == RAMP_MAX) - break; - case RAMP_DOWN: - dda->n += 4; - // be careful of signedness! - dda->c = (int32_t)dda->c - ((int32_t)(dda->c * 2) / dda->n); - if (dda->c <= dda->c_min) { - // maximum speed reached - dda->c = dda->c_min; - dda->ramp_state = RAMP_MAX; - dda->ramp_steps = dda->total_steps - dda->step_no; - } - setTimer(dda->c >> 8); - break; - } - dda->step_no++; + dda->step_no++; #endif if (did_step) { diff --git a/temp.c b/temp.c index 162879b..7a4285d 100644 --- a/temp.c +++ b/temp.c @@ -3,7 +3,7 @@ This file currently reads temp from a MAX6675 on the SPI bus. - ALL VALUES are in units of 0.25 degrees celsius, so temp_set(500) will set the temperature to 125 celsius, and temp_get() = 600 is reporting a temperature of 150 celsius. + temp fields are 14.2 fixed point, so temp_set(500) will set the temperature to 125 celsius, and temp_get() = 600 is reporting a temperature of 150 celsius. the conversion to/from this unit is done in gcode.c, near: if (next_target.M == 104) diff --git a/timer.c b/timer.c index 19b358f..6cafbcf 100644 --- a/timer.c +++ b/timer.c @@ -96,7 +96,7 @@ uint16_t getTimerCeiling(const uint32_t delay) void setTimer(uint32_t delay) { - // delay is the delay between steps in microsecond ticks. + // delay is the delay between steps in IOclk ticks. // // we break it into 5 different resolutions based on the delay. // then we set the resolution based on the size of the delay. @@ -115,7 +115,7 @@ void setTimer(uint32_t delay) void delay(uint32_t delay) { wd_reset(); while (delay > 65535) { - delayMicrosecondsInterruptible(65534); + delayMicrosecondsInterruptible(65533); delay -= 65535; wd_reset(); }