Explorar el Código

Merge pull request #4738 from thinkyhead/rc_ensure_floats

Optimize stepper ISRs, plus cleanup, shorthand
Scott Lahteine hace 8 años
padre
commit
c3caa42630
Se han modificado 6 ficheros con 97 adiciones y 59 borrados
  1. 6
    1
      Marlin/Conditionals_post.h
  2. 12
    17
      Marlin/Marlin_main.cpp
  3. 5
    7
      Marlin/planner.cpp
  4. 2
    2
      Marlin/planner.h
  5. 71
    31
      Marlin/stepper.cpp
  6. 1
    1
      Marlin/stepper.h

+ 6
- 1
Marlin/Conditionals_post.h Ver fichero

35
   #endif
35
   #endif
36
 
36
 
37
   /**
37
   /**
38
-   * Axis lengths
38
+   * Axis lengths and center
39
    */
39
    */
40
   #define X_MAX_LENGTH (X_MAX_POS - (X_MIN_POS))
40
   #define X_MAX_LENGTH (X_MAX_POS - (X_MIN_POS))
41
   #define Y_MAX_LENGTH (Y_MAX_POS - (Y_MIN_POS))
41
   #define Y_MAX_LENGTH (Y_MAX_POS - (Y_MIN_POS))
42
   #define Z_MAX_LENGTH (Z_MAX_POS - (Z_MIN_POS))
42
   #define Z_MAX_LENGTH (Z_MAX_POS - (Z_MIN_POS))
43
+  #define X_CENTER float((X_MIN_POS + X_MAX_POS) * 0.5)
44
+  #define Y_CENTER float((Y_MIN_POS + Y_MAX_POS) * 0.5)
45
+  #define Z_CENTER float((Z_MIN_POS + Z_MAX_POS) * 0.5)
43
 
46
 
44
   /**
47
   /**
45
    * CoreXY and CoreXZ
48
    * CoreXY and CoreXZ
127
    */
130
    */
128
   #define HAS_PROBING_PROCEDURE (ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST))
131
   #define HAS_PROBING_PROCEDURE (ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST))
129
 
132
 
133
+  #define HOMING_Z_WITH_PROBE (HAS_BED_PROBE && Z_HOME_DIR < 0 && ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN))
134
+
130
   // Boundaries for probing based on set limits
135
   // Boundaries for probing based on set limits
131
   #define MIN_PROBE_X (max(X_MIN_POS, X_MIN_POS + X_PROBE_OFFSET_FROM_EXTRUDER))
136
   #define MIN_PROBE_X (max(X_MIN_POS, X_MIN_POS + X_PROBE_OFFSET_FROM_EXTRUDER))
132
   #define MAX_PROBE_X (min(X_MAX_POS, X_MAX_POS + X_PROBE_OFFSET_FROM_EXTRUDER))
137
   #define MAX_PROBE_X (min(X_MAX_POS, X_MAX_POS + X_PROBE_OFFSET_FROM_EXTRUDER))

+ 12
- 17
Marlin/Marlin_main.cpp Ver fichero

1586
 
1586
 
1587
     if (axis == Z_AXIS) {
1587
     if (axis == Z_AXIS) {
1588
       #if HAS_BED_PROBE && Z_HOME_DIR < 0
1588
       #if HAS_BED_PROBE && Z_HOME_DIR < 0
1589
-        #if DISABLED(Z_MIN_PROBE_ENDSTOP)
1589
+        #if HOMING_Z_WITH_PROBE
1590
           current_position[Z_AXIS] -= zprobe_zoffset;
1590
           current_position[Z_AXIS] -= zprobe_zoffset;
1591
           #if ENABLED(DEBUG_LEVELING_FEATURE)
1591
           #if ENABLED(DEBUG_LEVELING_FEATURE)
1592
             if (DEBUGGING(LEVELING)) {
1592
             if (DEBUGGING(LEVELING)) {
2049
     #endif
2049
     #endif
2050
   #endif
2050
   #endif
2051
 
2051
 
2052
-  #define DEPLOY_PROBE() set_probe_deployed( true )
2053
-  #define STOW_PROBE() set_probe_deployed( false )
2052
+  #define DEPLOY_PROBE() set_probe_deployed(true)
2053
+  #define STOW_PROBE() set_probe_deployed(false)
2054
 
2054
 
2055
   // returns false for ok and true for failure
2055
   // returns false for ok and true for failure
2056
   static bool set_probe_deployed(bool deploy) {
2056
   static bool set_probe_deployed(bool deploy) {
2073
       if (axis_unhomed_error(true, true,  true )) { stop(); return true; }
2073
       if (axis_unhomed_error(true, true,  true )) { stop(); return true; }
2074
     #endif
2074
     #endif
2075
 
2075
 
2076
-    float oldXpos = current_position[X_AXIS]; // save x position
2077
-    float oldYpos = current_position[Y_AXIS]; // save y position
2076
+    float oldXpos = current_position[X_AXIS],
2077
+          oldYpos = current_position[Y_AXIS];
2078
 
2078
 
2079
     #ifdef _TRIGGERED_WHEN_STOWED_TEST
2079
     #ifdef _TRIGGERED_WHEN_STOWED_TEST
2080
 
2080
 
2430
 #define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS)
2430
 #define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS)
2431
 
2431
 
2432
 static void homeaxis(AxisEnum axis) {
2432
 static void homeaxis(AxisEnum axis) {
2433
-  #define HOMEAXIS_DO(LETTER) \
2434
-    ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))
2433
+  #define CAN_HOME(A) \
2434
+    (axis == A##_AXIS && ((A##_MIN_PIN > -1 && A##_HOME_DIR < 0) || (A##_MAX_PIN > -1 && A##_HOME_DIR > 0)))
2435
 
2435
 
2436
-  if (!(axis == X_AXIS ? HOMEAXIS_DO(X) : axis == Y_AXIS ? HOMEAXIS_DO(Y) : axis == Z_AXIS ? HOMEAXIS_DO(Z) : false)) return;
2436
+  if (!CAN_HOME(X) && !CAN_HOME(Y) && !CAN_HOME(Z)) return;
2437
 
2437
 
2438
   #if ENABLED(DEBUG_LEVELING_FEATURE)
2438
   #if ENABLED(DEBUG_LEVELING_FEATURE)
2439
     if (DEBUGGING(LEVELING)) {
2439
     if (DEBUGGING(LEVELING)) {
2449
     home_dir(axis);
2449
     home_dir(axis);
2450
 
2450
 
2451
   // Homing Z towards the bed? Deploy the Z probe or endstop.
2451
   // Homing Z towards the bed? Deploy the Z probe or endstop.
2452
-  #if HAS_BED_PROBE && Z_HOME_DIR < 0 && DISABLED(Z_MIN_PROBE_ENDSTOP)
2452
+  #if HOMING_Z_WITH_PROBE
2453
     if (axis == Z_AXIS) {
2453
     if (axis == Z_AXIS) {
2454
       #if ENABLED(DEBUG_LEVELING_FEATURE)
2454
       #if ENABLED(DEBUG_LEVELING_FEATURE)
2455
         if (DEBUGGING(LEVELING)) SERIAL_ECHOPGM("> ");
2455
         if (DEBUGGING(LEVELING)) SERIAL_ECHOPGM("> ");
2532
   #endif
2532
   #endif
2533
 
2533
 
2534
   // Put away the Z probe
2534
   // Put away the Z probe
2535
-  #if HAS_BED_PROBE && Z_HOME_DIR < 0 && DISABLED(Z_MIN_PROBE_ENDSTOP)
2535
+  #if HOMING_Z_WITH_PROBE
2536
     if (axis == Z_AXIS) {
2536
     if (axis == Z_AXIS) {
2537
       #if ENABLED(DEBUG_LEVELING_FEATURE)
2537
       #if ENABLED(DEBUG_LEVELING_FEATURE)
2538
         if (DEBUGGING(LEVELING)) SERIAL_ECHOPGM("> ");
2538
         if (DEBUGGING(LEVELING)) SERIAL_ECHOPGM("> ");
3104
         #if ENABLED(Z_SAFE_HOMING)
3104
         #if ENABLED(Z_SAFE_HOMING)
3105
 
3105
 
3106
           #if ENABLED(DEBUG_LEVELING_FEATURE)
3106
           #if ENABLED(DEBUG_LEVELING_FEATURE)
3107
-            if (DEBUGGING(LEVELING)) {
3108
-              SERIAL_ECHOLNPGM("> Z_SAFE_HOMING >>>");
3109
-            }
3107
+            if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("> Z_SAFE_HOMING >>>");
3110
           #endif
3108
           #endif
3111
 
3109
 
3112
           if (home_all_axis) {
3110
           if (home_all_axis) {
3127
             destination[Z_AXIS] = current_position[Z_AXIS]; // Z is already at the right height
3125
             destination[Z_AXIS] = current_position[Z_AXIS]; // Z is already at the right height
3128
 
3126
 
3129
             #if ENABLED(DEBUG_LEVELING_FEATURE)
3127
             #if ENABLED(DEBUG_LEVELING_FEATURE)
3130
-              if (DEBUGGING(LEVELING)) {
3131
-                DEBUG_POS("> Z_SAFE_HOMING > home_all_axis", current_position);
3132
-                DEBUG_POS("> Z_SAFE_HOMING > home_all_axis", destination);
3133
-              }
3128
+              if (DEBUGGING(LEVELING)) DEBUG_POS("> Z_SAFE_HOMING > home_all_axis", destination);
3134
             #endif
3129
             #endif
3135
 
3130
 
3136
             // Move in the XY plane
3131
             // Move in the XY plane

+ 5
- 7
Marlin/planner.cpp Ver fichero

203
 
203
 
204
 
204
 
205
 // The kernel called by recalculate() when scanning the plan from last to first entry.
205
 // The kernel called by recalculate() when scanning the plan from last to first entry.
206
-void Planner::reverse_pass_kernel(block_t* previous, block_t* current, block_t* next) {
206
+void Planner::reverse_pass_kernel(block_t* current, block_t* next) {
207
   if (!current) return;
207
   if (!current) return;
208
-  UNUSED(previous);
209
 
208
 
210
   if (next) {
209
   if (next) {
211
     // If entry speed is already at the maximum entry speed, no need to recheck. Block is cruising.
210
     // If entry speed is already at the maximum entry speed, no need to recheck. Block is cruising.
250
       block[2] = block[1];
249
       block[2] = block[1];
251
       block[1] = block[0];
250
       block[1] = block[0];
252
       block[0] = &block_buffer[b];
251
       block[0] = &block_buffer[b];
253
-      reverse_pass_kernel(block[0], block[1], block[2]);
252
+      reverse_pass_kernel(block[1], block[2]);
254
     }
253
     }
255
   }
254
   }
256
 }
255
 }
257
 
256
 
258
 // The kernel called by recalculate() when scanning the plan from first to last entry.
257
 // The kernel called by recalculate() when scanning the plan from first to last entry.
259
-void Planner::forward_pass_kernel(block_t* previous, block_t* current, block_t* next) {
258
+void Planner::forward_pass_kernel(block_t* previous, block_t* current) {
260
   if (!previous) return;
259
   if (!previous) return;
261
-  UNUSED(next);
262
 
260
 
263
   // If the previous block is an acceleration block, but it is not long enough to complete the
261
   // If the previous block is an acceleration block, but it is not long enough to complete the
264
   // full speed change within the block, we need to adjust the entry speed accordingly. Entry
262
   // full speed change within the block, we need to adjust the entry speed accordingly. Entry
288
     block[0] = block[1];
286
     block[0] = block[1];
289
     block[1] = block[2];
287
     block[1] = block[2];
290
     block[2] = &block_buffer[b];
288
     block[2] = &block_buffer[b];
291
-    forward_pass_kernel(block[0], block[1], block[2]);
289
+    forward_pass_kernel(block[0], block[1]);
292
   }
290
   }
293
-  forward_pass_kernel(block[1], block[2], NULL);
291
+  forward_pass_kernel(block[1], block[2]);
294
 }
292
 }
295
 
293
 
296
 /**
294
 /**

+ 2
- 2
Marlin/planner.h Ver fichero

320
 
320
 
321
     static void calculate_trapezoid_for_block(block_t* block, float entry_factor, float exit_factor);
321
     static void calculate_trapezoid_for_block(block_t* block, float entry_factor, float exit_factor);
322
 
322
 
323
-    static void reverse_pass_kernel(block_t* previous, block_t* current, block_t* next);
324
-    static void forward_pass_kernel(block_t* previous, block_t* current, block_t* next);
323
+    static void reverse_pass_kernel(block_t* current, block_t* next);
324
+    static void forward_pass_kernel(block_t* previous, block_t* current);
325
 
325
 
326
     static void reverse_pass();
326
     static void reverse_pass();
327
     static void forward_pass();
327
     static void forward_pass();

+ 71
- 31
Marlin/stepper.cpp Ver fichero

87
       Stepper::counter_Z = 0,
87
       Stepper::counter_Z = 0,
88
       Stepper::counter_E = 0;
88
       Stepper::counter_E = 0;
89
 
89
 
90
-volatile unsigned long Stepper::step_events_completed = 0; // The number of step events executed in the current block
90
+volatile uint32_t Stepper::step_events_completed = 0; // The number of step events executed in the current block
91
 
91
 
92
 #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
92
 #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
93
 
93
 
372
     ) endstops.update();
372
     ) endstops.update();
373
 
373
 
374
     // Take multiple steps per interrupt (For high speed moves)
374
     // Take multiple steps per interrupt (For high speed moves)
375
+    bool all_steps_done = false;
375
     for (int8_t i = 0; i < step_loops; i++) {
376
     for (int8_t i = 0; i < step_loops; i++) {
376
       #ifndef USBCON
377
       #ifndef USBCON
377
         customizedSerial.checkRx(); // Check for serial chars.
378
         customizedSerial.checkRx(); // Check for serial chars.
385
           #if DISABLED(MIXING_EXTRUDER)
386
           #if DISABLED(MIXING_EXTRUDER)
386
             // Don't step E here for mixing extruder
387
             // Don't step E here for mixing extruder
387
             count_position[E_AXIS] += count_direction[E_AXIS];
388
             count_position[E_AXIS] += count_direction[E_AXIS];
388
-            e_steps[TOOL_E_INDEX] += motor_direction(E_AXIS) ? -1 : 1;
389
+            motor_direction(E_AXIS) ? --e_steps[TOOL_E_INDEX] : ++e_steps[TOOL_E_INDEX];
389
           #endif
390
           #endif
390
         }
391
         }
391
 
392
 
449
       #define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP
450
       #define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP
450
       #define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN
451
       #define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN
451
 
452
 
453
+      // Advance the Bresenham counter; start a pulse if the axis needs a step
452
       #define PULSE_START(AXIS) \
454
       #define PULSE_START(AXIS) \
453
         _COUNTER(AXIS) += current_block->steps[_AXIS(AXIS)]; \
455
         _COUNTER(AXIS) += current_block->steps[_AXIS(AXIS)]; \
454
         if (_COUNTER(AXIS) > 0) { _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS),0); }
456
         if (_COUNTER(AXIS) > 0) { _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS),0); }
455
 
457
 
458
+      // Stop an active pulse, reset the Bresenham counter, update the position
456
       #define PULSE_STOP(AXIS) \
459
       #define PULSE_STOP(AXIS) \
457
         if (_COUNTER(AXIS) > 0) { \
460
         if (_COUNTER(AXIS) > 0) { \
458
           _COUNTER(AXIS) -= current_block->step_event_count; \
461
           _COUNTER(AXIS) -= current_block->step_event_count; \
460
           _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \
463
           _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \
461
         }
464
         }
462
 
465
 
466
+      // If a minimum pulse time was specified get the CPU clock
463
       #if MINIMUM_STEPPER_PULSE > 0
467
       #if MINIMUM_STEPPER_PULSE > 0
464
         static uint32_t pulse_start;
468
         static uint32_t pulse_start;
465
         pulse_start = TCNT0;
469
         pulse_start = TCNT0;
475
         PULSE_START(Z);
479
         PULSE_START(Z);
476
       #endif
480
       #endif
477
 
481
 
482
+      // For non-advance use linear interpolation for E also
478
       #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
483
       #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
479
         #if ENABLED(MIXING_EXTRUDER)
484
         #if ENABLED(MIXING_EXTRUDER)
480
           // Keep updating the single E axis
485
           // Keep updating the single E axis
491
         #endif
496
         #endif
492
       #endif // !ADVANCE && !LIN_ADVANCE
497
       #endif // !ADVANCE && !LIN_ADVANCE
493
 
498
 
499
+      // For a minimum pulse time wait before stopping pulses
494
       #if MINIMUM_STEPPER_PULSE > 0
500
       #if MINIMUM_STEPPER_PULSE > 0
495
         #define CYCLES_EATEN_BY_CODE 10
501
         #define CYCLES_EATEN_BY_CODE 10
496
         while ((uint32_t)(TCNT0 - pulse_start) < (MINIMUM_STEPPER_PULSE * (F_CPU / 1000000UL)) - CYCLES_EATEN_BY_CODE) { /* nada */ }
502
         while ((uint32_t)(TCNT0 - pulse_start) < (MINIMUM_STEPPER_PULSE * (F_CPU / 1000000UL)) - CYCLES_EATEN_BY_CODE) { /* nada */ }
524
         #endif
530
         #endif
525
       #endif // !ADVANCE && !LIN_ADVANCE
531
       #endif // !ADVANCE && !LIN_ADVANCE
526
 
532
 
527
-      step_events_completed++;
528
-      if (step_events_completed >= current_block->step_event_count) break;
533
+      if (++step_events_completed >= current_block->step_event_count) {
534
+        all_steps_done = true;
535
+        break;
536
+      }
529
     }
537
     }
530
 
538
 
531
     #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
539
     #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
532
-      // If we have esteps to execute, fire the next ISR "now"
540
+      // If we have esteps to execute, fire the next advance_isr "now"
533
       if (e_steps[TOOL_E_INDEX]) OCR0A = TCNT0 + 2;
541
       if (e_steps[TOOL_E_INDEX]) OCR0A = TCNT0 + 2;
534
     #endif
542
     #endif
535
 
543
 
536
     // Calculate new timer value
544
     // Calculate new timer value
537
-    unsigned short timer, step_rate;
538
-    if (step_events_completed <= (unsigned long)current_block->accelerate_until) {
545
+    uint16_t timer, step_rate;
546
+    if (step_events_completed <= (uint32_t)current_block->accelerate_until) {
539
 
547
 
540
       MultiU24X32toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
548
       MultiU24X32toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
541
       acc_step_rate += current_block->initial_rate;
549
       acc_step_rate += current_block->initial_rate;
551
       #if ENABLED(LIN_ADVANCE)
559
       #if ENABLED(LIN_ADVANCE)
552
 
560
 
553
         if (current_block->use_advance_lead)
561
         if (current_block->use_advance_lead)
554
-          current_estep_rate[TOOL_E_INDEX] = ((unsigned long)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
562
+          current_estep_rate[TOOL_E_INDEX] = ((uint32_t)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
555
 
563
 
556
         if (current_block->use_advance_lead) {
564
         if (current_block->use_advance_lead) {
557
           #if ENABLED(MIXING_EXTRUDER)
565
           #if ENABLED(MIXING_EXTRUDER)
558
             MIXING_STEPPERS_LOOP(j)
566
             MIXING_STEPPERS_LOOP(j)
559
-              current_estep_rate[j] = ((unsigned long)acc_step_rate * current_block->e_speed_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 8;
567
+              current_estep_rate[j] = ((uint32_t)acc_step_rate * current_block->e_speed_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 8;
560
           #else
568
           #else
561
-            current_estep_rate[TOOL_E_INDEX] = ((unsigned long)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
569
+            current_estep_rate[TOOL_E_INDEX] = ((uint32_t)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
562
           #endif
570
           #endif
563
         }
571
         }
564
 
572
 
588
         eISR_Rate = (timer >> 2) * step_loops / abs(e_steps[TOOL_E_INDEX]);
596
         eISR_Rate = (timer >> 2) * step_loops / abs(e_steps[TOOL_E_INDEX]);
589
       #endif
597
       #endif
590
     }
598
     }
591
-    else if (step_events_completed > (unsigned long)current_block->decelerate_after) {
599
+    else if (step_events_completed > (uint32_t)current_block->decelerate_after) {
592
       MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate);
600
       MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate);
593
 
601
 
594
-      if (step_rate <= acc_step_rate) { // Still decelerating?
602
+      if (step_rate < acc_step_rate) { // Still decelerating?
595
         step_rate = acc_step_rate - step_rate;
603
         step_rate = acc_step_rate - step_rate;
596
         NOLESS(step_rate, current_block->final_rate);
604
         NOLESS(step_rate, current_block->final_rate);
597
       }
605
       }
608
         if (current_block->use_advance_lead) {
616
         if (current_block->use_advance_lead) {
609
           #if ENABLED(MIXING_EXTRUDER)
617
           #if ENABLED(MIXING_EXTRUDER)
610
             MIXING_STEPPERS_LOOP(j)
618
             MIXING_STEPPERS_LOOP(j)
611
-              current_estep_rate[j] = ((unsigned long)step_rate * current_block->e_speed_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 8;
619
+              current_estep_rate[j] = ((uint32_t)step_rate * current_block->e_speed_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 8;
612
           #else
620
           #else
613
-            current_estep_rate[TOOL_E_INDEX] = ((unsigned long)step_rate * current_block->e_speed_multiplier8) >> 8;
621
+            current_estep_rate[TOOL_E_INDEX] = ((uint32_t)step_rate * current_block->e_speed_multiplier8) >> 8;
614
           #endif
622
           #endif
615
         }
623
         }
616
 
624
 
654
       step_loops = step_loops_nominal;
662
       step_loops = step_loops_nominal;
655
     }
663
     }
656
 
664
 
657
-    OCR1A = (OCR1A < (TCNT1 + 16)) ? (TCNT1 + 16) : OCR1A;
665
+    NOLESS(OCR1A, TCNT1 + 16);
658
 
666
 
659
     // If current block is finished, reset pointer
667
     // If current block is finished, reset pointer
660
-    if (step_events_completed >= current_block->step_event_count) {
668
+    if (all_steps_done) {
661
       current_block = NULL;
669
       current_block = NULL;
662
       planner.discard_current_block();
670
       planner.discard_current_block();
663
     }
671
     }
675
     old_OCR0A += eISR_Rate;
683
     old_OCR0A += eISR_Rate;
676
     OCR0A = old_OCR0A;
684
     OCR0A = old_OCR0A;
677
 
685
 
678
-    #define STEP_E_ONCE(INDEX) \
679
-      if (e_steps[INDEX] != 0) { \
680
-        E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN); \
681
-        if (e_steps[INDEX] < 0) { \
682
-          E## INDEX ##_DIR_WRITE(INVERT_E## INDEX ##_DIR); \
683
-          e_steps[INDEX]++; \
684
-        } \
685
-        else { \
686
-          E## INDEX ##_DIR_WRITE(!INVERT_E## INDEX ##_DIR); \
687
-          e_steps[INDEX]--; \
688
-        } \
686
+    #define SET_E_STEP_DIR(INDEX) \
687
+      E## INDEX ##_DIR_WRITE(e_steps[INDEX] <= 0 ? INVERT_E## INDEX ##_DIR : !INVERT_E## INDEX ##_DIR)
688
+
689
+    #define START_E_PULSE(INDEX) \
690
+      if (e_steps[INDEX]) E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN)
691
+
692
+    #define STOP_E_PULSE(INDEX) \
693
+      if (e_steps[INDEX]) { \
694
+        e_steps[INDEX] < 0 ? ++e_steps[INDEX] : --e_steps[INDEX]; \
689
         E## INDEX ##_STEP_WRITE(!INVERT_E_STEP_PIN); \
695
         E## INDEX ##_STEP_WRITE(!INVERT_E_STEP_PIN); \
690
       }
696
       }
691
 
697
 
698
+    SET_E_STEP_DIR(0);
699
+    #if E_STEPPERS > 1
700
+      SET_E_STEP_DIR(1);
701
+      #if E_STEPPERS > 2
702
+        SET_E_STEP_DIR(2);
703
+        #if E_STEPPERS > 3
704
+          SET_E_STEP_DIR(3);
705
+        #endif
706
+      #endif
707
+    #endif
708
+
692
     // Step all E steppers that have steps
709
     // Step all E steppers that have steps
693
     for (uint8_t i = 0; i < step_loops; i++) {
710
     for (uint8_t i = 0; i < step_loops; i++) {
694
-      STEP_E_ONCE(0);
711
+
712
+      #if MINIMUM_STEPPER_PULSE > 0
713
+        static uint32_t pulse_start;
714
+        pulse_start = TCNT0;
715
+      #endif
716
+
717
+      START_E_PULSE(0);
718
+      #if E_STEPPERS > 1
719
+        START_E_PULSE(1);
720
+        #if E_STEPPERS > 2
721
+          START_E_PULSE(2);
722
+          #if E_STEPPERS > 3
723
+            START_E_PULSE(3);
724
+          #endif
725
+        #endif
726
+      #endif
727
+
728
+      // For a minimum pulse time wait before stopping pulses
729
+      #if MINIMUM_STEPPER_PULSE > 0
730
+        #define CYCLES_EATEN_BY_E 10
731
+        while ((uint32_t)(TCNT0 - pulse_start) < (MINIMUM_STEPPER_PULSE * (F_CPU / 1000000UL)) - CYCLES_EATEN_BY_E) { /* nada */ }
732
+      #endif
733
+
734
+      STOP_E_PULSE(0);
695
       #if E_STEPPERS > 1
735
       #if E_STEPPERS > 1
696
-        STEP_E_ONCE(1);
736
+        STOP_E_PULSE(1);
697
         #if E_STEPPERS > 2
737
         #if E_STEPPERS > 2
698
-          STEP_E_ONCE(2);
738
+          STOP_E_PULSE(2);
699
           #if E_STEPPERS > 3
739
           #if E_STEPPERS > 3
700
-            STEP_E_ONCE(3);
740
+            STOP_E_PULSE(3);
701
           #endif
741
           #endif
702
         #endif
742
         #endif
703
       #endif
743
       #endif

+ 1
- 1
Marlin/stepper.h Ver fichero

102
 
102
 
103
     // Counter variables for the Bresenham line tracer
103
     // Counter variables for the Bresenham line tracer
104
     static long counter_X, counter_Y, counter_Z, counter_E;
104
     static long counter_X, counter_Y, counter_Z, counter_E;
105
-    static volatile unsigned long step_events_completed; // The number of step events executed in the current block
105
+    static volatile uint32_t step_events_completed; // The number of step events executed in the current block
106
 
106
 
107
     #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
107
     #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
108
       static unsigned char old_OCR0A;
108
       static unsigned char old_OCR0A;

Loading…
Cancelar
Guardar