Remove volatile from next_step_time as it can be easily managed using
memory barriers since it is only touched inside a single interrupt
handler or while interrupts are disabled in setTimer().
This saves about 90 bytes since it no longer needs to be reloaded multiple
Loading branch information
1 changed file
and 2 deletions.
@@ -19,13 +19,15 @@
include "dda_queue.h "
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;
/// 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
// re-enable clock interrupt in case we're recovering from emergency stop
@@ -173,6 +177,7 @@ void setTimer(uint32_t delay)
// restore interrupt flag
SREG = sreg;