浏览代码

Speedup advance_spread for common divisors

Yuri D'Elia 5 年之前
父节点
当前提交
935a798236
共有 1 个文件被更改,包括 9 次插入3 次删除
  1. 9 3
      Firmware/stepper.cpp

+ 9 - 3
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);