diff --git a/dda.c b/dda.c index 0733c3e..0b098d7 100644 --- a/dda.c +++ b/dda.c @@ -209,6 +209,7 @@ void dda_create(DDA *dda, TARGET *target) { // distance * 2400 .. * F_CPU / 40000 so we can move a distance of up to 1800mm without overflowing uint32_t move_duration = ((distance * 2400) / dda->total_steps) * (F_CPU / 40000); + #ifdef ACCELERATION_REPRAP // c is initial step time in IOclk ticks dda->c = (move_duration / startpoint.F) << 8; @@ -269,6 +270,9 @@ void dda_create(DDA *dda, TARGET *target) { } else dda->accel = 0; + #else + dda->c = (move_duration / target->F) << 8; + #endif } if (debug_flags & DEBUG_DDA) @@ -389,6 +393,7 @@ void dda_step(DDA *dda) { sei(); #endif + #ifdef ACCELERATION_REPRAP // linear acceleration magic, courtesy of http://www.embedded.com/columns/technicalinsights/56800129?printable=true if (dda->accel) { if ( @@ -405,6 +410,7 @@ void dda_step(DDA *dda) { } // else we are already at target speed } + #endif if (did_step) { // we stepped, reset timeout diff --git a/dda.h b/dda.h index 2248f10..78863ce 100644 --- a/dda.h +++ b/dda.h @@ -29,7 +29,9 @@ typedef struct { // status fields uint8_t nullmove :1; uint8_t live :1; + #ifdef ACCELERATION_REPRAP uint8_t accel :1; + #endif // wait for temperature to stabilise flag uint8_t waitfor_temp :1; @@ -60,8 +62,10 @@ typedef struct { // linear acceleration variables: c and end_c are 24.8 fixed point timer values, n is the tracking variable uint32_t c; + #ifdef ACCELERATION_REPRAP uint32_t end_c; int32_t n; + #endif } DDA; /* diff --git a/gcode.c b/gcode.c index a4770a3..b3063d7 100644 --- a/gcode.c +++ b/gcode.c @@ -693,7 +693,11 @@ void process_gcode_command(GCODE_COMMAND *gcmd) { serial_writestr_P(PSTR(",F:")); serwrite_int32(movebuffer[mb_tail].endpoint.F); serial_writestr_P(PSTR(",c:")); + #ifdef ACCELERATION_REPRAP serwrite_uint32(movebuffer[mb_tail].end_c); + #else + serwrite_uint32(movebuffer[mb_tail].c); + #endif serial_writestr_P(PSTR("}\n")); print_queue(); diff --git a/machine.h b/machine.h index 033ec7c..49a981a 100644 --- a/machine.h +++ b/machine.h @@ -36,6 +36,11 @@ #define TEMP_HYSTERESIS 20 #define TEMP_RESIDENCY_TIME 60 +// acceleration, reprap style. Each movement starts at the speed of +// the previous command and accelerates or decelerates linearly +// to reach target speed at the end of the movement. +#define ACCELERATION_REPRAP + // -------------------------------------------------------------------------- // you shouldn't need to edit something below this line