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,7 +54,7 @@ static unsigned int cleaning_buffer_counter;
54 54
               locked_z2_motor = false;
55 55
 #endif
56 56
 
57
-// Counter variables for the bresenham line tracer
57
+// Counter variables for the Bresenham line tracer
58 58
 static long counter_x, counter_y, counter_z, counter_e;
59 59
 volatile static unsigned long step_events_completed; // The number of step events executed in the current block
60 60
 
@@ -66,7 +66,7 @@ volatile static unsigned long step_events_completed; // The number of step event
66 66
 
67 67
 static long acceleration_time, deceleration_time;
68 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 70
 static char step_loops;
71 71
 static unsigned short OCR1A_nominal;
72 72
 static unsigned short step_loops_nominal;
@@ -205,8 +205,14 @@ volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1 };
205 205
 // intRes = longIn1 * longIn2 >> 24
206 206
 // uses:
207 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 216
   asm volatile ( \
211 217
     "clr r26 \n\t" \
212 218
     "mul %A1, %B2 \n\t" \
@@ -237,6 +243,11 @@ volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1 };
237 243
     "lsr r27 \n\t" \
238 244
     "adc %A0, r26 \n\t" \
239 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 251
     "clr r1 \n\t" \
241 252
     : \
242 253
     "=&r" (intRes) \
@@ -313,7 +324,7 @@ void enable_endstops(bool check) { check_endstops = check; }
313 324
 //  The trapezoid is the shape the speed curve over time. It starts at block->initial_rate, accelerates
314 325
 //  first block->accelerate_until step_events_completed, then keeps going at constant speed until
315 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 329
 void st_wake_up() {
319 330
   //  TCNT1 = 0;
@@ -469,7 +480,7 @@ ISR(TIMER1_COMPA_vect) {
469 480
         if ((current_block->steps[A_AXIS] != current_block->steps[B_AXIS]) || (TEST(out_bits, A_AXIS) == TEST(out_bits, B_AXIS))) {
470 481
           if (TEST(out_bits, X_HEAD))
471 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 484
       #endif
474 485
           { // -direction
475 486
             #ifdef DUAL_X_CARRIAGE
@@ -714,7 +725,7 @@ ISR(TIMER1_COMPA_vect) {
714 725
     unsigned short step_rate;
715 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 729
       acc_step_rate += current_block->initial_rate;
719 730
 
720 731
       // upper limit
@@ -737,7 +748,7 @@ ISR(TIMER1_COMPA_vect) {
737 748
       #endif
738 749
     }
739 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 753
       if (step_rate > acc_step_rate) { // Check step_rate stays positive
743 754
         step_rate = current_block->final_rate;

Loading…
Cancel
Save