Browse Source

Merge pull request #1926 from nophead/acceleration_fix

Fixed jump in speed at high accelerations on axes with lots of steps
Scott Lahteine 10 years ago
parent
commit
67a4471324
1 changed files with 19 additions and 8 deletions
  1. 19
    8
      Marlin/stepper.cpp

+ 19
- 8
Marlin/stepper.cpp View File

54
               locked_z2_motor = false;
54
               locked_z2_motor = false;
55
 #endif
55
 #endif
56
 
56
 
57
-// Counter variables for the bresenham line tracer
57
+// Counter variables for the Bresenham line tracer
58
 static long counter_x, counter_y, counter_z, counter_e;
58
 static long counter_x, counter_y, counter_z, counter_e;
59
 volatile static unsigned long step_events_completed; // The number of step events executed in the current block
59
 volatile static unsigned long step_events_completed; // The number of step events executed in the current block
60
 
60
 
66
 
66
 
67
 static long acceleration_time, deceleration_time;
67
 static long acceleration_time, deceleration_time;
68
 //static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
68
 //static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
69
-static unsigned short acc_step_rate; // needed for deccelaration start point
69
+static unsigned short acc_step_rate; // needed for deceleration start point
70
 static char step_loops;
70
 static char step_loops;
71
 static unsigned short OCR1A_nominal;
71
 static unsigned short OCR1A_nominal;
72
 static unsigned short step_loops_nominal;
72
 static unsigned short step_loops_nominal;
205
 // intRes = longIn1 * longIn2 >> 24
205
 // intRes = longIn1 * longIn2 >> 24
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
209
-#define MultiU24X24toH16(intRes, longIn1, longIn2) \
208
+// r27 to store bits 16-23 of the 48bit result. The top bit is used to round the two byte result.
209
+// note that the lower two bytes and the upper byte of the 48bit result are not calculated.
210
+// this can cause the result to be out by one as the lower bytes may cause carries into the upper ones.
211
+// B0 A0 are bits 24-39 and are the returned value
212
+// C1 B1 A1 is longIn1
213
+// D2 C2 B2 A2 is longIn2
214
+//
215
+#define MultiU24X32toH16(intRes, longIn1, longIn2) \
210
   asm volatile ( \
216
   asm volatile ( \
211
     "clr r26 \n\t" \
217
     "clr r26 \n\t" \
212
     "mul %A1, %B2 \n\t" \
218
     "mul %A1, %B2 \n\t" \
237
     "lsr r27 \n\t" \
243
     "lsr r27 \n\t" \
238
     "adc %A0, r26 \n\t" \
244
     "adc %A0, r26 \n\t" \
239
     "adc %B0, r26 \n\t" \
245
     "adc %B0, r26 \n\t" \
246
+    "mul %D2, %A1 \n\t" \
247
+    "add %A0, r0 \n\t" \
248
+    "adc %B0, r1 \n\t" \
249
+    "mul %D2, %B1 \n\t" \
250
+    "add %B0, r0 \n\t" \
240
     "clr r1 \n\t" \
251
     "clr r1 \n\t" \
241
     : \
252
     : \
242
     "=&r" (intRes) \
253
     "=&r" (intRes) \
313
 //  The trapezoid is the shape the speed curve over time. It starts at block->initial_rate, accelerates
324
 //  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
325
 //  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.
326
 //  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.
327
+//  The slope of acceleration is calculated using v = u + at where t is the accumulated timer values of the steps so far.
317
 
328
 
318
 void st_wake_up() {
329
 void st_wake_up() {
319
   //  TCNT1 = 0;
330
   //  TCNT1 = 0;
469
         if ((current_block->steps[A_AXIS] != current_block->steps[B_AXIS]) || (TEST(out_bits, A_AXIS) == TEST(out_bits, B_AXIS))) {
480
         if ((current_block->steps[A_AXIS] != current_block->steps[B_AXIS]) || (TEST(out_bits, A_AXIS) == TEST(out_bits, B_AXIS))) {
470
           if (TEST(out_bits, X_HEAD))
481
           if (TEST(out_bits, X_HEAD))
471
       #else
482
       #else
472
-          if (TEST(out_bits, X_AXIS))   // stepping along -X axis (regular cartesians bot)
483
+          if (TEST(out_bits, X_AXIS))   // stepping along -X axis (regular Cartesian bot)
473
       #endif
484
       #endif
474
           { // -direction
485
           { // -direction
475
             #ifdef DUAL_X_CARRIAGE
486
             #ifdef DUAL_X_CARRIAGE
714
     unsigned short step_rate;
725
     unsigned short step_rate;
715
     if (step_events_completed <= (unsigned long)current_block->accelerate_until) {
726
     if (step_events_completed <= (unsigned long)current_block->accelerate_until) {
716
 
727
 
717
-      MultiU24X24toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
728
+      MultiU24X32toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
718
       acc_step_rate += current_block->initial_rate;
729
       acc_step_rate += current_block->initial_rate;
719
 
730
 
720
       // upper limit
731
       // upper limit
737
       #endif
748
       #endif
738
     }
749
     }
739
     else if (step_events_completed > (unsigned long)current_block->decelerate_after) {
750
     else if (step_events_completed > (unsigned long)current_block->decelerate_after) {
740
-      MultiU24X24toH16(step_rate, deceleration_time, current_block->acceleration_rate);
751
+      MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate);
741
 
752
 
742
       if (step_rate > acc_step_rate) { // Check step_rate stays positive
753
       if (step_rate > acc_step_rate) { // Check step_rate stays positive
743
         step_rate = current_block->final_rate;
754
         step_rate = current_block->final_rate;

Loading…
Cancel
Save