Limit effect on dda->c when computing reprap style acceleration.

This fix is really a hack to protect from overflow/underflows
in the acceleration code due to the limited precision of the
fixed point calculations. It does, however, protect the code
from accidently turning off the step timer or setting the
timer interval value outside of the range defined by the current
interval and the ultimate endpoint interval.

This is a cleanup replacement for the code posted on the reprap forum:
http://forums.reprap.org/read.php?147,33082,83467#msg-83467
This commit is contained in:
Jim McGee 2011-05-13 21:38:23 -07:00 committed by Michael Moon
parent 5dc0c80f0b
commit 408718d2bb
1 changed files with 17 additions and 6 deletions

23
dda.c
View File

@ -481,12 +481,23 @@ void dda_step(DDA *dda) {
#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;
if ((dda->c > dda->end_c) && (dda->n > 0)) {
uint32_t new_c = dda->c - (dda->c * 2) / dda->n;
if (new_c <= dda->c && new_c > dda->end_c) {
dda->c = new_c;
dda->n += 4;
}
else
dda->c = dda->end_c;
}
else if ((dda->c < dda->end_c) && (dda->n < 0)) {
uint32_t new_c = dda->c + ((dda->c * 2) / -dda->n);
if (new_c >= dda->c && new_c < dda->end_c) {
dda->c = new_c;
dda->n += 4;
}
else
dda->c = dda->end_c;
}
else if (dda->c != dda->end_c) {
dda->c = dda->end_c;