From 935a7982369da88b56d6d6b10453559f9448c46b Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 25 May 2019 21:38:59 +0200 Subject: [PATCH] Speedup advance_spread for common divisors --- Firmware/stepper.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 37898f9ce..b3e6427a8 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -734,7 +734,14 @@ FORCE_INLINE void advance_spread(uint16_t timer) else eISR_Err -= timer - block; - eISR_Rate = timer / ticks; + if (ticks == 1) + eISR_Rate = timer; + else if (ticks == 2) + eISR_Rate = timer / 2; + else if (ticks == 4) + eISR_Rate = timer / 4; + else + eISR_Rate = timer / ticks; nextAdvanceISR = eISR_Rate / 2; } #endif @@ -822,9 +829,8 @@ FORCE_INLINE void isr() { } _NEXT_ISR(OCR1A_nominal); #ifdef LIN_ADVANCE - if (current_block->use_advance_lead && nextAdvanceISR != ADV_NEVER) { + if (current_block->use_advance_lead && nextAdvanceISR != ADV_NEVER) advance_spread(OCR1A_nominal); - } #endif } //WRITE_NC(LOGIC_ANALYZER_CH1, false);