Put more code between pulse start and stop (#9959)

This commit is contained in:
Scott Lahteine 2018-03-05 23:06:57 -06:00 committed by GitHub
parent f9cafc4001
commit 0dd1c4458d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -443,48 +443,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
@ -563,8 +539,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];
@ -580,6 +578,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)(HAL_timer_get_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ } while (EXTRA_CYCLES_XYZE > (uint32_t)(HAL_timer_get_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
@ -600,11 +610,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];
@ -686,6 +691,7 @@ void Stepper::isr() {
SPLIT(interval); // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL SPLIT(interval); // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL
_NEXT_ISR(ocr_val); _NEXT_ISR(ocr_val);
deceleration_time += interval; deceleration_time += interval;
#if ENABLED(LIN_ADVANCE) #if ENABLED(LIN_ADVANCE)
@ -714,6 +720,7 @@ void Stepper::isr() {
SPLIT(OCR1A_nominal); // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL SPLIT(OCR1A_nominal); // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL
_NEXT_ISR(ocr_val); _NEXT_ISR(ocr_val);
// ensure we're running at the correct step rate, even if we just came off an acceleration // ensure we're running at the correct step rate, even if we just came off an acceleration
step_loops = step_loops_nominal; step_loops = step_loops_nominal;
} }