Browse Source

Improve MINIMUM_STEPPER_PULSE

Scott Lahteine 8 years ago
parent
commit
eabff30e75
3 changed files with 16 additions and 8 deletions
  1. 3
    0
      Marlin/Conditionals_post.h
  2. 3
    0
      Marlin/macros.h
  3. 10
    8
      Marlin/stepper.cpp

+ 3
- 0
Marlin/Conditionals_post.h View File

708
     #define MAX_PROBE_Y (min(Y_MAX_POS, Y_MAX_POS + Y_PROBE_OFFSET_FROM_EXTRUDER))
708
     #define MAX_PROBE_Y (min(Y_MAX_POS, Y_MAX_POS + Y_PROBE_OFFSET_FROM_EXTRUDER))
709
   #endif
709
   #endif
710
 
710
 
711
+  // Stepper pulse duration, in cycles
712
+  #define STEP_PULSE_CYCLES ((MINIMUM_STEPPER_PULSE) * CYCLES_PER_MICROSECOND)
713
+
711
 #endif // CONDITIONALS_POST_H
714
 #endif // CONDITIONALS_POST_H

+ 3
- 0
Marlin/macros.h View File

36
   #define CRITICAL_SECTION_END    SREG = _sreg;
36
   #define CRITICAL_SECTION_END    SREG = _sreg;
37
 #endif
37
 #endif
38
 
38
 
39
+// Clock speed factor
40
+#define CYCLES_PER_MICROSECOND (F_CPU / 1000000UL) // 16 or 20
41
+
39
 // Remove compiler warning on an unused variable
42
 // Remove compiler warning on an unused variable
40
 #define UNUSED(x) (void) (x)
43
 #define UNUSED(x) (void) (x)
41
 
44
 

+ 10
- 8
Marlin/stepper.cpp View File

460
         _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \
460
         _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \
461
       }
461
       }
462
 
462
 
463
+    #define CYCLES_EATEN_BY_CODE 240
464
+
463
     // If a minimum pulse time was specified get the CPU clock
465
     // If a minimum pulse time was specified get the CPU clock
464
-    #if MINIMUM_STEPPER_PULSE > 0
466
+    #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_CODE
465
       static uint32_t pulse_start;
467
       static uint32_t pulse_start;
466
       pulse_start = TCNT0;
468
       pulse_start = TCNT0;
467
     #endif
469
     #endif
494
     #endif // !ADVANCE && !LIN_ADVANCE
496
     #endif // !ADVANCE && !LIN_ADVANCE
495
 
497
 
496
     // For a minimum pulse time wait before stopping pulses
498
     // For a minimum pulse time wait before stopping pulses
497
-    #if MINIMUM_STEPPER_PULSE > 0
498
-      #define CYCLES_EATEN_BY_CODE 10
499
-      while ((uint32_t)(TCNT0 - pulse_start) < (MINIMUM_STEPPER_PULSE * (F_CPU / 1000000UL)) - CYCLES_EATEN_BY_CODE) { /* nada */ }
499
+    #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_CODE
500
+      while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_CODE) { /* nada */ }
500
     #endif
501
     #endif
501
 
502
 
502
     #if HAS_X_STEP
503
     #if HAS_X_STEP
688
         E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN); \
689
         E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN); \
689
       }
690
       }
690
 
691
 
692
+    #define CYCLES_EATEN_BY_E 60
693
+
691
     // Step all E steppers that have steps
694
     // Step all E steppers that have steps
692
     for (uint8_t i = 0; i < step_loops; i++) {
695
     for (uint8_t i = 0; i < step_loops; i++) {
693
 
696
 
694
-      #if MINIMUM_STEPPER_PULSE > 0
697
+      #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_E
695
         static uint32_t pulse_start;
698
         static uint32_t pulse_start;
696
         pulse_start = TCNT0;
699
         pulse_start = TCNT0;
697
       #endif
700
       #endif
708
       #endif
711
       #endif
709
 
712
 
710
       // For a minimum pulse time wait before stopping pulses
713
       // For a minimum pulse time wait before stopping pulses
711
-      #if MINIMUM_STEPPER_PULSE > 0
712
-        #define CYCLES_EATEN_BY_E 10
713
-        while ((uint32_t)(TCNT0 - pulse_start) < (MINIMUM_STEPPER_PULSE * (F_CPU / 1000000UL)) - CYCLES_EATEN_BY_E) { /* nada */ }
714
+      #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_E
715
+        while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_E) { /* nada */ }
714
       #endif
716
       #endif
715
 
717
 
716
       STOP_E_PULSE(0);
718
       STOP_E_PULSE(0);

Loading…
Cancel
Save