Skip to content

Commit 747fed2

Browse files
ManuelMcLureW4tel-BiDi
authored andcommitted
Configure TMC interpolation per driver (MarlinFirmware#19828)
1 parent e230a48 commit 747fed2

4 files changed

Lines changed: 99 additions & 19 deletions

File tree

Marlin/Configuration_adv.h

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,14 +2261,20 @@
22612261
#if HAS_TRINAMIC_CONFIG
22622262

22632263
#define HOLD_MULTIPLIER 0.5 // Scales down the holding current from run current
2264-
#define INTERPOLATE true // Interpolate X/Y/Z_MICROSTEPS to 256
2264+
2265+
/**
2266+
* Interpolate microsteps to 256
2267+
* Override for each driver with <driver>_INTERPOLATE settings below
2268+
*/
2269+
#define INTERPOLATE true
22652270

22662271
#if AXIS_IS_TMC(X)
22672272
#define X_CURRENT 800 // (mA) RMS current. Multiply by 1.414 for peak current.
22682273
#define X_CURRENT_HOME X_CURRENT // (mA) RMS current for sensorless homing
2269-
#define X_MICROSTEPS 16 // 0..256
2274+
#define X_MICROSTEPS 16 // 0..256
22702275
#define X_RSENSE 0.11
2271-
#define X_CHAIN_POS -1 // <=0 : Not chained. 1 : MCU MOSI connected. 2 : Next in chain, ...
2276+
#define X_CHAIN_POS -1 // -1..0: Not chained. 1: MCU MOSI connected. 2: Next in chain, ...
2277+
//#define X_INTERPOLATE true // Enable to override 'INTERPOLATE' for the X axis
22722278
#endif
22732279

22742280
#if AXIS_IS_TMC(X2)
@@ -2277,6 +2283,7 @@
22772283
#define X2_MICROSTEPS 16
22782284
#define X2_RSENSE 0.11
22792285
#define X2_CHAIN_POS -1
2286+
//#define X2_INTERPOLATE true
22802287
#endif
22812288

22822289
#if AXIS_IS_TMC(Y)
@@ -2285,6 +2292,7 @@
22852292
#define Y_MICROSTEPS 16
22862293
#define Y_RSENSE 0.11
22872294
#define Y_CHAIN_POS -1
2295+
//#define Y_INTERPOLATE true
22882296
#endif
22892297

22902298
#if AXIS_IS_TMC(Y2)
@@ -2293,6 +2301,7 @@
22932301
#define Y2_MICROSTEPS 16
22942302
#define Y2_RSENSE 0.11
22952303
#define Y2_CHAIN_POS -1
2304+
//#define Y2_INTERPOLATE true
22962305
#endif
22972306

22982307
#if AXIS_IS_TMC(Z)
@@ -2301,6 +2310,7 @@
23012310
#define Z_MICROSTEPS 16
23022311
#define Z_RSENSE 0.11
23032312
#define Z_CHAIN_POS -1
2313+
//#define Z_INTERPOLATE true
23042314
#endif
23052315

23062316
#if AXIS_IS_TMC(Z2)
@@ -2309,6 +2319,7 @@
23092319
#define Z2_MICROSTEPS 16
23102320
#define Z2_RSENSE 0.11
23112321
#define Z2_CHAIN_POS -1
2322+
//#define Z2_INTERPOLATE true
23122323
#endif
23132324

23142325
#if AXIS_IS_TMC(Z3)
@@ -2317,6 +2328,7 @@
23172328
#define Z3_MICROSTEPS 16
23182329
#define Z3_RSENSE 0.11
23192330
#define Z3_CHAIN_POS -1
2331+
//#define Z3_INTERPOLATE true
23202332
#endif
23212333

23222334
#if AXIS_IS_TMC(Z4)
@@ -2325,62 +2337,71 @@
23252337
#define Z4_MICROSTEPS 16
23262338
#define Z4_RSENSE 0.11
23272339
#define Z4_CHAIN_POS -1
2340+
//#define Z4_INTERPOLATE true
23282341
#endif
23292342

23302343
#if AXIS_IS_TMC(E0)
23312344
#define E0_CURRENT 800
23322345
#define E0_MICROSTEPS 16
23332346
#define E0_RSENSE 0.11
23342347
#define E0_CHAIN_POS -1
2348+
//#define E0_INTERPOLATE true
23352349
#endif
23362350

23372351
#if AXIS_IS_TMC(E1)
23382352
#define E1_CURRENT 800
23392353
#define E1_MICROSTEPS 16
23402354
#define E1_RSENSE 0.11
23412355
#define E1_CHAIN_POS -1
2356+
//#define E1_INTERPOLATE true
23422357
#endif
23432358

23442359
#if AXIS_IS_TMC(E2)
23452360
#define E2_CURRENT 800
23462361
#define E2_MICROSTEPS 16
23472362
#define E2_RSENSE 0.11
23482363
#define E2_CHAIN_POS -1
2364+
//#define E2_INTERPOLATE true
23492365
#endif
23502366

23512367
#if AXIS_IS_TMC(E3)
23522368
#define E3_CURRENT 800
23532369
#define E3_MICROSTEPS 16
23542370
#define E3_RSENSE 0.11
23552371
#define E3_CHAIN_POS -1
2372+
//#define E3_INTERPOLATE true
23562373
#endif
23572374

23582375
#if AXIS_IS_TMC(E4)
23592376
#define E4_CURRENT 800
23602377
#define E4_MICROSTEPS 16
23612378
#define E4_RSENSE 0.11
23622379
#define E4_CHAIN_POS -1
2380+
//#define E4_INTERPOLATE true
23632381
#endif
23642382

23652383
#if AXIS_IS_TMC(E5)
23662384
#define E5_CURRENT 800
23672385
#define E5_MICROSTEPS 16
23682386
#define E5_RSENSE 0.11
23692387
#define E5_CHAIN_POS -1
2388+
//#define E5_INTERPOLATE true
23702389
#endif
23712390

23722391
#if AXIS_IS_TMC(E6)
23732392
#define E6_CURRENT 800
23742393
#define E6_MICROSTEPS 16
23752394
#define E6_RSENSE 0.11
23762395
#define E6_CHAIN_POS -1
2396+
//#define E6_INTERPOLATE true
23772397
#endif
23782398

23792399
#if AXIS_IS_TMC(E7)
23802400
#define E7_CURRENT 800
23812401
#define E7_MICROSTEPS 16
23822402
#define E7_RSENSE 0.11
23832403
#define E7_CHAIN_POS -1
2404+
//#define E7_INTERPOLATE true
23842405
#endif
23852406

23862407
/**

Marlin/src/feature/tmc_util.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,8 @@
497497
TMC_HEND,
498498
TMC_HSTRT,
499499
TMC_SGT,
500-
TMC_MSCNT
500+
TMC_MSCNT,
501+
TMC_INTERPOLATE
501502
};
502503
enum TMC_drv_status_enum : char {
503504
TMC_DRV_CODES,
@@ -553,6 +554,7 @@
553554
case TMC_PWM_SCALE: SERIAL_PRINT(st.PWM_SCALE(), DEC); break;
554555
case TMC_SGT: SERIAL_PRINT(st.sgt(), DEC); break;
555556
case TMC_STEALTHCHOP: serialprint_truefalse(st.en_pwm_mode()); break;
557+
case TMC_INTERPOLATE: serialprint_truefalse(st.intpol()); break;
556558
default: break;
557559
}
558560
}
@@ -588,6 +590,7 @@
588590
SERIAL_ECHOPGM("/256");
589591
}
590592
break;
593+
case TMC_INTERPOLATE: serialprint_truefalse(st.intpol()); break;
591594
default: break;
592595
}
593596
}
@@ -603,6 +606,7 @@
603606
case TMC_STEALTHCHOP: serialprint_truefalse(st.stealth()); break;
604607
case TMC_S2VSA: if (st.s2vsa()) SERIAL_CHAR('*'); break;
605608
case TMC_S2VSB: if (st.s2vsb()) SERIAL_CHAR('*'); break;
609+
case TMC_INTERPOLATE: serialprint_truefalse(st.intpol()); break;
606610
default: break;
607611
}
608612
}
@@ -644,6 +648,12 @@
644648

645649
#if HAS_DRIVER(TMC2660)
646650
static void _tmc_parse_drv_status(TMC2660Stepper, const TMC_drv_status_enum) { }
651+
static void _tmc_status(TMC2660Stepper &st, const TMC_debug_enum i) {
652+
switch (i) {
653+
case TMC_INTERPOLATE: serialprint_truefalse(st.intpol()); break;
654+
default: break;
655+
}
656+
}
647657
#endif
648658

649659
template <typename TMC>
@@ -902,6 +912,7 @@
902912
#endif
903913
TMC_REPORT("stealthChop", TMC_STEALTHCHOP);
904914
TMC_REPORT("msteps\t", TMC_MICROSTEPS);
915+
TMC_REPORT("interp\t", TMC_INTERPOLATE);
905916
TMC_REPORT("tstep\t", TMC_TSTEP);
906917
TMC_REPORT("PWM thresh.", TMC_TPWMTHRS);
907918
TMC_REPORT("[mm/s]\t", TMC_TPWMTHRS_MMS);

Marlin/src/inc/Conditionals_post.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,54 @@
16081608
#define Y_SPI_SENSORLESS Y_SENSORLESS
16091609
#define Z_SPI_SENSORLESS Z_SENSORLESS
16101610
#endif
1611+
#ifndef X_INTERPOLATE
1612+
#define X_INTERPOLATE INTERPOLATE
1613+
#endif
1614+
#ifndef X2_INTERPOLATE
1615+
#define X2_INTERPOLATE INTERPOLATE
1616+
#endif
1617+
#ifndef Y_INTERPOLATE
1618+
#define Y_INTERPOLATE INTERPOLATE
1619+
#endif
1620+
#ifndef Y2_INTERPOLATE
1621+
#define Y2_INTERPOLATE INTERPOLATE
1622+
#endif
1623+
#ifndef Z_INTERPOLATE
1624+
#define Z_INTERPOLATE INTERPOLATE
1625+
#endif
1626+
#ifndef Z2_INTERPOLATE
1627+
#define Z2_INTERPOLATE INTERPOLATE
1628+
#endif
1629+
#ifndef Z3_INTERPOLATE
1630+
#define Z3_INTERPOLATE INTERPOLATE
1631+
#endif
1632+
#ifndef Z4_INTERPOLATE
1633+
#define Z4_INTERPOLATE INTERPOLATE
1634+
#endif
1635+
#ifndef E0_INTERPOLATE
1636+
#define E0_INTERPOLATE INTERPOLATE
1637+
#endif
1638+
#ifndef E1_INTERPOLATE
1639+
#define E1_INTERPOLATE INTERPOLATE
1640+
#endif
1641+
#ifndef E2_INTERPOLATE
1642+
#define E2_INTERPOLATE INTERPOLATE
1643+
#endif
1644+
#ifndef E3_INTERPOLATE
1645+
#define E3_INTERPOLATE INTERPOLATE
1646+
#endif
1647+
#ifndef E4_INTERPOLATE
1648+
#define E4_INTERPOLATE INTERPOLATE
1649+
#endif
1650+
#ifndef E5_INTERPOLATE
1651+
#define E5_INTERPOLATE INTERPOLATE
1652+
#endif
1653+
#ifndef E6_INTERPOLATE
1654+
#define E6_INTERPOLATE INTERPOLATE
1655+
#endif
1656+
#ifndef E7_INTERPOLATE
1657+
#define E7_INTERPOLATE INTERPOLATE
1658+
#endif
16111659
#endif
16121660

16131661
#if (HAS_E_DRIVER(TMC2660) \

Marlin/src/module/stepper/trinamic.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include <SPI.h>
3737

3838
enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E };
39-
#define TMC_INIT(ST, STEALTH_INDEX) tmc_init(stepper##ST, ST##_CURRENT, ST##_MICROSTEPS, ST##_HYBRID_THRESHOLD, stealthchop_by_axis[STEALTH_INDEX], chopper_timing_##ST)
39+
#define TMC_INIT(ST, STEALTH_INDEX) tmc_init(stepper##ST, ST##_CURRENT, ST##_MICROSTEPS, ST##_HYBRID_THRESHOLD, stealthchop_by_axis[STEALTH_INDEX], chopper_timing_##ST, ST##_INTERPOLATE)
4040

4141
// IC = TMC model number
4242
// ST = Stepper object letter
@@ -131,13 +131,13 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E };
131131

132132
#if HAS_DRIVER(TMC2130)
133133
template<char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
134-
void tmc_init(TMCMarlin<TMC2130Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t hyb_thrs, const bool stealth, const chopper_timing_t &chop_init) {
134+
void tmc_init(TMCMarlin<TMC2130Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t hyb_thrs, const bool stealth, const chopper_timing_t &chop_init, const bool interpolate) {
135135
st.begin();
136136

137137
CHOPCONF_t chopconf{0};
138138
chopconf.tbl = 0b01;
139139
chopconf.toff = chop_init.toff;
140-
chopconf.intpol = INTERPOLATE;
140+
chopconf.intpol = interpolate;
141141
chopconf.hend = chop_init.hend + 3;
142142
chopconf.hstrt = chop_init.hstrt - 1;
143143
TERN_(SQUARE_WAVE_STEPPING, chopconf.dedge = true);
@@ -166,13 +166,13 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E };
166166

167167
#if HAS_DRIVER(TMC2160)
168168
template<char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
169-
void tmc_init(TMCMarlin<TMC2160Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t hyb_thrs, const bool stealth, const chopper_timing_t &chop_init) {
169+
void tmc_init(TMCMarlin<TMC2160Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t hyb_thrs, const bool stealth, const chopper_timing_t &chop_init, const bool interpolate) {
170170
st.begin();
171171

172172
CHOPCONF_t chopconf{0};
173173
chopconf.tbl = 0b01;
174174
chopconf.toff = chop_init.toff;
175-
chopconf.intpol = INTERPOLATE;
175+
chopconf.intpol = interpolate;
176176
chopconf.hend = chop_init.hend + 3;
177177
chopconf.hstrt = chop_init.hstrt - 1;
178178
TERN_(SQUARE_WAVE_STEPPING, chopconf.dedge = true);
@@ -484,7 +484,7 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E };
484484

485485
#if HAS_DRIVER(TMC2208)
486486
template<char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
487-
void tmc_init(TMCMarlin<TMC2208Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t hyb_thrs, const bool stealth, const chopper_timing_t &chop_init) {
487+
void tmc_init(TMCMarlin<TMC2208Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t hyb_thrs, const bool stealth, const chopper_timing_t &chop_init, const bool interpolate) {
488488
TMC2208_n::GCONF_t gconf{0};
489489
gconf.pdn_disable = true; // Use UART
490490
gconf.mstep_reg_select = true; // Select microsteps with UART
@@ -496,7 +496,7 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E };
496496
TMC2208_n::CHOPCONF_t chopconf{0};
497497
chopconf.tbl = 0b01; // blank_time = 24
498498
chopconf.toff = chop_init.toff;
499-
chopconf.intpol = INTERPOLATE;
499+
chopconf.intpol = interpolate;
500500
chopconf.hend = chop_init.hend + 3;
501501
chopconf.hstrt = chop_init.hstrt - 1;
502502
TERN_(SQUARE_WAVE_STEPPING, chopconf.dedge = true);
@@ -526,7 +526,7 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E };
526526

527527
#if HAS_DRIVER(TMC2209)
528528
template<char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
529-
void tmc_init(TMCMarlin<TMC2209Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t hyb_thrs, const bool stealth, const chopper_timing_t &chop_init) {
529+
void tmc_init(TMCMarlin<TMC2209Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t hyb_thrs, const bool stealth, const chopper_timing_t &chop_init, const bool interpolate) {
530530
TMC2208_n::GCONF_t gconf{0};
531531
gconf.pdn_disable = true; // Use UART
532532
gconf.mstep_reg_select = true; // Select microsteps with UART
@@ -538,7 +538,7 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E };
538538
TMC2208_n::CHOPCONF_t chopconf{0};
539539
chopconf.tbl = 0b01; // blank_time = 24
540540
chopconf.toff = chop_init.toff;
541-
chopconf.intpol = INTERPOLATE;
541+
chopconf.intpol = interpolate;
542542
chopconf.hend = chop_init.hend + 3;
543543
chopconf.hstrt = chop_init.hstrt - 1;
544544
TERN_(SQUARE_WAVE_STEPPING, chopconf.dedge = true);
@@ -568,7 +568,7 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E };
568568

569569
#if HAS_DRIVER(TMC2660)
570570
template<char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
571-
void tmc_init(TMCMarlin<TMC2660Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t, const bool, const chopper_timing_t &chop_init) {
571+
void tmc_init(TMCMarlin<TMC2660Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t, const bool, const chopper_timing_t &chop_init, const bool interpolate) {
572572
st.begin();
573573

574574
TMC2660_n::CHOPCONF_t chopconf{0};
@@ -582,21 +582,21 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E };
582582
st.rms_current(mA);
583583
st.microsteps(microsteps);
584584
TERN_(SQUARE_WAVE_STEPPING, st.dedge(true));
585-
st.intpol(INTERPOLATE);
585+
st.intpol(interpolate);
586586
st.diss2g(true); // Disable short to ground protection. Too many false readings?
587587
TERN_(TMC_DEBUG, st.rdsel(0b01));
588588
}
589589
#endif // TMC2660
590590

591591
#if HAS_DRIVER(TMC5130)
592592
template<char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
593-
void tmc_init(TMCMarlin<TMC5130Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t hyb_thrs, const bool stealth, const chopper_timing_t &chop_init) {
593+
void tmc_init(TMCMarlin<TMC5130Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t hyb_thrs, const bool stealth, const chopper_timing_t &chop_init, const bool interpolate) {
594594
st.begin();
595595

596596
CHOPCONF_t chopconf{0};
597597
chopconf.tbl = 0b01;
598598
chopconf.toff = chop_init.toff;
599-
chopconf.intpol = INTERPOLATE;
599+
chopconf.intpol = interpolate;
600600
chopconf.hend = chop_init.hend + 3;
601601
chopconf.hstrt = chop_init.hstrt - 1;
602602
TERN_(SQUARE_WAVE_STEPPING, chopconf.dedge = true);
@@ -625,13 +625,13 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E };
625625

626626
#if HAS_DRIVER(TMC5160)
627627
template<char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
628-
void tmc_init(TMCMarlin<TMC5160Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t hyb_thrs, const bool stealth, const chopper_timing_t &chop_init) {
628+
void tmc_init(TMCMarlin<TMC5160Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t hyb_thrs, const bool stealth, const chopper_timing_t &chop_init, const bool interpolate) {
629629
st.begin();
630630

631631
CHOPCONF_t chopconf{0};
632632
chopconf.tbl = 0b01;
633633
chopconf.toff = chop_init.toff;
634-
chopconf.intpol = INTERPOLATE;
634+
chopconf.intpol = interpolate;
635635
chopconf.hend = chop_init.hend + 3;
636636
chopconf.hstrt = chop_init.hstrt - 1;
637637
TERN_(SQUARE_WAVE_STEPPING, chopconf.dedge = true);

0 commit comments

Comments
 (0)