Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Marlin/src/feature/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ void Power::check() {
void Power::power_on() {
lastPowerOn = millis();
PSU_PIN_ON();

#if HAS_TRINAMIC
delay(100); // Wait for power to settle
restore_stepper_drivers();
#endif
}

void Power::power_off() {
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/feature/tmc_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt) {
}
}
#endif

#if ENABLED(HAVE_TMC2208)
static void tmc_status(TMC2208Stepper &st, const TMC_debug_enum i) {
switch (i) {
Expand Down
5 changes: 1 addition & 4 deletions Marlin/src/feature/tmc_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

extern bool report_tmc_status;

enum TMC_AxisEnum : char { TMC_X, TMC_X2, TMC_Y, TMC_Y2, TMC_Z, TMC_Z2, TMC_E0, TMC_E1, TMC_E2, TMC_E3, TMC_E4 };
enum TMC_AxisEnum : char { TMC_X, TMC_Y, TMC_Z, TMC_X2, TMC_Y2, TMC_Z2, TMC_E0, TMC_E1, TMC_E2, TMC_E3, TMC_E4 };

constexpr uint32_t _tmc_thrs(const uint16_t msteps, const int32_t thrs, const uint32_t spmm) {
return 12650000UL * msteps / (256 * thrs * spmm);
Expand All @@ -55,7 +55,6 @@ void tmc_get_current(TMC &st, const TMC_AxisEnum axis) {
template<typename TMC>
void tmc_set_current(TMC &st, const TMC_AxisEnum axis, const int mA) {
st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER);
tmc_get_current(st, axis);
}
template<typename TMC>
void tmc_report_otpw(TMC &st, const TMC_AxisEnum axis) {
Expand All @@ -73,7 +72,6 @@ void tmc_get_pwmthrs(TMC &st, const TMC_AxisEnum axis, const uint16_t spmm) {
template<typename TMC>
void tmc_set_pwmthrs(TMC &st, const TMC_AxisEnum axis, const int32_t thrs, const uint32_t spmm) {
st.TPWMTHRS(_tmc_thrs(st.microsteps(), thrs, spmm));
tmc_get_pwmthrs(st, axis, spmm);
}
template<typename TMC>
void tmc_get_sgt(TMC &st, const TMC_AxisEnum axis) {
Expand All @@ -82,7 +80,6 @@ void tmc_get_sgt(TMC &st, const TMC_AxisEnum axis) {
template<typename TMC>
void tmc_set_sgt(TMC &st, const TMC_AxisEnum axis, const int8_t sgt_val) {
st.sgt(sgt_val);
tmc_get_sgt(st, axis);
}

void monitor_tmc_driver();
Expand Down
11 changes: 3 additions & 8 deletions Marlin/src/gcode/control/M80_M81.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,9 @@
OUT_WRITE(SUICIDE_PIN, HIGH);
#endif

#if ENABLED(HAVE_TMC2130)
delay(100);
tmc2130_init(); // Settings only stick when the driver has power
#endif

#if ENABLED(HAVE_TMC2208)
delay(100);
tmc2208_init();
#if DISABLED(AUTO_POWER_CONTROL)
delay(100); // Wait for power to settle
restore_stepper_drivers();
#endif

#if ENABLED(ULTIPANEL)
Expand Down
134 changes: 96 additions & 38 deletions Marlin/src/gcode/feature/trinamic/M906.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,46 +33,104 @@
* Report driver currents when no axis specified
*/
void GcodeSuite::M906() {
uint16_t values[XYZE];
LOOP_XYZE(i) values[i] = parser.intval(axis_codes[i]);
#define TMC_SAY_CURRENT(Q) tmc_get_current(stepper##Q, TMC_##Q)
#define TMC_SET_CURRENT(Q) tmc_set_current(stepper##Q, TMC_##Q, value)

#define TMC_SET_GET_CURRENT(P,Q) do { \
if (values[P##_AXIS]) tmc_set_current(stepper##Q, TMC_##Q, values[P##_AXIS]); \
else tmc_get_current(stepper##Q, TMC_##Q); } while(0)
bool report = true;
const uint8_t index = parser.byteval('I');
LOOP_XYZE(i) if (uint16_t value = parser.intval(axis_codes[i])) {
report = false;
switch (i) {
case X_AXIS:
#if X_IS_TRINAMIC
if (index == 0) TMC_SET_CURRENT(X);
#endif
#if X2_IS_TRINAMIC
if (index == 1) TMC_SET_CURRENT(X2);
#endif
break;
case Y_AXIS:
#if Y_IS_TRINAMIC
if (index == 0) TMC_SET_CURRENT(Y);
#endif
#if Y2_IS_TRINAMIC
if (index == 1) TMC_SET_CURRENT(Y2);
#endif
break;
case Z_AXIS:
#if Z_IS_TRINAMIC
if (index == 0) TMC_SET_CURRENT(Z);
#endif
#if Z2_IS_TRINAMIC
if (index == 1) TMC_SET_CURRENT(Z2);
#endif
break;
case E_AXIS: {
if (get_target_extruder_from_command()) return;
switch (target_extruder) {
#if E0_IS_TRINAMIC
case 0: TMC_SET_CURRENT(E0); break;
#endif
#if E1_IS_TRINAMIC
case 1: TMC_SET_CURRENT(E1); break;
#endif
#if E2_IS_TRINAMIC
case 2: TMC_SET_CURRENT(E2); break;
#endif
#if E3_IS_TRINAMIC
case 3: TMC_SET_CURRENT(E3); break;
#endif
#if E4_IS_TRINAMIC
case 4: TMC_SET_CURRENT(E4); break;
#endif
}
} break;
}
}

#if X_IS_TRINAMIC
TMC_SET_GET_CURRENT(X,X);
#endif
#if X2_IS_TRINAMIC
TMC_SET_GET_CURRENT(X,X2);
#endif
#if Y_IS_TRINAMIC
TMC_SET_GET_CURRENT(Y,Y);
#endif
#if Y2_IS_TRINAMIC
TMC_SET_GET_CURRENT(Y,Y2);
#endif
#if Z_IS_TRINAMIC
TMC_SET_GET_CURRENT(Z,Z);
#endif
#if Z2_IS_TRINAMIC
TMC_SET_GET_CURRENT(Z,Z2);
#endif
#if E0_IS_TRINAMIC
TMC_SET_GET_CURRENT(E,E0);
#endif
#if E1_IS_TRINAMIC
TMC_SET_GET_CURRENT(E,E1);
#endif
#if E2_IS_TRINAMIC
TMC_SET_GET_CURRENT(E,E2);
#endif
#if E3_IS_TRINAMIC
TMC_SET_GET_CURRENT(E,E3);
#endif
#if E4_IS_TRINAMIC
TMC_SET_GET_CURRENT(E,E4);
#endif
if (report) LOOP_XYZE(i) switch (i) {
case X_AXIS:
#if X_IS_TRINAMIC
TMC_SAY_CURRENT(X);
#endif
#if X2_IS_TRINAMIC
TMC_SAY_CURRENT(X2);
#endif
break;
case Y_AXIS:
#if Y_IS_TRINAMIC
TMC_SAY_CURRENT(Y);
#endif
#if Y2_IS_TRINAMIC
TMC_SAY_CURRENT(Y2);
#endif
break;
case Z_AXIS:
#if Z_IS_TRINAMIC
TMC_SAY_CURRENT(Z);
#endif
#if Z2_IS_TRINAMIC
TMC_SAY_CURRENT(Z2);
#endif
break;
case E_AXIS:
#if E0_IS_TRINAMIC
TMC_SAY_CURRENT(E0);
#endif
#if E1_IS_TRINAMIC
TMC_SAY_CURRENT(E1);
#endif
#if E2_IS_TRINAMIC
TMC_SAY_CURRENT(E2);
#endif
#if E3_IS_TRINAMIC
TMC_SAY_CURRENT(E3);
#endif
#if E4_IS_TRINAMIC
TMC_SAY_CURRENT(E4);
#endif
break;
}
}

#endif // HAS_TRINAMIC
Loading