|
|
@ -103,6 +103,10 @@
|
|
|
|
#include <SPI.h>
|
|
|
|
#include <SPI.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
|
|
|
|
#include "../feature/mixing.h"
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
Stepper stepper; // Singleton
|
|
|
|
Stepper stepper; // Singleton
|
|
|
|
|
|
|
|
|
|
|
|
// public:
|
|
|
|
// public:
|
|
|
@ -158,12 +162,10 @@ uint32_t Stepper::advance_dividend[XYZE] = { 0 },
|
|
|
|
Stepper::decelerate_after, // The point from where we need to start decelerating
|
|
|
|
Stepper::decelerate_after, // The point from where we need to start decelerating
|
|
|
|
Stepper::step_event_count; // The total event count for the current block
|
|
|
|
Stepper::step_event_count; // The total event count for the current block
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
#if EXTRUDERS > 1 || ENABLED(MIXING_EXTRUDER)
|
|
|
|
int32_t Stepper::delta_error_m[MIXING_STEPPERS];
|
|
|
|
uint8_t Stepper::stepper_extruder;
|
|
|
|
uint32_t Stepper::advance_dividend_m[MIXING_STEPPERS],
|
|
|
|
#else
|
|
|
|
Stepper::advance_divisor_m;
|
|
|
|
constexpr uint8_t Stepper::stepper_extruder;
|
|
|
|
#elif EXTRUDERS > 1
|
|
|
|
|
|
|
|
uint8_t Stepper::active_extruder; // Active extruder
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(S_CURVE_ACCELERATION)
|
|
|
|
#if ENABLED(S_CURVE_ACCELERATION)
|
|
|
@ -301,7 +303,7 @@ int8_t Stepper::count_direction[NUM_AXIS] = { 0, 0, 0, 0 };
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if DISABLED(MIXING_EXTRUDER)
|
|
|
|
#if DISABLED(MIXING_EXTRUDER)
|
|
|
|
#define E_APPLY_STEP(v,Q) E_STEP_WRITE(active_extruder, v)
|
|
|
|
#define E_APPLY_STEP(v,Q) E_STEP_WRITE(stepper_extruder, v)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
void Stepper::wake_up() {
|
|
|
|
void Stepper::wake_up() {
|
|
|
@ -340,21 +342,23 @@ void Stepper::set_directions() {
|
|
|
|
|
|
|
|
|
|
|
|
#if DISABLED(LIN_ADVANCE)
|
|
|
|
#if DISABLED(LIN_ADVANCE)
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
|
|
|
|
// Because this is valid for the whole block we don't know
|
|
|
|
|
|
|
|
// what e-steppers will step. Likely all. Set all.
|
|
|
|
if (motor_direction(E_AXIS)) {
|
|
|
|
if (motor_direction(E_AXIS)) {
|
|
|
|
MIXING_STEPPERS_LOOP(j) REV_E_DIR(j);
|
|
|
|
MIXER_STEPPER_LOOP(j) REV_E_DIR(j);
|
|
|
|
count_direction[E_AXIS] = -1;
|
|
|
|
count_direction[E_AXIS] = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
MIXING_STEPPERS_LOOP(j) NORM_E_DIR(j);
|
|
|
|
MIXER_STEPPER_LOOP(j) NORM_E_DIR(j);
|
|
|
|
count_direction[E_AXIS] = 1;
|
|
|
|
count_direction[E_AXIS] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
if (motor_direction(E_AXIS)) {
|
|
|
|
if (motor_direction(E_AXIS)) {
|
|
|
|
REV_E_DIR(active_extruder);
|
|
|
|
REV_E_DIR(stepper_extruder);
|
|
|
|
count_direction[E_AXIS] = -1;
|
|
|
|
count_direction[E_AXIS] = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
NORM_E_DIR(active_extruder);
|
|
|
|
NORM_E_DIR(stepper_extruder);
|
|
|
|
count_direction[E_AXIS] = 1;
|
|
|
|
count_direction[E_AXIS] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
@ -1387,39 +1391,27 @@ void Stepper::stepper_pulse_phase_isr() {
|
|
|
|
PULSE_START(Z);
|
|
|
|
PULSE_START(Z);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Pulse E/Mixing extruders
|
|
|
|
// Pulse Extruders
|
|
|
|
#if ENABLED(LIN_ADVANCE)
|
|
|
|
|
|
|
|
// Tick the E axis, correct error term and update position
|
|
|
|
// Tick the E axis, correct error term and update position
|
|
|
|
|
|
|
|
#if ENABLED(LIN_ADVANCE) || ENABLED(MIXING_EXTRUDER)
|
|
|
|
delta_error[E_AXIS] += advance_dividend[E_AXIS];
|
|
|
|
delta_error[E_AXIS] += advance_dividend[E_AXIS];
|
|
|
|
if (delta_error[E_AXIS] >= 0) {
|
|
|
|
if (delta_error[E_AXIS] >= 0) {
|
|
|
|
count_position[E_AXIS] += count_direction[E_AXIS];
|
|
|
|
count_position[E_AXIS] += count_direction[E_AXIS];
|
|
|
|
|
|
|
|
#if ENABLED(LIN_ADVANCE)
|
|
|
|
delta_error[E_AXIS] -= advance_divisor;
|
|
|
|
delta_error[E_AXIS] -= advance_divisor;
|
|
|
|
|
|
|
|
|
|
|
|
// Don't step E here - But remember the number of steps to perform
|
|
|
|
// Don't step E here - But remember the number of steps to perform
|
|
|
|
motor_direction(E_AXIS) ? --LA_steps : ++LA_steps;
|
|
|
|
motor_direction(E_AXIS) ? --LA_steps : ++LA_steps;
|
|
|
|
|
|
|
|
#else // !LIN_ADVANCE && MIXING_EXTRUDER
|
|
|
|
|
|
|
|
// Don't adjust delta_error[E_AXIS] here!
|
|
|
|
|
|
|
|
// Being positive is the criteria for ending the pulse.
|
|
|
|
|
|
|
|
E_STEP_WRITE(mixer.get_next_stepper(), !INVERT_E_STEP_PIN);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else // !LIN_ADVANCE - use linear interpolation for E also
|
|
|
|
#else // !LIN_ADVANCE && !MIXING_EXTRUDER
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
#if HAS_E_STEP
|
|
|
|
|
|
|
|
|
|
|
|
// Tick the E axis
|
|
|
|
|
|
|
|
delta_error[E_AXIS] += advance_dividend[E_AXIS];
|
|
|
|
|
|
|
|
if (delta_error[E_AXIS] >= 0) {
|
|
|
|
|
|
|
|
count_position[E_AXIS] += count_direction[E_AXIS];
|
|
|
|
|
|
|
|
delta_error[E_AXIS] -= advance_divisor;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Tick the counters used for this mix in proper proportion
|
|
|
|
|
|
|
|
MIXING_STEPPERS_LOOP(j) {
|
|
|
|
|
|
|
|
// Step mixing steppers (proportionally)
|
|
|
|
|
|
|
|
delta_error_m[j] += advance_dividend_m[j];
|
|
|
|
|
|
|
|
// Step when the counter goes over zero
|
|
|
|
|
|
|
|
if (delta_error_m[j] >= 0) E_STEP_WRITE(j, !INVERT_E_STEP_PIN);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#else // !MIXING_EXTRUDER
|
|
|
|
|
|
|
|
PULSE_START(E);
|
|
|
|
PULSE_START(E);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif // !LIN_ADVANCE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if MINIMUM_STEPPER_PULSE
|
|
|
|
#if MINIMUM_STEPPER_PULSE
|
|
|
|
// Just wait for the requested pulse duration
|
|
|
|
// Just wait for the requested pulse duration
|
|
|
@ -1442,11 +1434,9 @@ void Stepper::stepper_pulse_phase_isr() {
|
|
|
|
|
|
|
|
|
|
|
|
#if DISABLED(LIN_ADVANCE)
|
|
|
|
#if DISABLED(LIN_ADVANCE)
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
MIXING_STEPPERS_LOOP(j) {
|
|
|
|
if (delta_error[E_AXIS] >= 0) {
|
|
|
|
if (delta_error_m[j] >= 0) {
|
|
|
|
delta_error[E_AXIS] -= advance_divisor;
|
|
|
|
delta_error_m[j] -= advance_divisor_m;
|
|
|
|
E_STEP_WRITE(mixer.get_stepper(), INVERT_E_STEP_PIN);
|
|
|
|
E_STEP_WRITE(j, INVERT_E_STEP_PIN);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else // !MIXING_EXTRUDER
|
|
|
|
#else // !MIXING_EXTRUDER
|
|
|
|
PULSE_STOP(E);
|
|
|
|
PULSE_STOP(E);
|
|
|
@ -1717,27 +1707,18 @@ uint32_t Stepper::stepper_block_phase_isr() {
|
|
|
|
decelerate_after = current_block->decelerate_after << oversampling;
|
|
|
|
decelerate_after = current_block->decelerate_after << oversampling;
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
const uint32_t e_steps = (
|
|
|
|
MIXER_STEPPER_SETUP();
|
|
|
|
#if ENABLED(LIN_ADVANCE)
|
|
|
|
|
|
|
|
current_block->steps[E_AXIS]
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
step_event_count
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
|
|
|
|
MIXING_STEPPERS_LOOP(i) {
|
|
|
|
#if EXTRUDERS > 1
|
|
|
|
delta_error_m[i] = -int32_t(e_steps);
|
|
|
|
stepper_extruder = current_block->extruder;
|
|
|
|
advance_dividend_m[i] = current_block->mix_steps[i] << 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
advance_divisor_m = e_steps << 1;
|
|
|
|
|
|
|
|
#elif EXTRUDERS > 1
|
|
|
|
|
|
|
|
active_extruder = current_block->active_extruder;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize the trapezoid generator from the current block.
|
|
|
|
// Initialize the trapezoid generator from the current block.
|
|
|
|
#if ENABLED(LIN_ADVANCE)
|
|
|
|
#if ENABLED(LIN_ADVANCE)
|
|
|
|
#if DISABLED(MIXING_EXTRUDER) && E_STEPPERS > 1
|
|
|
|
#if DISABLED(MIXING_EXTRUDER) && E_STEPPERS > 1
|
|
|
|
// If the now active extruder wasn't in use during the last move, its pressure is most likely gone.
|
|
|
|
// If the now active extruder wasn't in use during the last move, its pressure is most likely gone.
|
|
|
|
if (active_extruder != last_moved_extruder) LA_current_adv_steps = 0;
|
|
|
|
if (stepper_extruder != last_moved_extruder) LA_current_adv_steps = 0;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
if ((LA_use_advance_lead = current_block->use_advance_lead)) {
|
|
|
|
if ((LA_use_advance_lead = current_block->use_advance_lead)) {
|
|
|
@ -1752,14 +1733,14 @@ uint32_t Stepper::stepper_block_phase_isr() {
|
|
|
|
|
|
|
|
|
|
|
|
if (current_block->direction_bits != last_direction_bits
|
|
|
|
if (current_block->direction_bits != last_direction_bits
|
|
|
|
#if DISABLED(MIXING_EXTRUDER)
|
|
|
|
#if DISABLED(MIXING_EXTRUDER)
|
|
|
|
|| active_extruder != last_moved_extruder
|
|
|
|
|| stepper_extruder != last_moved_extruder
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
last_direction_bits = current_block->direction_bits;
|
|
|
|
last_direction_bits = current_block->direction_bits;
|
|
|
|
#if DISABLED(MIXING_EXTRUDER) && EXTRUDERS > 1
|
|
|
|
|
|
|
|
last_moved_extruder = active_extruder;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
set_directions();
|
|
|
|
set_directions();
|
|
|
|
|
|
|
|
#if EXTRUDERS > 1
|
|
|
|
|
|
|
|
last_moved_extruder = stepper_extruder;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// At this point, we must ensure the movement about to execute isn't
|
|
|
|
// At this point, we must ensure the movement about to execute isn't
|
|
|
@ -1827,15 +1808,17 @@ uint32_t Stepper::stepper_block_phase_isr() {
|
|
|
|
interval = LA_ADV_NEVER;
|
|
|
|
interval = LA_ADV_NEVER;
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
|
|
|
|
// We don't know which steppers will be stepped because LA loop follows,
|
|
|
|
|
|
|
|
// with potentially multiple steps. Set all.
|
|
|
|
if (LA_steps >= 0)
|
|
|
|
if (LA_steps >= 0)
|
|
|
|
MIXING_STEPPERS_LOOP(j) NORM_E_DIR(j);
|
|
|
|
MIXER_STEPPER_LOOP(j) NORM_E_DIR(j);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
MIXING_STEPPERS_LOOP(j) REV_E_DIR(j);
|
|
|
|
MIXER_STEPPER_LOOP(j) REV_E_DIR(j);
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
if (LA_steps >= 0)
|
|
|
|
if (LA_steps >= 0)
|
|
|
|
NORM_E_DIR(active_extruder);
|
|
|
|
NORM_E_DIR(stepper_extruder);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
REV_E_DIR(active_extruder);
|
|
|
|
REV_E_DIR(stepper_extruder);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Get the timer count and estimate the end of the pulse
|
|
|
|
// Get the timer count and estimate the end of the pulse
|
|
|
@ -1848,14 +1831,9 @@ uint32_t Stepper::stepper_block_phase_isr() {
|
|
|
|
|
|
|
|
|
|
|
|
// Set the STEP pulse ON
|
|
|
|
// Set the STEP pulse ON
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
MIXING_STEPPERS_LOOP(j) {
|
|
|
|
E_STEP_WRITE(mixer.get_next_stepper(), !INVERT_E_STEP_PIN);
|
|
|
|
// Step mixing steppers (proportionally)
|
|
|
|
|
|
|
|
delta_error_m[j] += advance_dividend_m[j];
|
|
|
|
|
|
|
|
// Step when the counter goes over zero
|
|
|
|
|
|
|
|
if (delta_error_m[j] >= 0) E_STEP_WRITE(j, !INVERT_E_STEP_PIN);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
E_STEP_WRITE(active_extruder, !INVERT_E_STEP_PIN);
|
|
|
|
E_STEP_WRITE(stepper_extruder, !INVERT_E_STEP_PIN);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Enforce a minimum duration for STEP pulse ON
|
|
|
|
// Enforce a minimum duration for STEP pulse ON
|
|
|
@ -1871,14 +1849,9 @@ uint32_t Stepper::stepper_block_phase_isr() {
|
|
|
|
|
|
|
|
|
|
|
|
// Set the STEP pulse OFF
|
|
|
|
// Set the STEP pulse OFF
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
MIXING_STEPPERS_LOOP(j) {
|
|
|
|
E_STEP_WRITE(mixer.get_stepper(), INVERT_E_STEP_PIN);
|
|
|
|
if (delta_error_m[j] >= 0) {
|
|
|
|
|
|
|
|
delta_error_m[j] -= advance_divisor_m;
|
|
|
|
|
|
|
|
E_STEP_WRITE(j, INVERT_E_STEP_PIN);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
E_STEP_WRITE(active_extruder, INVERT_E_STEP_PIN);
|
|
|
|
E_STEP_WRITE(stepper_extruder, INVERT_E_STEP_PIN);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// For minimum pulse time wait before looping
|
|
|
|
// For minimum pulse time wait before looping
|
|
|
@ -2106,8 +2079,6 @@ void Stepper::init() {
|
|
|
|
|
|
|
|
|
|
|
|
endstops.enable(true); // Start with endstops active. After homing they can be disabled
|
|
|
|
endstops.enable(true); // Start with endstops active. After homing they can be disabled
|
|
|
|
sei();
|
|
|
|
sei();
|
|
|
|
|
|
|
|
|
|
|
|
set_directions(); // Init directions to last_direction_bits = 0
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|