From 95939ecc229a2a3f71917bb67cfd7ee027ec1e06 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Mon, 4 Oct 2010 15:55:39 +0200 Subject: [PATCH] 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. --- dda.c | 1 + dda_queue.c | 17 ++++++----------- timer.c | 3 --- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/dda.c b/dda.c index 857076e..454ee84 100644 --- a/dda.c +++ b/dda.c @@ -330,6 +330,7 @@ void dda_start(DDA *dda) { // set timeout for first step setTimer(dda->c >> 8); + enableTimerInterrupt(); } } diff --git a/dda_queue.c b/dda_queue.c index 7359291..3ef2665 100644 --- a/dda_queue.c +++ b/dda_queue.c @@ -26,10 +26,7 @@ uint8_t queue_empty() { // It calls a few other functions, though. // ------------------------------------------------------- void queue_step() { - disableTimerInterrupt(); - // 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].waitfor_temp) { if (temp_achieved()) { @@ -42,6 +39,7 @@ void queue_step() { #endif } else { + // NOTE: dda_step makes this interrupt interruptible after steps have been sent but before new speed is calculated. 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 if (movebuffer[mb_tail].live == 0) 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) { @@ -93,9 +84,11 @@ void enqueue(TARGET *t) { #endif // 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() { if (queue_empty() == 0) { // next item @@ -104,6 +97,8 @@ void next_move() { dda_start(&movebuffer[t]); mb_tail = t; } + else + disableTimerInterrupt(); #ifdef XONXOFF // restart transmission if the move buffer is only half full diff --git a/timer.c b/timer.c index 111fc96..a172b04 100644 --- a/timer.c +++ b/timer.c @@ -21,9 +21,6 @@ void setupTimerInterrupt() TCCR1B = MASK(WGM12); // no interrupts yet 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