Improve MINIMUM_STEPPER_PULSE

master
Scott Lahteine 8 years ago
parent da1644313d
commit eabff30e75

@ -708,4 +708,7 @@
#define MAX_PROBE_Y (min(Y_MAX_POS, Y_MAX_POS + Y_PROBE_OFFSET_FROM_EXTRUDER)) #define MAX_PROBE_Y (min(Y_MAX_POS, Y_MAX_POS + Y_PROBE_OFFSET_FROM_EXTRUDER))
#endif #endif
// Stepper pulse duration, in cycles
#define STEP_PULSE_CYCLES ((MINIMUM_STEPPER_PULSE) * CYCLES_PER_MICROSECOND)
#endif // CONDITIONALS_POST_H #endif // CONDITIONALS_POST_H

@ -36,6 +36,9 @@
#define CRITICAL_SECTION_END SREG = _sreg; #define CRITICAL_SECTION_END SREG = _sreg;
#endif #endif
// Clock speed factor
#define CYCLES_PER_MICROSECOND (F_CPU / 1000000UL) // 16 or 20
// Remove compiler warning on an unused variable // Remove compiler warning on an unused variable
#define UNUSED(x) (void) (x) #define UNUSED(x) (void) (x)

@ -460,8 +460,10 @@ void Stepper::isr() {
_APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \ _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \
} }
#define CYCLES_EATEN_BY_CODE 240
// If a minimum pulse time was specified get the CPU clock // If a minimum pulse time was specified get the CPU clock
#if MINIMUM_STEPPER_PULSE > 0 #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_CODE
static uint32_t pulse_start; static uint32_t pulse_start;
pulse_start = TCNT0; pulse_start = TCNT0;
#endif #endif
@ -494,9 +496,8 @@ void Stepper::isr() {
#endif // !ADVANCE && !LIN_ADVANCE #endif // !ADVANCE && !LIN_ADVANCE
// For a minimum pulse time wait before stopping pulses // For a minimum pulse time wait before stopping pulses
#if MINIMUM_STEPPER_PULSE > 0 #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_CODE
#define CYCLES_EATEN_BY_CODE 10 while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_CODE) { /* nada */ }
while ((uint32_t)(TCNT0 - pulse_start) < (MINIMUM_STEPPER_PULSE * (F_CPU / 1000000UL)) - CYCLES_EATEN_BY_CODE) { /* nada */ }
#endif #endif
#if HAS_X_STEP #if HAS_X_STEP
@ -688,10 +689,12 @@ void Stepper::isr() {
E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN); \ E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN); \
} }
#define CYCLES_EATEN_BY_E 60
// Step all E steppers that have steps // Step all E steppers that have steps
for (uint8_t i = 0; i < step_loops; i++) { for (uint8_t i = 0; i < step_loops; i++) {
#if MINIMUM_STEPPER_PULSE > 0 #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_E
static uint32_t pulse_start; static uint32_t pulse_start;
pulse_start = TCNT0; pulse_start = TCNT0;
#endif #endif
@ -708,9 +711,8 @@ void Stepper::isr() {
#endif #endif
// For a minimum pulse time wait before stopping pulses // For a minimum pulse time wait before stopping pulses
#if MINIMUM_STEPPER_PULSE > 0 #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_E
#define CYCLES_EATEN_BY_E 10 while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_E) { /* nada */ }
while ((uint32_t)(TCNT0 - pulse_start) < (MINIMUM_STEPPER_PULSE * (F_CPU / 1000000UL)) - CYCLES_EATEN_BY_E) { /* nada */ }
#endif #endif
STOP_E_PULSE(0); STOP_E_PULSE(0);

Loading…
Cancel
Save