diff --git a/timer.c b/timer.c index 1c1244a..838fcc7 100644 --- a/timer.c +++ b/timer.c @@ -19,13 +19,15 @@ #include "dda_queue.h" #endif +#include "memory_barrier.h" + /// how often we overflow and update our clock; with F_CPU=16MHz, max is < 4.096ms (TICK_TIME = 65535) #define TICK_TIME 2 MS /// convert back to ms from cpu ticks so our system clock runs properly if you change TICK_TIME #define TICK_TIME_MS (TICK_TIME / (F_CPU / 1000)) /// time until next step, as output compare register is too small for long step times -volatile uint32_t next_step_time; +uint32_t next_step_time; /// every time our clock fires, we increment this so we know when 10ms has elapsed uint8_t clock_counter_10ms = 0; @@ -125,9 +127,11 @@ void setTimer(uint32_t delay) // save interrupt flag uint8_t sreg = SREG; uint16_t step_start = 0; + // disable interrupts cli(); - + CLI_SEI_BUG_MEMORY_BARRIER(); + // re-enable clock interrupt in case we're recovering from emergency stop TIMSK1 |= MASK(OCIE1B); @@ -173,6 +177,7 @@ void setTimer(uint32_t delay) } // restore interrupt flag + MEMORY_BARRIER(); SREG = sreg; }