Pārlūkot izejas kodu

Fixed jump in speed when using high accelerations on axes with lots of steps.

I.e., when acceleration * steps per mm > 2,000,000.
This was done by changing MultiU24X24toH16 to take a 32b bit operand.
Removed the claim that stepper.cpp uses the Leib algorithm.
Chris Palmer 10 gadus atpakaļ
vecāks
revīzija
e4595fa24a
1 mainītis faili ar 19 papildinājumiem un 4 dzēšanām
  1. 19
    4
      Marlin/stepper.cpp

+ 19
- 4
Marlin/stepper.cpp Parādīt failu

@@ -206,7 +206,17 @@ volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1 };
206 206
 // uses:
207 207
 // r26 to store 0
208 208
 // r27 to store the byte 1 of the 48bit result
209
-#define MultiU24X24toH16(intRes, longIn1, longIn2) \
209
+// intRes = longIn1 * longIn2 >> 24
210
+// uses:
211
+// r26 to store 0
212
+// r27 to store bits 16-23 of the 48bit result. The top bit is used to round the two byte result.
213
+// note that the lower two bytes and the upper byte of the 48bit result are not calculated.
214
+// this can cause the result to be out by one as the lower bytes may cause carries into the upper ones.
215
+// B0 A0 are bits 24-39 and are the returned value
216
+// C1 B1 A1 is longIn1
217
+// D2 C2 B2 A2 is longIn2
218
+//
219
+#define MultiU24X32toH16(intRes, longIn1, longIn2) \
210 220
   asm volatile ( \
211 221
     "clr r26 \n\t" \
212 222
     "mul %A1, %B2 \n\t" \
@@ -237,6 +247,11 @@ volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1 };
237 247
     "lsr r27 \n\t" \
238 248
     "adc %A0, r26 \n\t" \
239 249
     "adc %B0, r26 \n\t" \
250
+    "mul %D2, %A1 \n\t" \
251
+    "add %A0, r0 \n\t" \
252
+    "adc %B0, r1 \n\t" \
253
+    "mul %D2, %B1 \n\t" \
254
+    "add %B0, r0 \n\t" \
240 255
     "clr r1 \n\t" \
241 256
     : \
242 257
     "=&r" (intRes) \
@@ -313,7 +328,7 @@ void enable_endstops(bool check) { check_endstops = check; }
313 328
 //  The trapezoid is the shape the speed curve over time. It starts at block->initial_rate, accelerates
314 329
 //  first block->accelerate_until step_events_completed, then keeps going at constant speed until
315 330
 //  step_events_completed reaches block->decelerate_after after which it decelerates until the trapezoid generator is reset.
316
-//  The slope of acceleration is calculated with the leib ramp alghorithm.
331
+//  The slope of acceleration is calculated using v = u + at where t is the accumulated timer values of the steps so far.
317 332
 
318 333
 void st_wake_up() {
319 334
   //  TCNT1 = 0;
@@ -714,7 +729,7 @@ ISR(TIMER1_COMPA_vect) {
714 729
     unsigned short step_rate;
715 730
     if (step_events_completed <= (unsigned long)current_block->accelerate_until) {
716 731
 
717
-      MultiU24X24toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
732
+      MultiU24X32toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
718 733
       acc_step_rate += current_block->initial_rate;
719 734
 
720 735
       // upper limit
@@ -737,7 +752,7 @@ ISR(TIMER1_COMPA_vect) {
737 752
       #endif
738 753
     }
739 754
     else if (step_events_completed > (unsigned long)current_block->decelerate_after) {
740
-      MultiU24X24toH16(step_rate, deceleration_time, current_block->acceleration_rate);
755
+      MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate);
741 756
 
742 757
       if (step_rate > acc_step_rate) { // Check step_rate stays positive
743 758
         step_rate = current_block->final_rate;

Notiek ielāde…
Atcelt
Saglabāt