Trinamic: Split stealthChop, improve driver monitoring, etc. (#12582)
This commit is contained in:
committed by
Scott Lahteine
parent
055cb2b956
commit
50b2fbd031
@ -206,14 +206,6 @@ void forward_kinematics_DELTA(const float &z1, const float &z2, const float &z3)
|
||||
cartes[Z_AXIS] = z1 + ex[2] * Xnew + ey[2] * Ynew - ez[2] * Znew;
|
||||
}
|
||||
|
||||
#if ENABLED(SENSORLESS_HOMING)
|
||||
inline void delta_sensorless_homing(const bool on=true) {
|
||||
sensorless_homing_per_axis(A_AXIS, on);
|
||||
sensorless_homing_per_axis(B_AXIS, on);
|
||||
sensorless_homing_per_axis(C_AXIS, on);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A delta can only safely home all axes at the same time
|
||||
* This is like quick_home_xy() but for 3 towers.
|
||||
@ -229,7 +221,10 @@ void home_delta() {
|
||||
|
||||
// Disable stealthChop if used. Enable diag1 pin on driver.
|
||||
#if ENABLED(SENSORLESS_HOMING)
|
||||
delta_sensorless_homing();
|
||||
sensorless_t stealth_states { false, false, false };
|
||||
stealth_states.x = tmc_enable_stallguard(stepperX);
|
||||
stealth_states.y = tmc_enable_stallguard(stepperY);
|
||||
stealth_states.z = tmc_enable_stallguard(stepperZ);
|
||||
#endif
|
||||
|
||||
// Move all carriages together linearly until an endstop is hit.
|
||||
@ -239,7 +234,9 @@ void home_delta() {
|
||||
|
||||
// Re-enable stealthChop if used. Disable diag1 pin on driver.
|
||||
#if ENABLED(SENSORLESS_HOMING)
|
||||
delta_sensorless_homing(false);
|
||||
tmc_disable_stallguard(stepperX, stealth_states.x);
|
||||
tmc_disable_stallguard(stepperY, stealth_states.y);
|
||||
tmc_disable_stallguard(stepperZ, stealth_states.z);
|
||||
#endif
|
||||
|
||||
endstops.validate_homing_move();
|
||||
|
@ -1046,40 +1046,78 @@ inline float get_homing_bump_feedrate(const AxisEnum axis) {
|
||||
}
|
||||
|
||||
#if ENABLED(SENSORLESS_HOMING)
|
||||
|
||||
/**
|
||||
* Set sensorless homing if the axis has it, accounting for Core Kinematics.
|
||||
*/
|
||||
void sensorless_homing_per_axis(const AxisEnum axis, const bool enable/*=true*/) {
|
||||
sensorless_t start_sensorless_homing_per_axis(const AxisEnum axis) {
|
||||
sensorless_t stealth_states { false, false, false };
|
||||
|
||||
switch (axis) {
|
||||
default: break;
|
||||
#if X_SENSORLESS
|
||||
case X_AXIS:
|
||||
tmc_stallguard(stepperX, enable);
|
||||
stealth_states.x = tmc_enable_stallguard(stepperX);
|
||||
#if CORE_IS_XY && Y_SENSORLESS
|
||||
tmc_stallguard(stepperY, enable);
|
||||
stealth_states.y = tmc_enable_stallguard(stepperY);
|
||||
#elif CORE_IS_XZ && Z_SENSORLESS
|
||||
tmc_stallguard(stepperZ, enable);
|
||||
stealth_states.z = tmc_enable_stallguard(stepperZ);
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
#if Y_SENSORLESS
|
||||
case Y_AXIS:
|
||||
tmc_stallguard(stepperY, enable);
|
||||
stealth_states.y = tmc_enable_stallguard(stepperY);
|
||||
#if CORE_IS_XY && X_SENSORLESS
|
||||
tmc_stallguard(stepperX, enable);
|
||||
stealth_states.x = tmc_enable_stallguard(stepperX);
|
||||
#elif CORE_IS_YZ && Z_SENSORLESS
|
||||
tmc_stallguard(stepperZ, enable);
|
||||
stealth_states.z = tmc_enable_stallguard(stepperZ);
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
#if Z_SENSORLESS
|
||||
case Z_AXIS:
|
||||
tmc_stallguard(stepperZ, enable);
|
||||
stealth_states.z = tmc_enable_stallguard(stepperZ);
|
||||
#if CORE_IS_XZ && X_SENSORLESS
|
||||
tmc_stallguard(stepperX, enable);
|
||||
stealth_states.x = tmc_enable_stallguard(stepperX);
|
||||
#elif CORE_IS_YZ && Y_SENSORLESS
|
||||
tmc_stallguard(stepperY, enable);
|
||||
stealth_states.y = tmc_enable_stallguard(stepperY);
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
return stealth_states;
|
||||
}
|
||||
|
||||
void end_sensorless_homing_per_axis(const AxisEnum axis, sensorless_t enable_stealth) {
|
||||
switch (axis) {
|
||||
default: break;
|
||||
#if X_SENSORLESS
|
||||
case X_AXIS:
|
||||
tmc_disable_stallguard(stepperX, enable_stealth.x);
|
||||
#if CORE_IS_XY && Y_SENSORLESS
|
||||
tmc_disable_stallguard(stepperY, enable_stealth.y);
|
||||
#elif CORE_IS_XZ && Z_SENSORLESS
|
||||
tmc_disable_stallguard(stepperZ, enable_stealth.z);
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
#if Y_SENSORLESS
|
||||
case Y_AXIS:
|
||||
tmc_disable_stallguard(stepperY, enable_stealth.y);
|
||||
#if CORE_IS_XY && X_SENSORLESS
|
||||
tmc_disable_stallguard(stepperX, enable_stealth.x);
|
||||
#elif CORE_IS_YZ && Z_SENSORLESS
|
||||
tmc_disable_stallguard(stepperZ, enable_stealth.z);
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
#if Z_SENSORLESS
|
||||
case Z_AXIS:
|
||||
tmc_disable_stallguard(stepperZ, enable_stealth.z);
|
||||
#if CORE_IS_XZ && X_SENSORLESS
|
||||
tmc_disable_stallguard(stepperX, enable_stealth.x);
|
||||
#elif CORE_IS_YZ && Y_SENSORLESS
|
||||
tmc_disable_stallguard(stepperY, enable_stealth.y);
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
@ -1126,6 +1164,10 @@ void do_homing_move(const AxisEnum axis, const float distance, const float fr_mm
|
||||
home_dir(axis);
|
||||
const bool is_home_dir = (axis_home_dir > 0) == (distance > 0);
|
||||
|
||||
#if ENABLED(SENSORLESS_HOMING)
|
||||
sensorless_t stealth_states;
|
||||
#endif
|
||||
|
||||
if (is_home_dir) {
|
||||
|
||||
#if HOMING_Z_WITH_PROBE && QUIET_PROBING
|
||||
@ -1134,7 +1176,7 @@ void do_homing_move(const AxisEnum axis, const float distance, const float fr_mm
|
||||
|
||||
// Disable stealthChop if used. Enable diag1 pin on driver.
|
||||
#if ENABLED(SENSORLESS_HOMING)
|
||||
sensorless_homing_per_axis(axis);
|
||||
stealth_states = start_sensorless_homing_per_axis(axis);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1175,7 +1217,7 @@ void do_homing_move(const AxisEnum axis, const float distance, const float fr_mm
|
||||
|
||||
// Re-enable stealthChop if used. Disable diag1 pin on driver.
|
||||
#if ENABLED(SENSORLESS_HOMING)
|
||||
sensorless_homing_per_axis(axis, false);
|
||||
end_sensorless_homing_per_axis(axis, stealth_states);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -216,10 +216,6 @@ void set_axis_is_not_at_home(const AxisEnum axis);
|
||||
|
||||
void homeaxis(const AxisEnum axis);
|
||||
|
||||
#if ENABLED(SENSORLESS_HOMING)
|
||||
void sensorless_homing_per_axis(const AxisEnum axis, const bool enable=true);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Workspace offsets
|
||||
*/
|
||||
|
@ -545,11 +545,12 @@ static bool do_probe_move(const float z, const float fr_mm_s) {
|
||||
|
||||
// Disable stealthChop if used. Enable diag1 pin on driver.
|
||||
#if ENABLED(SENSORLESS_PROBING)
|
||||
sensorless_t stealth_states { false, false, false };
|
||||
#if ENABLED(DELTA)
|
||||
tmc_stallguard(stepperX);
|
||||
tmc_stallguard(stepperY);
|
||||
stealth_states.x = tmc_enable_stallguard(stepperX);
|
||||
stealth_states.y = tmc_enable_stallguard(stepperY);
|
||||
#endif
|
||||
tmc_stallguard(stepperZ);
|
||||
stealth_states.z = tmc_enable_stallguard(stepperZ);
|
||||
endstops.enable(true);
|
||||
#endif
|
||||
|
||||
@ -583,10 +584,10 @@ static bool do_probe_move(const float z, const float fr_mm_s) {
|
||||
#if ENABLED(SENSORLESS_PROBING)
|
||||
endstops.not_homing();
|
||||
#if ENABLED(DELTA)
|
||||
tmc_stallguard(stepperX, false);
|
||||
tmc_stallguard(stepperY, false);
|
||||
tmc_disable_stallguard(stepperX, stealth_states.x);
|
||||
tmc_disable_stallguard(stepperY, stealth_states.y);
|
||||
#endif
|
||||
tmc_stallguard(stepperZ, false);
|
||||
tmc_disable_stallguard(stepperZ, stealth_states.z);
|
||||
#endif
|
||||
|
||||
// Retract BLTouch immediately after a probe if it was triggered
|
||||
|
@ -140,7 +140,8 @@
|
||||
#endif // TMC26X
|
||||
|
||||
#if HAS_TRINAMIC
|
||||
#define _TMC_INIT(ST, SPMM) tmc_init(stepper##ST, ST##_CURRENT, ST##_MICROSTEPS, ST##_HYBRID_THRESHOLD, SPMM)
|
||||
enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E };
|
||||
#define _TMC_INIT(ST, SPMM_INDEX, STEALTH_INDEX) tmc_init(stepper##ST, ST##_CURRENT, ST##_MICROSTEPS, ST##_HYBRID_THRESHOLD, planner.settings.axis_steps_per_mm[SPMM_INDEX], stealthchop_by_axis[STEALTH_INDEX])
|
||||
#endif
|
||||
|
||||
//
|
||||
@ -201,11 +202,7 @@
|
||||
#endif
|
||||
|
||||
template<char AXIS_LETTER, char DRIVER_ID>
|
||||
void tmc_init(TMCMarlin<TMC2130Stepper, AXIS_LETTER, DRIVER_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const float spmm) {
|
||||
#if DISABLED(STEALTHCHOP) || DISABLED(HYBRID_THRESHOLD)
|
||||
UNUSED(thrs);
|
||||
UNUSED(spmm);
|
||||
#endif
|
||||
void tmc_init(TMCMarlin<TMC2130Stepper, AXIS_LETTER, DRIVER_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const float spmm, const bool stealth) {
|
||||
st.begin();
|
||||
|
||||
CHOPCONF_t chopconf{0};
|
||||
@ -221,20 +218,22 @@
|
||||
st.iholddelay(10);
|
||||
st.TPOWERDOWN(128); // ~2s until driver lowers to hold current
|
||||
|
||||
#if ENABLED(STEALTHCHOP)
|
||||
st.en_pwm_mode(true);
|
||||
st.en_pwm_mode(stealth);
|
||||
|
||||
PWMCONF_t pwmconf{0};
|
||||
pwmconf.pwm_freq = 0b01; // f_pwm = 2/683 f_clk
|
||||
pwmconf.pwm_autoscale = true;
|
||||
pwmconf.pwm_grad = 5;
|
||||
pwmconf.pwm_ampl = 180;
|
||||
st.PWMCONF(pwmconf.sr);
|
||||
PWMCONF_t pwmconf{0};
|
||||
pwmconf.pwm_freq = 0b01; // f_pwm = 2/683 f_clk
|
||||
pwmconf.pwm_autoscale = true;
|
||||
pwmconf.pwm_grad = 5;
|
||||
pwmconf.pwm_ampl = 180;
|
||||
st.PWMCONF(pwmconf.sr);
|
||||
|
||||
#if ENABLED(HYBRID_THRESHOLD)
|
||||
st.TPWMTHRS(12650000UL*microsteps/(256*thrs*spmm));
|
||||
#endif
|
||||
#if ENABLED(HYBRID_THRESHOLD)
|
||||
st.TPWMTHRS(12650000UL*microsteps/(256*thrs*spmm));
|
||||
#else
|
||||
UNUSED(thrs);
|
||||
UNUSED(spmm);
|
||||
#endif
|
||||
|
||||
st.GSTAT(); // Clear GSTAT
|
||||
}
|
||||
#endif // TMC2130
|
||||
@ -440,16 +439,13 @@
|
||||
}
|
||||
|
||||
template<char AXIS_LETTER, char DRIVER_ID>
|
||||
void tmc_init(TMCMarlin<TMC2208Stepper, AXIS_LETTER, DRIVER_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const float spmm) {
|
||||
#if DISABLED(STEALTHCHOP) || DISABLED(HYBRID_THRESHOLD)
|
||||
UNUSED(thrs);
|
||||
UNUSED(spmm);
|
||||
#endif
|
||||
|
||||
void tmc_init(TMCMarlin<TMC2208Stepper, AXIS_LETTER, DRIVER_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const float spmm, const bool stealth) {
|
||||
TMC2208_n::GCONF_t gconf{0};
|
||||
gconf.pdn_disable = true; // Use UART
|
||||
gconf.mstep_reg_select = true; // Select microsteps with UART
|
||||
gconf.i_scale_analog = false;
|
||||
gconf.en_spreadcycle = !stealth;
|
||||
st.GCONF(gconf.sr);
|
||||
|
||||
TMC2208_n::CHOPCONF_t chopconf{0};
|
||||
chopconf.tbl = 0b01; // blank_time = 24
|
||||
@ -463,25 +459,24 @@
|
||||
st.microsteps(microsteps);
|
||||
st.iholddelay(10);
|
||||
st.TPOWERDOWN(128); // ~2s until driver lowers to hold current
|
||||
#if ENABLED(STEALTHCHOP)
|
||||
gconf.en_spreadcycle = false;
|
||||
|
||||
TMC2208_n::PWMCONF_t pwmconf{0};
|
||||
pwmconf.pwm_lim = 12;
|
||||
pwmconf.pwm_reg = 8;
|
||||
pwmconf.pwm_autograd = true;
|
||||
pwmconf.pwm_autoscale = true;
|
||||
pwmconf.pwm_freq = 0b01;
|
||||
pwmconf.pwm_grad = 14;
|
||||
pwmconf.pwm_ofs = 36;
|
||||
st.PWMCONF(pwmconf.sr);
|
||||
#if ENABLED(HYBRID_THRESHOLD)
|
||||
st.TPWMTHRS(12650000UL*microsteps/(256*thrs*spmm));
|
||||
#endif
|
||||
TMC2208_n::PWMCONF_t pwmconf{0};
|
||||
pwmconf.pwm_lim = 12;
|
||||
pwmconf.pwm_reg = 8;
|
||||
pwmconf.pwm_autograd = true;
|
||||
pwmconf.pwm_autoscale = true;
|
||||
pwmconf.pwm_freq = 0b01;
|
||||
pwmconf.pwm_grad = 14;
|
||||
pwmconf.pwm_ofs = 36;
|
||||
st.PWMCONF(pwmconf.sr);
|
||||
|
||||
#if ENABLED(HYBRID_THRESHOLD)
|
||||
st.TPWMTHRS(12650000UL*microsteps/(256*thrs*spmm));
|
||||
#else
|
||||
gconf.en_spreadcycle = true;
|
||||
UNUSED(thrs);
|
||||
UNUSED(spmm);
|
||||
#endif
|
||||
st.GCONF(gconf.sr);
|
||||
|
||||
st.GSTAT(0b111); // Clear
|
||||
delay(200);
|
||||
}
|
||||
@ -543,7 +538,7 @@
|
||||
#endif
|
||||
|
||||
template<char AXIS_LETTER, char DRIVER_ID>
|
||||
void tmc_init(TMCMarlin<TMC2660Stepper, AXIS_LETTER, DRIVER_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t, const float) {
|
||||
void tmc_init(TMCMarlin<TMC2660Stepper, AXIS_LETTER, DRIVER_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t, const float, const bool) {
|
||||
st.begin();
|
||||
st.rms_current(mA);
|
||||
st.microsteps(microsteps);
|
||||
@ -605,44 +600,66 @@ void reset_stepper_drivers() {
|
||||
L6470_init_to_defaults();
|
||||
#endif
|
||||
|
||||
#if HAS_TRINAMIC
|
||||
static constexpr bool stealthchop_by_axis[] = {
|
||||
#if ENABLED(STEALTHCHOP_XY)
|
||||
true
|
||||
#else
|
||||
false
|
||||
#endif
|
||||
,
|
||||
#if ENABLED(STEALTHCHOP_Z)
|
||||
true
|
||||
#else
|
||||
false
|
||||
#endif
|
||||
,
|
||||
#if ENABLED(STEALTHCHOP_E)
|
||||
true
|
||||
#else
|
||||
false
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
||||
#if AXIS_IS_TMC(X)
|
||||
_TMC_INIT(X, planner.settings.axis_steps_per_mm[X_AXIS]);
|
||||
_TMC_INIT(X, X_AXIS, STEALTH_AXIS_XY);
|
||||
#endif
|
||||
#if AXIS_IS_TMC(X2)
|
||||
_TMC_INIT(X2, planner.settings.axis_steps_per_mm[X_AXIS]);
|
||||
_TMC_INIT(X2, X_AXIS, STEALTH_AXIS_XY);
|
||||
#endif
|
||||
#if AXIS_IS_TMC(Y)
|
||||
_TMC_INIT(Y, planner.settings.axis_steps_per_mm[Y_AXIS]);
|
||||
_TMC_INIT(Y, Y_AXIS, STEALTH_AXIS_XY);
|
||||
#endif
|
||||
#if AXIS_IS_TMC(Y2)
|
||||
_TMC_INIT(Y2, planner.settings.axis_steps_per_mm[Y_AXIS]);
|
||||
_TMC_INIT(Y2, Y_AXIS, STEALTH_AXIS_XY);
|
||||
#endif
|
||||
#if AXIS_IS_TMC(Z)
|
||||
_TMC_INIT(Z, planner.settings.axis_steps_per_mm[Z_AXIS]);
|
||||
_TMC_INIT(Z, Z_AXIS, STEALTH_AXIS_Z);
|
||||
#endif
|
||||
#if AXIS_IS_TMC(Z2)
|
||||
_TMC_INIT(Z2, planner.settings.axis_steps_per_mm[Z_AXIS]);
|
||||
_TMC_INIT(Z2, Z_AXIS, STEALTH_AXIS_Z);
|
||||
#endif
|
||||
#if AXIS_IS_TMC(Z3)
|
||||
_TMC_INIT(Z3, planner.settings.axis_steps_per_mm[Z_AXIS]);
|
||||
_TMC_INIT(Z3, Z_AXIS, STEALTH_AXIS_Z);
|
||||
#endif
|
||||
#if AXIS_IS_TMC(E0)
|
||||
_TMC_INIT(E0, planner.settings.axis_steps_per_mm[E_AXIS_N(0)]);
|
||||
_TMC_INIT(E0, E_AXIS, STEALTH_AXIS_E);
|
||||
#endif
|
||||
#if AXIS_IS_TMC(E1)
|
||||
_TMC_INIT(E1, planner.settings.axis_steps_per_mm[E_AXIS_N(1)]);
|
||||
_TMC_INIT(E1, E_AXIS_N(1), STEALTH_AXIS_E);
|
||||
#endif
|
||||
#if AXIS_IS_TMC(E2)
|
||||
_TMC_INIT(E2, planner.settings.axis_steps_per_mm[E_AXIS_N(2)]);
|
||||
_TMC_INIT(E2, E_AXIS_N(2), STEALTH_AXIS_E);
|
||||
#endif
|
||||
#if AXIS_IS_TMC(E3)
|
||||
_TMC_INIT(E3, planner.settings.axis_steps_per_mm[E_AXIS_N(3)]);
|
||||
_TMC_INIT(E3, E_AXIS_N(3), STEALTH_AXIS_E);
|
||||
#endif
|
||||
#if AXIS_IS_TMC(E4)
|
||||
_TMC_INIT(E4, planner.settings.axis_steps_per_mm[E_AXIS_N(4)]);
|
||||
_TMC_INIT(E4, E_AXIS_N(4), STEALTH_AXIS_E);
|
||||
#endif
|
||||
#if AXIS_IS_TMC(E5)
|
||||
_TMC_INIT(E5, planner.settings.axis_steps_per_mm[E_AXIS_N(5)]);
|
||||
_TMC_INIT(E5, E_AXIS_N(5), STEALTH_AXIS_E);
|
||||
#endif
|
||||
|
||||
#if USE_SENSORLESS
|
||||
|
Reference in New Issue
Block a user