Browse Source

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 years ago
parent
commit
e4595fa24a
1 changed files with 19 additions and 4 deletions
  1. 19
    4
      Marlin/stepper.cpp

+ 19
- 4
Marlin/stepper.cpp View File

206
 // uses:
206
 // uses:
207
 // r26 to store 0
207
 // r26 to store 0
208
 // r27 to store the byte 1 of the 48bit result
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
   asm volatile ( \
220
   asm volatile ( \
211
     "clr r26 \n\t" \
221
     "clr r26 \n\t" \
212
     "mul %A1, %B2 \n\t" \
222
     "mul %A1, %B2 \n\t" \
237
     "lsr r27 \n\t" \
247
     "lsr r27 \n\t" \
238
     "adc %A0, r26 \n\t" \
248
     "adc %A0, r26 \n\t" \
239
     "adc %B0, r26 \n\t" \
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
     "clr r1 \n\t" \
255
     "clr r1 \n\t" \
241
     : \
256
     : \
242
     "=&r" (intRes) \
257
     "=&r" (intRes) \
313
 //  The trapezoid is the shape the speed curve over time. It starts at block->initial_rate, accelerates
328
 //  The trapezoid is the shape the speed curve over time. It starts at block->initial_rate, accelerates
314
 //  first block->accelerate_until step_events_completed, then keeps going at constant speed until
329
 //  first block->accelerate_until step_events_completed, then keeps going at constant speed until
315
 //  step_events_completed reaches block->decelerate_after after which it decelerates until the trapezoid generator is reset.
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
 void st_wake_up() {
333
 void st_wake_up() {
319
   //  TCNT1 = 0;
334
   //  TCNT1 = 0;
714
     unsigned short step_rate;
729
     unsigned short step_rate;
715
     if (step_events_completed <= (unsigned long)current_block->accelerate_until) {
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
       acc_step_rate += current_block->initial_rate;
733
       acc_step_rate += current_block->initial_rate;
719
 
734
 
720
       // upper limit
735
       // upper limit
737
       #endif
752
       #endif
738
     }
753
     }
739
     else if (step_events_completed > (unsigned long)current_block->decelerate_after) {
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
       if (step_rate > acc_step_rate) { // Check step_rate stays positive
757
       if (step_rate > acc_step_rate) { // Check step_rate stays positive
743
         step_rate = current_block->final_rate;
758
         step_rate = current_block->final_rate;

Loading…
Cancel
Save