Pārlūkot izejas kodu

Fix #5699 - LIN_ADVANCE freeze when ADV_RATE returns 0

Ross Allan 7 gadus atpakaļ
vecāks
revīzija
cfcd069501
1 mainītis faili ar 18 papildinājumiem un 5 dzēšanām
  1. 18
    5
      Marlin/stepper.cpp

+ 18
- 5
Marlin/stepper.cpp Parādīt failu

@@ -110,9 +110,22 @@ volatile uint32_t Stepper::step_events_completed = 0; // The number of step even
110 110
          Stepper::advance;
111 111
   #endif
112 112
 
113
-  #define ADV_RATE(T, L) (e_steps[TOOL_E_INDEX] ? (T) * (L) / abs(e_steps[TOOL_E_INDEX]) : ADV_NEVER)
113
+  /**
114
+   * See https://github.com/MarlinFirmware/Marlin/issues/5699#issuecomment-309264382
115
+   *
116
+   * This fix isn't perfect and may lose steps - but better than locking up completely
117
+   * in future the planner should slow down if advance stepping rate would be too high
118
+   */
119
+  FORCE_INLINE uint16_t adv_rate(const int steps, const uint16_t timer, const uint8_t loops) {
120
+    if (steps) {
121
+      const uint16_t rate = (timer * loops) / abs(steps);
122
+      //return constrain(rate, 1, ADV_NEVER - 1)
123
+      return rate ? rate : 1;
124
+    }
125
+    return ADV_NEVER;
126
+  }
114 127
 
115
-#endif
128
+#endif // ADVANCE || LIN_ADVANCE
116 129
 
117 130
 long Stepper::acceleration_time, Stepper::deceleration_time;
118 131
 
@@ -743,7 +756,7 @@ void Stepper::isr() {
743 756
     #endif // ADVANCE or LIN_ADVANCE
744 757
 
745 758
     #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
746
-      eISR_Rate = ADV_RATE(timer, step_loops);
759
+      eISR_Rate = adv_rate(e_steps[TOOL_E_INDEX], timer, step_loops);
747 760
     #endif
748 761
   }
749 762
   else if (step_events_completed > (uint32_t)current_block->decelerate_after) {
@@ -797,7 +810,7 @@ void Stepper::isr() {
797 810
     #endif // ADVANCE or LIN_ADVANCE
798 811
 
799 812
     #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
800
-      eISR_Rate = ADV_RATE(timer, step_loops);
813
+      eISR_Rate = adv_rate(e_steps[TOOL_E_INDEX], timer, step_loops);
801 814
     #endif
802 815
   }
803 816
   else {
@@ -807,7 +820,7 @@ void Stepper::isr() {
807 820
       if (current_block->use_advance_lead)
808 821
         current_estep_rate[TOOL_E_INDEX] = final_estep_rate;
809 822
 
810
-      eISR_Rate = ADV_RATE(OCR1A_nominal, step_loops_nominal);
823
+      eISR_Rate = adv_rate(e_steps[TOOL_E_INDEX], OCR1A_nominal, step_loops_nominal);
811 824
 
812 825
     #endif
813 826
 

Notiek ielāde…
Atcelt
Saglabāt