Merge pull request #4887 from thinkyhead/rc_autumn_fixups

Improve MINIMUM_STEPPER_PULSE
This commit is contained in:
Scott Lahteine 2016-09-24 03:23:42 -05:00 committed by GitHub
commit 6cf0952bf9
3 changed files with 16 additions and 8 deletions

View File

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

View File

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

View File

@ -460,8 +460,10 @@ void Stepper::isr() {
_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 MINIMUM_STEPPER_PULSE > 0
#if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_CODE
static uint32_t pulse_start;
pulse_start = TCNT0;
#endif
@ -494,9 +496,8 @@ void Stepper::isr() {
#endif // !ADVANCE && !LIN_ADVANCE
// For a minimum pulse time wait before stopping pulses
#if MINIMUM_STEPPER_PULSE > 0
#define CYCLES_EATEN_BY_CODE 10
while ((uint32_t)(TCNT0 - pulse_start) < (MINIMUM_STEPPER_PULSE * (F_CPU / 1000000UL)) - CYCLES_EATEN_BY_CODE) { /* nada */ }
#if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_CODE
while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_CODE) { /* nada */ }
#endif
#if HAS_X_STEP
@ -688,10 +689,12 @@ void Stepper::isr() {
E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN); \
}
#define CYCLES_EATEN_BY_E 60
// Step all E steppers that have steps
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;
pulse_start = TCNT0;
#endif
@ -708,9 +711,8 @@ void Stepper::isr() {
#endif
// For a minimum pulse time wait before stopping pulses
#if MINIMUM_STEPPER_PULSE > 0
#define CYCLES_EATEN_BY_E 10
while ((uint32_t)(TCNT0 - pulse_start) < (MINIMUM_STEPPER_PULSE * (F_CPU / 1000000UL)) - CYCLES_EATEN_BY_E) { /* nada */ }
#if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_E
while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_E) { /* nada */ }
#endif
STOP_E_PULSE(0);