Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M919 - Get or Set Trinamic Chopper Times #23333

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
489d838
add M9999
magnificu Dec 21, 2021
1bda6e5
M9999 code clean up
magnificu Dec 21, 2021
3712c61
M9999 code clean up
magnificu Dec 22, 2021
1dd1874
Merge branch 'MarlinFirmware:bugfix-2.0.x' into bugfix-2.0.x
magnificu Dec 22, 2021
9b2fdfd
extend functionality for TMC 2208, 2209, 2660
magnificu Dec 22, 2021
c3a67e2
Merge branch 'bugfix-2.0.x' of https://github.com/magnificu/Marlin in…
magnificu Dec 22, 2021
8a5c5ef
use M919 gcode instead of M9999
magnificu Dec 22, 2021
3ae201f
Merge branch 'MarlinFirmware:bugfix-2.0.x' into bugfix-2.0.x
magnificu Dec 23, 2021
4b4b400
corrections
thinkyhead Dec 23, 2021
b8f34a9
add src filter
thinkyhead Dec 23, 2021
68294d1
inline hints
thinkyhead Dec 23, 2021
f8b962b
Merge branch 'MarlinFirmware:bugfix-2.0.x' into bugfix-2.0.x
magnificu Dec 23, 2021
35519cc
fix typo
thinkyhead Dec 24, 2021
c8f7c55
Merge branch 'MarlinFirmware:bugfix-2.0.x' into bugfix-2.0.x
magnificu Dec 24, 2021
d47cfbf
V before S as in Configuration_adv.h
magnificu Dec 24, 2021
bf9a57d
Merge branch 'MarlinFirmware:bugfix-2.0.x' into bugfix-2.0.x
magnificu Dec 26, 2021
8e73d80
Merge branch 'MarlinFirmware:bugfix-2.0.x' into bugfix-2.0.x
magnificu Dec 27, 2021
52b50a9
Simplify M919
thinkyhead Dec 28, 2021
f6e76fb
simplify set_chopper_times
thinkyhead Dec 28, 2021
bb63e79
Relocate tmc functions
thinkyhead Dec 28, 2021
4312459
V => P
thinkyhead Dec 28, 2021
4058373
Alter 'I' and 'T' behavior
thinkyhead Dec 28, 2021
cef37bc
ibid.
thinkyhead Dec 28, 2021
01b4d0b
UVW => ...
thinkyhead Dec 28, 2021
874fd76
Merge 'bugfix-2.0.x' into pr/23333
thinkyhead Dec 28, 2021
3ea3d0d
sp
thinkyhead Dec 28, 2021
9e19312
alert on collision
thinkyhead Dec 28, 2021
e067096
Merge 'bugfix-2.0.x' into pr/23333
thinkyhead Dec 28, 2021
0054b38
Merge branch 'MarlinFirmware:bugfix-2.0.x' into bugfix-2.0.x
magnificu Dec 29, 2021
3ecb85b
separate default axis chopper_times
magnificu Dec 29, 2021
8578655
correct default chopper index behaviour
magnificu Dec 29, 2021
56b7991
Revert "correct default chopper index behaviour"
magnificu Dec 29, 2021
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
65 changes: 55 additions & 10 deletions Marlin/src/feature/tmc_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,20 @@ class TMCMarlin : public TMC, public TMCStorage<AXIS_LETTER, DRIVER_ID> {
inline bool toggle_stepping_mode() { set_stealthChop(!this->stored.stealthChop_enabled); return get_stealthChop(); }
#endif

inline void set_chopper_times(uint8_t time_off, int8_t hysteresis_end, uint8_t hysteresis_start) {
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
this->toff(time_off);
this->hysteresis_end(hysteresis_end);
this->hysteresis_start(hysteresis_start);
TMC::toff(time_off);
TMC::hysteresis_end(hysteresis_end);
TMC::hysteresis_start(hysteresis_start);
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
}

#if ENABLED(HYBRID_THRESHOLD)
uint32_t get_pwm_thrs() {
inline uint32_t get_pwm_thrs() {
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
return _tmc_thrs(this->microsteps(), this->TPWMTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]);
}
void set_pwm_thrs(const uint32_t thrs) {
inline void set_pwm_thrs(const uint32_t thrs) {
TMC::TPWMTHRS(_tmc_thrs(this->microsteps(), thrs, planner.settings.axis_steps_per_mm[AXIS_ID]));
TERN_(HAS_LCD_MENU, this->stored.hybrid_thrs = thrs);
}
Expand Down Expand Up @@ -160,7 +169,7 @@ class TMCMarlin<TMC2208Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> : public TMC220
TMC2208Stepper(RX, TX, RS)
{}

uint16_t rms_current() { return TMC2208Stepper::rms_current(); }
inline uint16_t rms_current() { return TMC2208Stepper::rms_current(); }
inline void rms_current(const uint16_t mA) {
this->val_mA = mA;
TMC2208Stepper::rms_current(mA);
Expand All @@ -179,11 +188,20 @@ class TMCMarlin<TMC2208Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> : public TMC220
inline bool toggle_stepping_mode() { set_stealthChop(!this->stored.stealthChop_enabled); return get_stealthChop(); }
#endif

inline void set_chopper_times(uint8_t time_off, int8_t hysteresis_end, uint8_t hysteresis_start) {
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
this->toff(time_off);
this->hysteresis_end(hysteresis_end);
this->hysteresis_start(hysteresis_start);
TMC2208Stepper::toff(time_off);
TMC2208Stepper::hysteresis_end(hysteresis_end);
TMC2208Stepper::hysteresis_start(hysteresis_start);
}

#if ENABLED(HYBRID_THRESHOLD)
uint32_t get_pwm_thrs() {
inline uint32_t get_pwm_thrs() {
return _tmc_thrs(this->microsteps(), this->TPWMTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]);
}
void set_pwm_thrs(const uint32_t thrs) {
inline void set_pwm_thrs(const uint32_t thrs) {
TMC2208Stepper::TPWMTHRS(_tmc_thrs(this->microsteps(), thrs, planner.settings.axis_steps_per_mm[AXIS_ID]));
TERN_(HAS_LCD_MENU, this->stored.hybrid_thrs = thrs);
}
Expand All @@ -207,8 +225,8 @@ class TMCMarlin<TMC2209Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> : public TMC220
TMCMarlin(const uint16_t RX, const uint16_t TX, const float RS, const uint8_t addr) :
TMC2209Stepper(RX, TX, RS, addr)
{}
uint8_t get_address() { return slave_address; }
uint16_t rms_current() { return TMC2209Stepper::rms_current(); }
inline uint8_t get_address() { return slave_address; }
inline uint16_t rms_current() { return TMC2209Stepper::rms_current(); }
inline void rms_current(const uint16_t mA) {
this->val_mA = mA;
TMC2209Stepper::rms_current(mA);
Expand All @@ -227,11 +245,20 @@ class TMCMarlin<TMC2209Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> : public TMC220
inline bool toggle_stepping_mode() { set_stealthChop(!this->stored.stealthChop_enabled); return get_stealthChop(); }
#endif

inline void set_chopper_times(uint8_t time_off, int8_t hysteresis_end, uint8_t hysteresis_start) {
this->toff(time_off);
this->hysteresis_end(hysteresis_end);
this->hysteresis_start(hysteresis_start);
TMC2209Stepper::toff(time_off);
TMC2209Stepper::hysteresis_end(hysteresis_end);
TMC2209Stepper::hysteresis_start(hysteresis_start);
}

#if ENABLED(HYBRID_THRESHOLD)
uint32_t get_pwm_thrs() {
inline uint32_t get_pwm_thrs() {
return _tmc_thrs(this->microsteps(), this->TPWMTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]);
}
void set_pwm_thrs(const uint32_t thrs) {
inline void set_pwm_thrs(const uint32_t thrs) {
TMC2209Stepper::TPWMTHRS(_tmc_thrs(this->microsteps(), thrs, planner.settings.axis_steps_per_mm[AXIS_ID]));
TERN_(HAS_LCD_MENU, this->stored.hybrid_thrs = thrs);
}
Expand Down Expand Up @@ -276,9 +303,18 @@ class TMCMarlin<TMC2660Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> : public TMC266
}
inline uint16_t get_microstep_counter() { return TMC2660Stepper::mstep(); }

inline void set_chopper_times(uint8_t time_off, int8_t hysteresis_end, uint8_t hysteresis_start) {
this->toff(time_off);
this->hysteresis_end(hysteresis_end);
this->hysteresis_start(hysteresis_start);
TMC2660Stepper::toff(time_off);
TMC2660Stepper::hysteresis_end(hysteresis_end);
TMC2660Stepper::hysteresis_start(hysteresis_start);
}

#if USE_SENSORLESS
inline int16_t homing_threshold() { return TMC2660Stepper::sgt(); }
void homing_threshold(int16_t sgt_val) {
inline void homing_threshold(int16_t sgt_val) {
sgt_val = (int16_t)constrain(sgt_val, sgt_min, sgt_max);
TMC2660Stepper::sgt(sgt_val);
TERN_(HAS_LCD_MENU, this->stored.homing_thrs = sgt_val);
Expand All @@ -303,6 +339,15 @@ void tmc_print_current(TMC &st) {
SERIAL_ECHOLNPGM(" driver current: ", st.getMilliamps());
}

template<typename TMC>
void tmc_print_chopper_time(TMC &st) {
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
st.printLabel();
SERIAL_EOL();
SERIAL_ECHOLNPGM(" chopper time_off : ", st.toff());
SERIAL_ECHOLNPGM(" chopper hysteresis_end : ", st.hysteresis_end());
SERIAL_ECHOLNPGM(" chopper hysteresis_start: ", st.hysteresis_start());
}

#if ENABLED(MONITOR_DRIVER_STATUS)
template<typename TMC>
void tmc_report_otpw(TMC &st) {
Expand Down
257 changes: 257 additions & 0 deletions Marlin/src/gcode/feature/trinamic/M919.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

#include "../../../inc/MarlinConfig.h"

#if HAS_TRINAMIC_CONFIG

#include "../../gcode.h"
#include "../../../feature/tmc_util.h"
#include "../../../module/stepper/indirection.h"

#define DEBUG_OUT ENABLED(MARLIN_DEV_MODE)
#include "../../../core/debug_out.h"

/**
* M919: Set TMC stepper drive chopper times
*
* Parameters:
* XYZIJKE...
* I[index] - Axis sub-index (Omit or 0 for X, Y, Z, E0; 1 for X2, Y2, Z2, E1; 2 for Z3, E2; 3 for Z4, E3; 4 for E4; 5 for E5; 6 for E6; 7 for E7)
* T[index] - Extruder index (Zero-based. Omit for E0 only.)
* O - time-off [ 1..15]
* V - hysteresis_end [-3..12]
* S - hysteresis_start [ 1...8]
*
* With no parameters report chopper times for all axis
*/

void GcodeSuite::M919() {
#define TMC_SAY_CHOPPER_TIME(Q) tmc_print_chopper_time(stepper##Q)
#define TMC_SET_CHOPPER_TIME(Q) stepper##Q.set_chopper_times(time_off, hysteresis_end, hysteresis_start)
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved

bool report = true;
uint8_t time_off;
uint8_t hysteresis_start;
int8_t hysteresis_end;
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved

#if AXIS_IS_TMC(X) || AXIS_IS_TMC(X2) || AXIS_IS_TMC(Y) || AXIS_IS_TMC(Y2) || AXIS_IS_TMC(Z) || AXIS_IS_TMC(Z2) || AXIS_IS_TMC(Z3) || AXIS_IS_TMC(Z4)
const uint8_t index = parser.byteval('I');
#endif

static constexpr chopper_timing_t chopper_timing = CHOPPER_TIMING;
time_off = chopper_timing.toff;
hysteresis_end = chopper_timing.hend;
hysteresis_start = chopper_timing.hstrt;
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved

LOOP_LOGICAL_AXES(i) if (parser.seen_test(axis_codes[i])) {
report = false;

if (parser.seenval('O')) {
const uint8_t v = parser.value_byte();
if (WITHIN(v, 1, 15)) {
time_off = v;
DEBUG_ECHOLNPGM("time_off: ", v);
}
else
SERIAL_ECHOLNPGM("?O out of range (1..15)");
}

if (parser.seenval('S')) {
const uint8_t v = parser.value_byte();
if (WITHIN(v, 1, 8)) {
hysteresis_start = v;
DEBUG_ECHOLNPGM("hysteresis_start: ", v);
}
else
SERIAL_ECHOLNPGM("?S out of range (1..8)");
}

if (parser.seenval('V')) {
const int8_t v = (int8_t)constrain(parser.value_long(), -127, 127);
if (WITHIN(v, -3, 12)) {
hysteresis_end = v;
DEBUG_ECHOLNPGM("hysteresis_end: ", v);
}
else
SERIAL_ECHOLNPGM("?V out of range (-3..12)");
}

switch (i) {
case X_AXIS:
#if AXIS_IS_TMC(X)
if (index == 0) TMC_SET_CHOPPER_TIME(X);
#endif
#if AXIS_IS_TMC(X2)
if (index == 1) TMC_SET_CHOPPER_TIME(X2);
#endif
break;

#if HAS_Y_AXIS
case Y_AXIS:
#if AXIS_IS_TMC(Y)
if (index == 0) TMC_SET_CHOPPER_TIME(Y);
#endif
#if AXIS_IS_TMC(Y2)
if (index == 1) TMC_SET_CHOPPER_TIME(Y2);
#endif
break;
#endif

#if HAS_Z_AXIS
case Z_AXIS:
#if AXIS_IS_TMC(Z)
if (index == 0) TMC_SET_CHOPPER_TIME(Z);
#endif
#if AXIS_IS_TMC(Z2)
if (index == 1) TMC_SET_CHOPPER_TIME(Z2);
#endif
#if AXIS_IS_TMC(Z3)
if (index == 2) TMC_SET_CHOPPER_TIME(Z3);
#endif
#if AXIS_IS_TMC(Z4)
if (index == 3) TMC_SET_CHOPPER_TIME(Z4);
#endif
break;
#endif

#if LINEAR_AXES >= 4
case I_AXIS:
#if AXIS_IS_TMC(I)
TMC_SET_CHOPPER_TIME(I);
#endif
break;
#endif

#if LINEAR_AXES >= 5
case J_AXIS:
#if AXIS_IS_TMC(J)
TMC_SET_CHOPPER_TIME(J);
#endif
break;
#endif

#if LINEAR_AXES >= 4
case K_AXIS:
#if AXIS_IS_TMC(K)
TMC_SET_CHOPPER_TIME(K);
#endif
break;
#endif

#if E_STEPPERS
case E_AXIS: {
const int8_t target_e_stepper = get_target_e_stepper_from_command(0);
if (target_e_stepper < 0) return;
switch (target_e_stepper) {
#if AXIS_IS_TMC(E0)
case 0: TMC_SET_CHOPPER_TIME(E0); break;
#endif
#if AXIS_IS_TMC(E1)
case 1: TMC_SET_CHOPPER_TIME(E1); break;
#endif
#if AXIS_IS_TMC(E2)
case 2: TMC_SET_CHOPPER_TIME(E2); break;
#endif
#if AXIS_IS_TMC(E3)
case 3: TMC_SET_CHOPPER_TIME(E3); break;
#endif
#if AXIS_IS_TMC(E4)
case 4: TMC_SET_CHOPPER_TIME(E4); break;
#endif
#if AXIS_IS_TMC(E5)
case 5: TMC_SET_CHOPPER_TIME(E5); break;
#endif
#if AXIS_IS_TMC(E6)
case 6: TMC_SET_CHOPPER_TIME(E6); break;
#endif
#if AXIS_IS_TMC(E7)
case 7: TMC_SET_CHOPPER_TIME(E7); break;
#endif
}
} break;
#endif
}
}

if (report) {
#if AXIS_IS_TMC(X)
TMC_SAY_CHOPPER_TIME(X);
#endif
#if AXIS_IS_TMC(X2)
TMC_SAY_CHOPPER_TIME(X2);
#endif
#if AXIS_IS_TMC(Y)
TMC_SAY_CHOPPER_TIME(Y);
#endif
#if AXIS_IS_TMC(Y2)
TMC_SAY_CHOPPER_TIME(Y2);
#endif
#if AXIS_IS_TMC(Z)
TMC_SAY_CHOPPER_TIME(Z);
#endif
#if AXIS_IS_TMC(Z2)
TMC_SAY_CHOPPER_TIME(Z2);
#endif
#if AXIS_IS_TMC(Z3)
TMC_SAY_CHOPPER_TIME(Z3);
#endif
#if AXIS_IS_TMC(Z4)
TMC_SAY_CHOPPER_TIME(Z4);
#endif
#if AXIS_IS_TMC(I)
TMC_SAY_CHOPPER_TIME(I);
#endif
#if AXIS_IS_TMC(J)
TMC_SAY_CHOPPER_TIME(J);
#endif
#if AXIS_IS_TMC(K)
TMC_SAY_CHOPPER_TIME(K);
#endif
#if AXIS_IS_TMC(E0)
TMC_SAY_CHOPPER_TIME(E0);
#endif
#if AXIS_IS_TMC(E1)
TMC_SAY_CHOPPER_TIME(E1);
#endif
#if AXIS_IS_TMC(E2)
TMC_SAY_CHOPPER_TIME(E2);
#endif
#if AXIS_IS_TMC(E3)
TMC_SAY_CHOPPER_TIME(E3);
#endif
#if AXIS_IS_TMC(E4)
TMC_SAY_CHOPPER_TIME(E4);
#endif
#if AXIS_IS_TMC(E5)
TMC_SAY_CHOPPER_TIME(E5);
#endif
#if AXIS_IS_TMC(E6)
TMC_SAY_CHOPPER_TIME(E6);
#endif
#if AXIS_IS_TMC(E7)
TMC_SAY_CHOPPER_TIME(E7);
#endif
}
}

#endif // HAS_TRINAMIC_CONFIG
1 change: 1 addition & 0 deletions Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
#if USE_SENSORLESS
case 914: M914(); break; // M914: Set StallGuard sensitivity.
#endif
case 919: M919(); break; // M919: Set stepper Chopper Times
#endif

#if HAS_L64XX
Expand Down
Loading