Don't disable the stepper timer interrupt while stepping.

After lots of try and error the conclusion was, disabling this
interrupt makes the timer vulnerable to be messed up by
characters incoming over the serial line. So, now the
interrupt is enabled as a move starts and not disabled before
the move, and all subsequent moves are done.
This commit is contained in:
Markus Hitter 2010-10-04 15:55:39 +02:00
parent fb53c2c0a8
commit 95939ecc22
3 changed files with 7 additions and 14 deletions

1
dda.c
View File

@ -330,6 +330,7 @@ void dda_start(DDA *dda) {
// set timeout for first step // set timeout for first step
setTimer(dda->c >> 8); setTimer(dda->c >> 8);
enableTimerInterrupt();
} }
} }

View File

@ -26,10 +26,7 @@ uint8_t queue_empty() {
// It calls a few other functions, though. // It calls a few other functions, though.
// ------------------------------------------------------- // -------------------------------------------------------
void queue_step() { void queue_step() {
disableTimerInterrupt();
// do our next step // do our next step
// NOTE: dda_step makes this interrupt interruptible after steps have been sent but before new speed is calculated.
if (movebuffer[mb_tail].live) { if (movebuffer[mb_tail].live) {
if (movebuffer[mb_tail].waitfor_temp) { if (movebuffer[mb_tail].waitfor_temp) {
if (temp_achieved()) { if (temp_achieved()) {
@ -42,6 +39,7 @@ void queue_step() {
#endif #endif
} }
else { else {
// NOTE: dda_step makes this interrupt interruptible after steps have been sent but before new speed is calculated.
dda_step(&(movebuffer[mb_tail])); dda_step(&(movebuffer[mb_tail]));
} }
} }
@ -50,13 +48,6 @@ void queue_step() {
// the dda dies not directly after its last step, but when the timer fires and there's no steps to do // the dda dies not directly after its last step, but when the timer fires and there's no steps to do
if (movebuffer[mb_tail].live == 0) if (movebuffer[mb_tail].live == 0)
next_move(); next_move();
#if STEP_INTERRUPT_INTERRUPTIBLE
cli();
#endif
// check queue, if empty we don't need to interrupt again until re-enabled in dda_create
if (queue_empty() == 0)
enableTimerInterrupt();
} }
void enqueue(TARGET *t) { void enqueue(TARGET *t) {
@ -93,9 +84,11 @@ void enqueue(TARGET *t) {
#endif #endif
// fire up in case we're not running yet // fire up in case we're not running yet
enableTimerInterrupt(); if (TIMSK1 == 0)
next_move();
} }
// sometimes called from normal program execution, sometimes from interrupt context
void next_move() { void next_move() {
if (queue_empty() == 0) { if (queue_empty() == 0) {
// next item // next item
@ -104,6 +97,8 @@ void next_move() {
dda_start(&movebuffer[t]); dda_start(&movebuffer[t]);
mb_tail = t; mb_tail = t;
} }
else
disableTimerInterrupt();
#ifdef XONXOFF #ifdef XONXOFF
// restart transmission if the move buffer is only half full // restart transmission if the move buffer is only half full

View File

@ -21,9 +21,6 @@ void setupTimerInterrupt()
TCCR1B = MASK(WGM12); TCCR1B = MASK(WGM12);
// no interrupts yet // no interrupts yet
TIMSK1 = 0; TIMSK1 = 0;
//start off with a slow frequency.
setTimer(F_CPU / 100);
} }
// the following are all from reprap project 5D firmware with some modification to reduce redundancy // the following are all from reprap project 5D firmware with some modification to reduce redundancy