|
|
@ -87,7 +87,7 @@ long Stepper::counter_X = 0,
|
|
|
|
Stepper::counter_Z = 0,
|
|
|
|
Stepper::counter_Z = 0,
|
|
|
|
Stepper::counter_E = 0;
|
|
|
|
Stepper::counter_E = 0;
|
|
|
|
|
|
|
|
|
|
|
|
volatile unsigned long Stepper::step_events_completed = 0; // The number of step events executed in the current block
|
|
|
|
volatile uint32_t Stepper::step_events_completed = 0; // The number of step events executed in the current block
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
|
|
|
|
#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
|
|
|
|
|
|
|
|
|
|
|
@ -372,6 +372,7 @@ void Stepper::isr() {
|
|
|
|
) endstops.update();
|
|
|
|
) endstops.update();
|
|
|
|
|
|
|
|
|
|
|
|
// Take multiple steps per interrupt (For high speed moves)
|
|
|
|
// Take multiple steps per interrupt (For high speed moves)
|
|
|
|
|
|
|
|
bool all_steps_done = false;
|
|
|
|
for (int8_t i = 0; i < step_loops; i++) {
|
|
|
|
for (int8_t i = 0; i < step_loops; i++) {
|
|
|
|
#ifndef USBCON
|
|
|
|
#ifndef USBCON
|
|
|
|
customizedSerial.checkRx(); // Check for serial chars.
|
|
|
|
customizedSerial.checkRx(); // Check for serial chars.
|
|
|
@ -385,7 +386,7 @@ void Stepper::isr() {
|
|
|
|
#if DISABLED(MIXING_EXTRUDER)
|
|
|
|
#if DISABLED(MIXING_EXTRUDER)
|
|
|
|
// Don't step E here for mixing extruder
|
|
|
|
// Don't step E here for mixing extruder
|
|
|
|
count_position[E_AXIS] += count_direction[E_AXIS];
|
|
|
|
count_position[E_AXIS] += count_direction[E_AXIS];
|
|
|
|
e_steps[TOOL_E_INDEX] += motor_direction(E_AXIS) ? -1 : 1;
|
|
|
|
motor_direction(E_AXIS) ? --e_steps[TOOL_E_INDEX] : ++e_steps[TOOL_E_INDEX];
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -449,10 +450,12 @@ void Stepper::isr() {
|
|
|
|
#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
|
|
|
|
#define PULSE_START(AXIS) \
|
|
|
|
#define PULSE_START(AXIS) \
|
|
|
|
_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); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Stop an active pulse, reset the Bresenham counter, update the position
|
|
|
|
#define PULSE_STOP(AXIS) \
|
|
|
|
#define PULSE_STOP(AXIS) \
|
|
|
|
if (_COUNTER(AXIS) > 0) { \
|
|
|
|
if (_COUNTER(AXIS) > 0) { \
|
|
|
|
_COUNTER(AXIS) -= current_block->step_event_count; \
|
|
|
|
_COUNTER(AXIS) -= current_block->step_event_count; \
|
|
|
@ -460,6 +463,7 @@ void Stepper::isr() {
|
|
|
|
_APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \
|
|
|
|
_APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If a minimum pulse time was specified get the CPU clock
|
|
|
|
#if MINIMUM_STEPPER_PULSE > 0
|
|
|
|
#if MINIMUM_STEPPER_PULSE > 0
|
|
|
|
static uint32_t pulse_start;
|
|
|
|
static uint32_t pulse_start;
|
|
|
|
pulse_start = TCNT0;
|
|
|
|
pulse_start = TCNT0;
|
|
|
@ -475,6 +479,7 @@ void Stepper::isr() {
|
|
|
|
PULSE_START(Z);
|
|
|
|
PULSE_START(Z);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// For non-advance use linear interpolation for E also
|
|
|
|
#if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
|
|
|
|
#if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
// Keep updating the single E axis
|
|
|
|
// Keep updating the single E axis
|
|
|
@ -491,6 +496,7 @@ void Stepper::isr() {
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif // !ADVANCE && !LIN_ADVANCE
|
|
|
|
#endif // !ADVANCE && !LIN_ADVANCE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// For a minimum pulse time wait before stopping pulses
|
|
|
|
#if MINIMUM_STEPPER_PULSE > 0
|
|
|
|
#if MINIMUM_STEPPER_PULSE > 0
|
|
|
|
#define CYCLES_EATEN_BY_CODE 10
|
|
|
|
#define CYCLES_EATEN_BY_CODE 10
|
|
|
|
while ((uint32_t)(TCNT0 - pulse_start) < (MINIMUM_STEPPER_PULSE * (F_CPU / 1000000UL)) - CYCLES_EATEN_BY_CODE) { /* nada */ }
|
|
|
|
while ((uint32_t)(TCNT0 - pulse_start) < (MINIMUM_STEPPER_PULSE * (F_CPU / 1000000UL)) - CYCLES_EATEN_BY_CODE) { /* nada */ }
|
|
|
@ -524,18 +530,20 @@ void Stepper::isr() {
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif // !ADVANCE && !LIN_ADVANCE
|
|
|
|
#endif // !ADVANCE && !LIN_ADVANCE
|
|
|
|
|
|
|
|
|
|
|
|
step_events_completed++;
|
|
|
|
if (++step_events_completed >= current_block->step_event_count) {
|
|
|
|
if (step_events_completed >= current_block->step_event_count) break;
|
|
|
|
all_steps_done = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
|
|
|
|
#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
|
|
|
|
// If we have esteps to execute, fire the next ISR "now"
|
|
|
|
// If we have esteps to execute, fire the next advance_isr "now"
|
|
|
|
if (e_steps[TOOL_E_INDEX]) OCR0A = TCNT0 + 2;
|
|
|
|
if (e_steps[TOOL_E_INDEX]) OCR0A = TCNT0 + 2;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Calculate new timer value
|
|
|
|
// Calculate new timer value
|
|
|
|
unsigned short timer, step_rate;
|
|
|
|
uint16_t timer, step_rate;
|
|
|
|
if (step_events_completed <= (unsigned long)current_block->accelerate_until) {
|
|
|
|
if (step_events_completed <= (uint32_t)current_block->accelerate_until) {
|
|
|
|
|
|
|
|
|
|
|
|
MultiU24X32toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
|
|
|
|
MultiU24X32toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
|
|
|
|
acc_step_rate += current_block->initial_rate;
|
|
|
|
acc_step_rate += current_block->initial_rate;
|
|
|
@ -551,14 +559,14 @@ void Stepper::isr() {
|
|
|
|
#if ENABLED(LIN_ADVANCE)
|
|
|
|
#if ENABLED(LIN_ADVANCE)
|
|
|
|
|
|
|
|
|
|
|
|
if (current_block->use_advance_lead)
|
|
|
|
if (current_block->use_advance_lead)
|
|
|
|
current_estep_rate[TOOL_E_INDEX] = ((unsigned long)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
|
|
|
|
current_estep_rate[TOOL_E_INDEX] = ((uint32_t)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
|
|
|
|
|
|
|
|
|
|
|
|
if (current_block->use_advance_lead) {
|
|
|
|
if (current_block->use_advance_lead) {
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
MIXING_STEPPERS_LOOP(j)
|
|
|
|
MIXING_STEPPERS_LOOP(j)
|
|
|
|
current_estep_rate[j] = ((unsigned long)acc_step_rate * current_block->e_speed_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 8;
|
|
|
|
current_estep_rate[j] = ((uint32_t)acc_step_rate * current_block->e_speed_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 8;
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
current_estep_rate[TOOL_E_INDEX] = ((unsigned long)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
|
|
|
|
current_estep_rate[TOOL_E_INDEX] = ((uint32_t)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -588,10 +596,10 @@ void Stepper::isr() {
|
|
|
|
eISR_Rate = (timer >> 2) * step_loops / abs(e_steps[TOOL_E_INDEX]);
|
|
|
|
eISR_Rate = (timer >> 2) * step_loops / abs(e_steps[TOOL_E_INDEX]);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (step_events_completed > (unsigned long)current_block->decelerate_after) {
|
|
|
|
else if (step_events_completed > (uint32_t)current_block->decelerate_after) {
|
|
|
|
MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate);
|
|
|
|
MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate);
|
|
|
|
|
|
|
|
|
|
|
|
if (step_rate <= acc_step_rate) { // Still decelerating?
|
|
|
|
if (step_rate < acc_step_rate) { // Still decelerating?
|
|
|
|
step_rate = acc_step_rate - step_rate;
|
|
|
|
step_rate = acc_step_rate - step_rate;
|
|
|
|
NOLESS(step_rate, current_block->final_rate);
|
|
|
|
NOLESS(step_rate, current_block->final_rate);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -608,9 +616,9 @@ void Stepper::isr() {
|
|
|
|
if (current_block->use_advance_lead) {
|
|
|
|
if (current_block->use_advance_lead) {
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
MIXING_STEPPERS_LOOP(j)
|
|
|
|
MIXING_STEPPERS_LOOP(j)
|
|
|
|
current_estep_rate[j] = ((unsigned long)step_rate * current_block->e_speed_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 8;
|
|
|
|
current_estep_rate[j] = ((uint32_t)step_rate * current_block->e_speed_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 8;
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
current_estep_rate[TOOL_E_INDEX] = ((unsigned long)step_rate * current_block->e_speed_multiplier8) >> 8;
|
|
|
|
current_estep_rate[TOOL_E_INDEX] = ((uint32_t)step_rate * current_block->e_speed_multiplier8) >> 8;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -654,10 +662,10 @@ void Stepper::isr() {
|
|
|
|
step_loops = step_loops_nominal;
|
|
|
|
step_loops = step_loops_nominal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OCR1A = (OCR1A < (TCNT1 + 16)) ? (TCNT1 + 16) : OCR1A;
|
|
|
|
NOLESS(OCR1A, TCNT1 + 16);
|
|
|
|
|
|
|
|
|
|
|
|
// If current block is finished, reset pointer
|
|
|
|
// If current block is finished, reset pointer
|
|
|
|
if (step_events_completed >= current_block->step_event_count) {
|
|
|
|
if (all_steps_done) {
|
|
|
|
current_block = NULL;
|
|
|
|
current_block = NULL;
|
|
|
|
planner.discard_current_block();
|
|
|
|
planner.discard_current_block();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -675,29 +683,61 @@ void Stepper::isr() {
|
|
|
|
old_OCR0A += eISR_Rate;
|
|
|
|
old_OCR0A += eISR_Rate;
|
|
|
|
OCR0A = old_OCR0A;
|
|
|
|
OCR0A = old_OCR0A;
|
|
|
|
|
|
|
|
|
|
|
|
#define STEP_E_ONCE(INDEX) \
|
|
|
|
#define SET_E_STEP_DIR(INDEX) \
|
|
|
|
if (e_steps[INDEX] != 0) { \
|
|
|
|
E## INDEX ##_DIR_WRITE(e_steps[INDEX] <= 0 ? INVERT_E## INDEX ##_DIR : !INVERT_E## INDEX ##_DIR)
|
|
|
|
E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN); \
|
|
|
|
|
|
|
|
if (e_steps[INDEX] < 0) { \
|
|
|
|
#define START_E_PULSE(INDEX) \
|
|
|
|
E## INDEX ##_DIR_WRITE(INVERT_E## INDEX ##_DIR); \
|
|
|
|
if (e_steps[INDEX]) E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN)
|
|
|
|
e_steps[INDEX]++; \
|
|
|
|
|
|
|
|
} \
|
|
|
|
#define STOP_E_PULSE(INDEX) \
|
|
|
|
else { \
|
|
|
|
if (e_steps[INDEX]) { \
|
|
|
|
E## INDEX ##_DIR_WRITE(!INVERT_E## INDEX ##_DIR); \
|
|
|
|
e_steps[INDEX] < 0 ? ++e_steps[INDEX] : --e_steps[INDEX]; \
|
|
|
|
e_steps[INDEX]--; \
|
|
|
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
E## INDEX ##_STEP_WRITE(!INVERT_E_STEP_PIN); \
|
|
|
|
E## INDEX ##_STEP_WRITE(!INVERT_E_STEP_PIN); \
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SET_E_STEP_DIR(0);
|
|
|
|
|
|
|
|
#if E_STEPPERS > 1
|
|
|
|
|
|
|
|
SET_E_STEP_DIR(1);
|
|
|
|
|
|
|
|
#if E_STEPPERS > 2
|
|
|
|
|
|
|
|
SET_E_STEP_DIR(2);
|
|
|
|
|
|
|
|
#if E_STEPPERS > 3
|
|
|
|
|
|
|
|
SET_E_STEP_DIR(3);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// 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++) {
|
|
|
|
STEP_E_ONCE(0);
|
|
|
|
|
|
|
|
|
|
|
|
#if MINIMUM_STEPPER_PULSE > 0
|
|
|
|
|
|
|
|
static uint32_t pulse_start;
|
|
|
|
|
|
|
|
pulse_start = TCNT0;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
START_E_PULSE(0);
|
|
|
|
#if E_STEPPERS > 1
|
|
|
|
#if E_STEPPERS > 1
|
|
|
|
STEP_E_ONCE(1);
|
|
|
|
START_E_PULSE(1);
|
|
|
|
#if E_STEPPERS > 2
|
|
|
|
#if E_STEPPERS > 2
|
|
|
|
STEP_E_ONCE(2);
|
|
|
|
START_E_PULSE(2);
|
|
|
|
#if E_STEPPERS > 3
|
|
|
|
#if E_STEPPERS > 3
|
|
|
|
STEP_E_ONCE(3);
|
|
|
|
START_E_PULSE(3);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#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 */ }
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
STOP_E_PULSE(0);
|
|
|
|
|
|
|
|
#if E_STEPPERS > 1
|
|
|
|
|
|
|
|
STOP_E_PULSE(1);
|
|
|
|
|
|
|
|
#if E_STEPPERS > 2
|
|
|
|
|
|
|
|
STOP_E_PULSE(2);
|
|
|
|
|
|
|
|
#if E_STEPPERS > 3
|
|
|
|
|
|
|
|
STOP_E_PULSE(3);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|