Skip to content

Commit 1a505f7

Browse files
committed
✨ EDITABLE_HOMING_CURRENT
1 parent d91e0c7 commit 1a505f7

File tree

8 files changed

+121
-52
lines changed

8 files changed

+121
-52
lines changed

Marlin/Configuration_adv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2995,6 +2995,8 @@
29952995

29962996
#define HOLD_MULTIPLIER 0.5 // Scales down the holding current from run current
29972997

2998+
//#define EDITABLE_HOMING_CURRENT // Add a G-code and menu to modify the Homing Current
2999+
29983000
/**
29993001
* Interpolate microsteps to 256
30003002
* Override for each driver with <driver>_INTERPOLATE settings below

Marlin/src/feature/tmc_util.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
#endif
4444
#endif
4545

46+
#if ENABLED(EDITABLE_HOMING_CURRENT)
47+
homing_current_t homing_current_mA;
48+
#endif
49+
4650
/**
4751
* Check for over temperature or short to ground error flags.
4852
* Report and log warning of overtemperature condition.

Marlin/src/feature/tmc_util.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,32 @@ void test_tmc_connection(LOGICAL_AXIS_DECL_LC(const bool, true));
375375

376376
#endif // USE_SENSORLESS
377377

378+
#if HAS_HOMING_CURRENT
379+
380+
// Axes that have a distinct homing current
381+
struct homing_current_t {
382+
OPTCODE(X_HAS_HOME_CURRENT, uint16_t X)
383+
OPTCODE(Y_HAS_HOME_CURRENT, uint16_t Y)
384+
OPTCODE(Z_HAS_HOME_CURRENT, uint16_t Z)
385+
OPTCODE(X2_HAS_HOME_CURRENT, uint16_t X2)
386+
OPTCODE(Y2_HAS_HOME_CURRENT, uint16_t Y2)
387+
OPTCODE(Z2_HAS_HOME_CURRENT, uint16_t Z2)
388+
OPTCODE(Z3_HAS_HOME_CURRENT, uint16_t Z3)
389+
OPTCODE(Z4_HAS_HOME_CURRENT, uint16_t Z4)
390+
OPTCODE(I_HAS_HOME_CURRENT, uint16_t I)
391+
OPTCODE(J_HAS_HOME_CURRENT, uint16_t J)
392+
OPTCODE(K_HAS_HOME_CURRENT, uint16_t K)
393+
OPTCODE(U_HAS_HOME_CURRENT, uint16_t U)
394+
OPTCODE(V_HAS_HOME_CURRENT, uint16_t V)
395+
OPTCODE(W_HAS_HOME_CURRENT, uint16_t W)
396+
};
397+
398+
#if ENABLED(EDITABLE_HOMING_CURRENT)
399+
extern homing_current_t homing_current_mA;
400+
#endif
401+
402+
#endif // HAS_HOMING_CURRENT
403+
378404
#endif // HAS_TRINAMIC_CONFIG
379405

380406
#if HAS_TMC_SPI

Marlin/src/lcd/language/language_en.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,7 @@ namespace LanguageNarrow_en {
883883
LSTR MSG_TMC_HOMING_THRS = _UxGT("Sensorless Homing");
884884
LSTR MSG_TMC_STEPPING_MODE = _UxGT("Stepping Mode");
885885
LSTR MSG_TMC_STEALTHCHOP = _UxGT("StealthChop");
886+
LSTR MSG_TMC_HOMING_CURRENT = _UxGT("Homing Current");
886887
LSTR MSG_SERVICE_RESET = _UxGT("Reset");
887888
LSTR MSG_SERVICE_IN = _UxGT(" in:");
888889
LSTR MSG_BACKLASH = _UxGT("Backlash");

Marlin/src/lcd/menu/menu_tmc.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,33 @@ void menu_tmc_current() {
110110

111111
#endif // SENSORLESS_HOMING
112112

113+
#if ENABLED(EDITABLE_HOMING_CURRENT)
114+
115+
#define TMC_EDIT_HOMING_CURRENT(ST, STR) EDIT_ITEM_FAST_F(uint16_4, F(STR), &homing_current_mA.ST, ST##_CURRENT / 3, ST##_CURRENT)
116+
117+
void menu_tmc_homing_current() {
118+
START_MENU();
119+
STATIC_ITEM(MSG_TMC_HOMING_CURRENT);
120+
BACK_ITEM(MSG_TMC_DRIVERS);
121+
TERN_( X_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(X, STR_X));
122+
TERN_(X2_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(X2, STR_X2));
123+
TERN_( Y_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(Y, STR_Y));
124+
TERN_(Y2_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(Y2, STR_Y2));
125+
TERN_( Z_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(Z, STR_Z));
126+
TERN_(Z2_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(Z2, STR_Z2));
127+
TERN_(Z3_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(Z3, STR_Z3));
128+
TERN_(Z4_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(Z4, STR_Z4));
129+
TERN_( I_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(I, STR_I));
130+
TERN_( J_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(J, STR_J));
131+
TERN_( K_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(K, STR_K));
132+
TERN_( U_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(U, STR_U));
133+
TERN_( V_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(V, STR_V));
134+
TERN_( W_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(W, STR_W));
135+
END_MENU();
136+
}
137+
138+
#endif // EDITABLE_HOMING_CURRENT
139+
113140
#if HAS_STEALTHCHOP
114141

115142
#define TMC_EDIT_STEP_MODE(ST, STR) EDIT_ITEM_F(bool, F(STR), &stepper##ST.stored.stealthChop_enabled, []{ stepper##ST.refresh_stepping_mode(); })
@@ -143,9 +170,10 @@ void menu_tmc() {
143170
START_MENU();
144171
BACK_ITEM(MSG_ADVANCED_SETTINGS);
145172
SUBMENU(MSG_TMC_CURRENT, menu_tmc_current);
146-
TERN_(HYBRID_THRESHOLD, SUBMENU(MSG_TMC_HYBRID_THRS, menu_tmc_hybrid_thrs));
147-
TERN_(SENSORLESS_HOMING, SUBMENU(MSG_TMC_HOMING_THRS, menu_tmc_homing_thrs));
148-
TERN_(HAS_STEALTHCHOP, SUBMENU(MSG_TMC_STEPPING_MODE, menu_tmc_step_mode));
173+
TERN_(HYBRID_THRESHOLD, SUBMENU(MSG_TMC_HYBRID_THRS, menu_tmc_hybrid_thrs));
174+
TERN_(SENSORLESS_HOMING, SUBMENU(MSG_TMC_HOMING_THRS, menu_tmc_homing_thrs));
175+
TERN_(EDITABLE_HOMING_CURRENT, SUBMENU(MSG_TMC_HOMING_CURRENT, menu_tmc_homing_current));
176+
TERN_(HAS_STEALTHCHOP, SUBMENU(MSG_TMC_STEALTHCHOP, menu_tmc_step_mode));
149177
END_MENU();
150178
}
151179

Marlin/src/module/motion.cpp

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -271,60 +271,21 @@ void report_current_position_projected() {
271271
#define debug_current(...)
272272
#endif
273273

274-
#if HAS_CURRENT_HOME_X
275-
int16_t saved_current_X;
276-
#endif
277-
#if HAS_CURRENT_HOME_Y
278-
int16_t saved_current_Y;
279-
#endif
280-
#if HAS_CURRENT_HOME_Z
281-
int16_t saved_current_Z;
282-
#endif
283-
#if HAS_CURRENT_HOME_X2
284-
int16_t saved_current_X2;
285-
#endif
286-
#if HAS_CURRENT_HOME_Y2
287-
int16_t saved_current_Y2;
288-
#endif
289-
#if HAS_CURRENT_HOME_Z2
290-
int16_t saved_current_Z2;
291-
#endif
292-
#if HAS_CURRENT_HOME_Z3
293-
int16_t saved_current_Z3;
294-
#endif
295-
#if HAS_CURRENT_HOME_Z4
296-
int16_t saved_current_Z4;
297-
#endif
298-
#if HAS_CURRENT_HOME_I
299-
int16_t saved_current_I;
300-
#endif
301-
#if HAS_CURRENT_HOME_J
302-
int16_t saved_current_J;
303-
#endif
304-
#if HAS_CURRENT_HOME_K
305-
int16_t saved_current_K;
306-
#endif
307-
#if HAS_CURRENT_HOME_U
308-
int16_t saved_current_U;
309-
#endif
310-
#if HAS_CURRENT_HOME_V
311-
int16_t saved_current_V;
312-
#endif
313-
#if HAS_CURRENT_HOME_W
314-
int16_t saved_current_W;
315-
#endif
274+
homing_current_t saved_current_mA;
316275

317276
/**
318277
* Set motors to their homing / probing currents.
319278
* Currents are saved first so they can be restored afterward.
320279
*/
321280
void set_homing_current(const AxisEnum axis) {
322281

282+
#define HOMING_CURRENT(A) TERN(EDITABLE_HOMING_CURRENT, homing_current_mA.A, A##_CURRENT_HOME)
283+
323284
// Saves the running current of the motor at the moment the function is called and sets current to CURRENT_HOME
324285
#define _SAVE_SET_CURRENT(A) \
325-
saved_current_##A = stepper##A.getMilliamps(); \
326-
stepper##A.rms_current(A##_CURRENT_HOME); \
327-
debug_current(F(STR_##A), saved_current_##A, A##_CURRENT_HOME)
286+
saved_current_mA.A = stepper##A.getMilliamps(); \
287+
stepper##A.rms_current(HOMING_CURRENT(A)); \
288+
debug_current(F(STR_##A), saved_current_mA.A, HOMING_CURRENT(A))
328289

329290
#define _MAP_SAVE_SET(A) OPTCODE(A##_HAS_HOME_CURRENT, _SAVE_SET_CURRENT(A))
330291

@@ -478,8 +439,8 @@ void report_current_position_projected() {
478439

479440
// Restore the saved current
480441
#define _RESTORE_CURRENT(A) \
481-
stepper##A.rms_current(saved_current_##A); \
482-
debug_current(F(STR_##A), A##_CURRENT_HOME, saved_current_##A)
442+
stepper##A.rms_current(saved_current_mA.A); \
443+
debug_current(F(STR_##A), HOMING_CURRENT(A), saved_current_mA.A)
483444

484445
#define _MAP_RESTORE(A) OPTCODE(A##_HAS_HOME_CURRENT, _RESTORE_CURRENT(A))
485446

Marlin/src/module/settings.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,13 @@ typedef struct SettingsDataStruct {
469469
xyz_feedrate_t homing_feedrate_mm_m; // M210 X Y Z I J K U V W
470470
#endif
471471

472+
//
473+
// TMC Homing Current
474+
//
475+
#if ENABLED(EDITABLE_HOMING_CURRENT)
476+
homing_current_t homing_current_mA; // M917 X Y Z...
477+
#endif
478+
472479
//
473480
// !NO_VOLUMETRIC
474481
//
@@ -1355,6 +1362,14 @@ void MarlinSettings::postprocess() {
13551362
EEPROM_WRITE(homing_feedrate_mm_m);
13561363
#endif
13571364

1365+
//
1366+
// TMC Homing Current
1367+
//
1368+
#if ENABLED(EDITABLE_HOMING_CURRENT)
1369+
_FIELD_TEST(homing_current_mA);
1370+
EEPROM_WRITE(homing_current_mA);
1371+
#endif
1372+
13581373
//
13591374
// Volumetric & Filament Size
13601375
//
@@ -2414,6 +2429,14 @@ void MarlinSettings::postprocess() {
24142429
EEPROM_READ(homing_feedrate_mm_m);
24152430
#endif
24162431

2432+
//
2433+
// TMC Homing Current
2434+
//
2435+
#if ENABLED(EDITABLE_HOMING_CURRENT)
2436+
_FIELD_TEST(homing_current_mA);
2437+
EEPROM_READ(homing_current_mA);
2438+
#endif
2439+
24172440
//
24182441
// Volumetric & Filament Size
24192442
//
@@ -3626,6 +3649,29 @@ void MarlinSettings::reset() {
36263649
//
36273650
TERN_(EDITABLE_HOMING_FEEDRATE, homing_feedrate_mm_m = xyz_feedrate_t(HOMING_FEEDRATE_MM_M));
36283651

3652+
//
3653+
// TMC Homing Current
3654+
//
3655+
#if ENABLED(EDITABLE_HOMING_CURRENT)
3656+
homing_current_t base_homing_current_mA = {
3657+
OPTITEM(X_HAS_HOME_CURRENT, X_CURRENT_HOME)
3658+
OPTITEM(Y_HAS_HOME_CURRENT, Y_CURRENT_HOME)
3659+
OPTITEM(Z_HAS_HOME_CURRENT, Z_CURRENT_HOME)
3660+
OPTITEM(X2_HAS_HOME_CURRENT, X2_CURRENT_HOME)
3661+
OPTITEM(Y2_HAS_HOME_CURRENT, Y2_CURRENT_HOME)
3662+
OPTITEM(Z2_HAS_HOME_CURRENT, Z2_CURRENT_HOME)
3663+
OPTITEM(Z3_HAS_HOME_CURRENT, Z3_CURRENT_HOME)
3664+
OPTITEM(Z4_HAS_HOME_CURRENT, Z4_CURRENT_HOME)
3665+
OPTITEM(I_HAS_HOME_CURRENT, I_CURRENT_HOME)
3666+
OPTITEM(J_HAS_HOME_CURRENT, J_CURRENT_HOME)
3667+
OPTITEM(K_HAS_HOME_CURRENT, K_CURRENT_HOME)
3668+
OPTITEM(U_HAS_HOME_CURRENT, U_CURRENT_HOME)
3669+
OPTITEM(V_HAS_HOME_CURRENT, V_CURRENT_HOME)
3670+
OPTITEM(W_HAS_HOME_CURRENT, W_CURRENT_HOME)
3671+
};
3672+
homing_current_mA = base_homing_current_mA;
3673+
#endif
3674+
36293675
//
36303676
// Volumetric & Filament Size
36313677
//

buildroot/tests/STM32F103RC_btt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ set -e
1111
#
1212
restore_configs
1313
opt_set MOTHERBOARD BOARD_BTT_SKR_MINI_E3_V1_0 SERIAL_PORT 1 SERIAL_PORT_2 -1 \
14-
X_DRIVER_TYPE TMC2209 Y_DRIVER_TYPE TMC2209 Z_DRIVER_TYPE TMC2209 E0_DRIVER_TYPE TMC2209
15-
opt_enable CR10_STOCKDISPLAY PINS_DEBUGGING Z_IDLE_HEIGHT \
14+
X_DRIVER_TYPE TMC2209 Y_DRIVER_TYPE TMC2209 Z_DRIVER_TYPE TMC2209 E0_DRIVER_TYPE TMC2209 \
15+
X_CURRENT_HOME X_CURRENT/2 Y_CURRENT_HOME Y_CURRENT/2 Z_CURRENT_HOME Y_CURRENT/2
16+
opt_enable CR10_STOCKDISPLAY PINS_DEBUGGING Z_IDLE_HEIGHT EDITABLE_HOMING_CURRENT \
1617
FT_MOTION FT_MOTION_MENU BIQU_MICROPROBE_V1 PROBE_ENABLE_DISABLE Z_SAFE_HOMING AUTO_BED_LEVELING_BILINEAR \
1718
ADAPTIVE_STEP_SMOOTHING NONLINEAR_EXTRUSION
1819
exec_test $1 $2 "BigTreeTech SKR Mini E3 1.0 - TMC2209 HW Serial, FT_MOTION" "$3"

0 commit comments

Comments
 (0)