From 2247bf1ba5f1a62a7433aa1b2764a91af1a80e2a Mon Sep 17 00:00:00 2001 From: teemuatlut Date: Sun, 23 Jun 2019 01:00:15 +0300 Subject: [PATCH] Add missing dedge init for TMC2209 (#14370) --- Marlin/src/module/stepper_indirection.cpp | 36 +++++++---------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/Marlin/src/module/stepper_indirection.cpp b/Marlin/src/module/stepper_indirection.cpp index b5575cfbba..3dacfc7cfb 100644 --- a/Marlin/src/module/stepper_indirection.cpp +++ b/Marlin/src/module/stepper_indirection.cpp @@ -269,14 +269,12 @@ void tmc_init(TMCMarlin &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const bool stealth) { st.begin(); - static constexpr int8_t timings[] = CHOPPER_TIMING; // Default 4, -2, 1 - CHOPCONF_t chopconf{0}; chopconf.tbl = 1; - chopconf.toff = timings[0]; + chopconf.toff = chopper_timing.toff; chopconf.intpol = INTERPOLATE; - chopconf.hend = timings[1] + 3; - chopconf.hstrt = timings[2] - 1; + chopconf.hend = chopper_timing.hend + 3; + chopconf.hstrt = chopper_timing.hstrt - 1; #if ENABLED(SQUARE_WAVE_STEPPING) chopconf.dedge = true; #endif @@ -286,16 +284,9 @@ st.microsteps(microsteps); st.iholddelay(10); st.TPOWERDOWN(128); // ~2s until driver lowers to hold current - st.TCOOLTHRS(0xFFFFF); - - #if ENABLED(ADAPTIVE_CURRENT) - COOLCONF_t coolconf{0}; - coolconf.semin = INCREASE_CURRENT_THRS; - coolconf.semax = REDUCE_CURRENT_THRS; - st.COOLCONF(coolconf.sr); - #endif st.en_pwm_mode(stealth); + st.stored.stealthChop_enabled = stealth; TMC2160_n::PWMCONF_t pwmconf{0}; pwmconf.pwm_lim = 12; @@ -573,6 +564,9 @@ chopconf.intpol = INTERPOLATE; chopconf.hend = chopper_timing.hend + 3; chopconf.hstrt = chopper_timing.hstrt - 1; + #if ENABLED(SQUARE_WAVE_STEPPING) + chopconf.dedge = true; + #endif st.CHOPCONF(chopconf.sr); st.rms_current(mA, HOLD_MULTIPLIER); @@ -673,14 +667,12 @@ void tmc_init(TMCMarlin &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const bool stealth) { st.begin(); - int8_t timings[] = CHOPPER_TIMING; // Default 4, -2, 1 - CHOPCONF_t chopconf{0}; chopconf.tbl = 1; - chopconf.toff = timings[0]; + chopconf.toff = chopper_timing.toff; chopconf.intpol = INTERPOLATE; - chopconf.hend = timings[1] + 3; - chopconf.hstrt = timings[2] - 1; + chopconf.hend = chopper_timing.hend + 3; + chopconf.hstrt = chopper_timing.hstrt - 1; #if ENABLED(SQUARE_WAVE_STEPPING) chopconf.dedge = true; #endif @@ -691,14 +683,8 @@ st.iholddelay(10); st.TPOWERDOWN(128); // ~2s until driver lowers to hold current - #if ENABLED(ADAPTIVE_CURRENT) - COOLCONF_t coolconf{0}; - coolconf.semin = INCREASE_CURRENT_THRS; - coolconf.semax = REDUCE_CURRENT_THRS; - st.COOLCONF(coolconf.sr); - #endif - st.en_pwm_mode(stealth); + st.stored.stealthChop_enabled = stealth; TMC2160_n::PWMCONF_t pwmconf{0}; pwmconf.pwm_lim = 12;