diff --git a/clock.c b/clock.c index 53adf65..d0868c2 100644 --- a/clock.c +++ b/clock.c @@ -16,6 +16,7 @@ #ifdef TEMP_INTERCOM #include "intercom.h" #endif +#include "memory_barrier.h" /*! do stuff every 1/4 second @@ -25,8 +26,14 @@ void clock_250ms() { if (steptimeout > (30 * 4)) { power_off(); } - else if (heaters_all_off()) + else if (heaters_all_off()) { + uint8_t save_reg = SREG; + cli(); + CLI_SEI_BUG_MEMORY_BARRIER(); steptimeout++; + MEMORY_BARRIER(); + SREG = save_reg; + } ifclock(CLOCK_FLAG_1S) { if (debug_flags & DEBUG_POSITION) { diff --git a/dda.c b/dda.c index 846af3a..ac62a54 100644 --- a/dda.c +++ b/dda.c @@ -23,7 +23,7 @@ #endif /// step timeout -uint8_t steptimeout = 0; +volatile uint8_t steptimeout = 0; /* position tracking diff --git a/dda.h b/dda.h index 4d05685..6699d27 100644 --- a/dda.h +++ b/dda.h @@ -122,7 +122,8 @@ typedef struct { */ /// steptimeout is set to zero when we step, and increases over time so we can turn the motors off when they've been idle for a while -extern uint8_t steptimeout; +/// It is also used inside and outside of interrupts, which is why it has been made volatile +extern volatile uint8_t steptimeout; /// startpoint holds the endpoint of the most recently created DDA, so we know where the next one created starts. could also be called last_endpoint extern TARGET startpoint;