Put more code between pulse start and stop (#9956)
This commit is contained in:
parent
70e9c07b2d
commit
3bae28a5e1
@ -482,48 +482,24 @@ void Stepper::isr() {
|
|||||||
// Take multiple steps per interrupt (For high speed moves)
|
// Take multiple steps per interrupt (For high speed moves)
|
||||||
bool all_steps_done = false;
|
bool all_steps_done = false;
|
||||||
for (uint8_t i = step_loops; i--;) {
|
for (uint8_t i = step_loops; i--;) {
|
||||||
#if ENABLED(LIN_ADVANCE)
|
|
||||||
|
|
||||||
counter_E += current_block->steps[E_AXIS];
|
|
||||||
if (counter_E > 0) {
|
|
||||||
counter_E -= current_block->step_event_count;
|
|
||||||
#if DISABLED(MIXING_EXTRUDER)
|
|
||||||
// Don't step E here for mixing extruder
|
|
||||||
count_position[E_AXIS] += count_direction[E_AXIS];
|
|
||||||
motor_direction(E_AXIS) ? --e_steps : ++e_steps;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#if ENABLED(MIXING_EXTRUDER)
|
|
||||||
// Step mixing steppers proportionally
|
|
||||||
const bool dir = motor_direction(E_AXIS);
|
|
||||||
MIXING_STEPPERS_LOOP(j) {
|
|
||||||
counter_m[j] += current_block->steps[E_AXIS];
|
|
||||||
if (counter_m[j] > 0) {
|
|
||||||
counter_m[j] -= current_block->mix_event_count[j];
|
|
||||||
dir ? --e_steps[j] : ++e_steps[j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // LIN_ADVANCE
|
|
||||||
|
|
||||||
#define _COUNTER(AXIS) counter_## AXIS
|
#define _COUNTER(AXIS) counter_## AXIS
|
||||||
#define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP
|
#define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP
|
||||||
#define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN
|
#define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN
|
||||||
|
|
||||||
// Advance the Bresenham counter; start a pulse if the axis needs a step
|
// Advance the Bresenham counter; start a pulse if the axis needs a step
|
||||||
#define PULSE_START(AXIS) \
|
#define PULSE_START(AXIS) do{ \
|
||||||
_COUNTER(AXIS) += current_block->steps[_AXIS(AXIS)]; \
|
_COUNTER(AXIS) += current_block->steps[_AXIS(AXIS)]; \
|
||||||
if (_COUNTER(AXIS) > 0) { _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS),0); }
|
if (_COUNTER(AXIS) > 0) _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS), 0); }while(0)
|
||||||
|
|
||||||
// Stop an active pulse, reset the Bresenham counter, update the position
|
// Advance the Bresenham counter; start a pulse if the axis needs a step
|
||||||
#define PULSE_STOP(AXIS) \
|
#define STEP_TICK(AXIS) \
|
||||||
if (_COUNTER(AXIS) > 0) { \
|
if (_COUNTER(AXIS) > 0) { \
|
||||||
_COUNTER(AXIS) -= current_block->step_event_count; \
|
_COUNTER(AXIS) -= current_block->step_event_count; \
|
||||||
count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \
|
count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; }
|
||||||
_APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \
|
|
||||||
}
|
// Stop an active pulse, if any
|
||||||
|
#define PULSE_STOP(AXIS) _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS), 0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Estimate the number of cycles that the stepper logic already takes
|
* Estimate the number of cycles that the stepper logic already takes
|
||||||
@ -583,7 +559,7 @@ void Stepper::isr() {
|
|||||||
/**
|
/**
|
||||||
* If a minimum pulse time was specified get the timer 0 value.
|
* If a minimum pulse time was specified get the timer 0 value.
|
||||||
*
|
*
|
||||||
* TCNT0 has an 8x prescaler, so it increments every 8 cycles.
|
* On AVR the TCNT0 timer has an 8x prescaler, so it increments every 8 cycles.
|
||||||
* That's every 0.5µs on 16MHz and every 0.4µs on 20MHz.
|
* That's every 0.5µs on 16MHz and every 0.4µs on 20MHz.
|
||||||
* 20 counts of TCNT0 -by itself- is a good pulse delay.
|
* 20 counts of TCNT0 -by itself- is a good pulse delay.
|
||||||
* 10µs = 160 or 200 cycles.
|
* 10µs = 160 or 200 cycles.
|
||||||
@ -602,8 +578,30 @@ void Stepper::isr() {
|
|||||||
PULSE_START(Z);
|
PULSE_START(Z);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// For non-advance use linear interpolation for E also
|
#if ENABLED(LIN_ADVANCE)
|
||||||
#if DISABLED(LIN_ADVANCE)
|
|
||||||
|
counter_E += current_block->steps[E_AXIS];
|
||||||
|
if (counter_E > 0) {
|
||||||
|
#if DISABLED(MIXING_EXTRUDER)
|
||||||
|
// Don't step E here for mixing extruder
|
||||||
|
motor_direction(E_AXIS) ? --e_steps : ++e_steps;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if ENABLED(MIXING_EXTRUDER)
|
||||||
|
// Step mixing steppers proportionally
|
||||||
|
const bool dir = motor_direction(E_AXIS);
|
||||||
|
MIXING_STEPPERS_LOOP(j) {
|
||||||
|
counter_m[j] += current_block->steps[E_AXIS];
|
||||||
|
if (counter_m[j] > 0) {
|
||||||
|
counter_m[j] -= current_block->mix_event_count[j];
|
||||||
|
dir ? --e_steps[j] : ++e_steps[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#else // !LIN_ADVANCE - use linear interpolation for E also
|
||||||
|
|
||||||
#if ENABLED(MIXING_EXTRUDER)
|
#if ENABLED(MIXING_EXTRUDER)
|
||||||
// Keep updating the single E axis
|
// Keep updating the single E axis
|
||||||
counter_E += current_block->steps[E_AXIS];
|
counter_E += current_block->steps[E_AXIS];
|
||||||
@ -619,6 +617,18 @@ void Stepper::isr() {
|
|||||||
#endif
|
#endif
|
||||||
#endif // !LIN_ADVANCE
|
#endif // !LIN_ADVANCE
|
||||||
|
|
||||||
|
#if HAS_X_STEP
|
||||||
|
STEP_TICK(X);
|
||||||
|
#endif
|
||||||
|
#if HAS_Y_STEP
|
||||||
|
STEP_TICK(Y);
|
||||||
|
#endif
|
||||||
|
#if HAS_Z_STEP
|
||||||
|
STEP_TICK(Z);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
STEP_TICK(E); // Always tick the single E axis
|
||||||
|
|
||||||
// For minimum pulse time wait before stopping pulses
|
// For minimum pulse time wait before stopping pulses
|
||||||
#if EXTRA_CYCLES_XYZE > 20
|
#if EXTRA_CYCLES_XYZE > 20
|
||||||
while (EXTRA_CYCLES_XYZE > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
|
while (EXTRA_CYCLES_XYZE > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
|
||||||
@ -639,11 +649,6 @@ void Stepper::isr() {
|
|||||||
|
|
||||||
#if DISABLED(LIN_ADVANCE)
|
#if DISABLED(LIN_ADVANCE)
|
||||||
#if ENABLED(MIXING_EXTRUDER)
|
#if ENABLED(MIXING_EXTRUDER)
|
||||||
// Always step the single E axis
|
|
||||||
if (counter_E > 0) {
|
|
||||||
counter_E -= current_block->step_event_count;
|
|
||||||
count_position[E_AXIS] += count_direction[E_AXIS];
|
|
||||||
}
|
|
||||||
MIXING_STEPPERS_LOOP(j) {
|
MIXING_STEPPERS_LOOP(j) {
|
||||||
if (counter_m[j] > 0) {
|
if (counter_m[j] > 0) {
|
||||||
counter_m[j] -= current_block->mix_event_count[j];
|
counter_m[j] -= current_block->mix_event_count[j];
|
||||||
@ -1234,7 +1239,7 @@ void Stepper::quick_stop() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stepper::endstop_triggered(AxisEnum axis) {
|
void Stepper::endstop_triggered(const AxisEnum axis) {
|
||||||
|
|
||||||
#if IS_CORE
|
#if IS_CORE
|
||||||
|
|
||||||
@ -1319,6 +1324,7 @@ void Stepper::report_positions() {
|
|||||||
_ENABLE(AXIS); \
|
_ENABLE(AXIS); \
|
||||||
_SAVE_START; \
|
_SAVE_START; \
|
||||||
_APPLY_DIR(AXIS, _INVERT_DIR(AXIS)^direction^INVERT); \
|
_APPLY_DIR(AXIS, _INVERT_DIR(AXIS)^direction^INVERT); \
|
||||||
|
_PULSE_WAIT; \
|
||||||
_APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS), true); \
|
_APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS), true); \
|
||||||
_PULSE_WAIT; \
|
_PULSE_WAIT; \
|
||||||
_APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS), true); \
|
_APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS), true); \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user