From e0babfa4bab5fd27c50d70a2d99aacc6453b7c69 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Thu, 2 Sep 2021 13:19:21 +0300 Subject: [PATCH] Updated motor currents and added freewheeling --- src/config/config.h | 24 ++++++++++++++++-------- src/hal/tmc2130.cpp | 3 ++- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/config/config.h b/src/config/config.h index 4b827ca..9f8d096 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -80,8 +80,8 @@ static constexpr AxisConfig pulley = { .dirOn = false, .mRes = MRes_2, .vSense = true, - .iRun = 30, - .iHold = 1, + .iRun = 20, /// 348mA + .iHold = 0, /// 17mA in SpreadCycle, freewheel in StealthChop .stealth = false, .stepsPerUnit = (200 * 2 / 19.147274), }; @@ -97,9 +97,9 @@ static constexpr PulleyLimits pulleyLimits = { static constexpr AxisConfig selector = { .dirOn = true, .mRes = MRes_2, - .vSense = false, - .iRun = 17, - .iHold = 5, + .vSense = true, + .iRun = 18, /// 315mA + .iHold = 5, /// 99mA .stealth = false, .stepsPerUnit = (200 * 2 / 8.), }; @@ -115,9 +115,9 @@ static constexpr SelectorLimits selectorLimits = { static constexpr AxisConfig idler = { .dirOn = true, .mRes = MRes_16, - .vSense = false, - .iRun = 23, - .iHold = 11, + .vSense = true, + .iRun = 31, /// 530mA + .iHold = 23, /// 398mA .stealth = false, .stepsPerUnit = (200 * 16 / 360.), }; @@ -152,4 +152,12 @@ static_assert(tmc2130_PWM_FREQ <= 3, "tmc2130_PWM_GRAD out of range"); static constexpr uint32_t tmc2130_PWM_AUTOSCALE = 1; static_assert(tmc2130_PWM_AUTOSCALE <= 1, "tmc2130_PWM_AUTOSCALE out of range"); +/// Freewheel options for standstill: +/// 0: Normal operation (IHOLD is supplied to the motor at standstill) +/// 1: Freewheeling (as if the driver was disabled, no breaking except for detent torque) +/// 2: Coil shorted using LS drivers (stronger passive breaking) +/// 3: Coil shorted using HS drivers (weaker passive breaking) +static constexpr uint32_t tmc2130_freewheel = 1; +static_assert(tmc2130_PWM_AUTOSCALE <= 3, "tmc2130_freewheel out of range"); + } // namespace config diff --git a/src/hal/tmc2130.cpp b/src/hal/tmc2130.cpp index 42bcd77..d13b221 100644 --- a/src/hal/tmc2130.cpp +++ b/src/hal/tmc2130.cpp @@ -51,7 +51,8 @@ bool TMC2130::Init(const MotorParams ¶ms, const MotorCurrents ¤ts, Mot constexpr uint32_t pwmconf = ((uint32_t)(config::tmc2130_PWM_AMPL) << 0U) | ((uint32_t)(config::tmc2130_PWM_GRAD) << 8U) | ((uint32_t)(config::tmc2130_PWM_FREQ) << 16U) - | ((uint32_t)(config::tmc2130_PWM_AUTOSCALE & 0x01U) << 18U); + | ((uint32_t)(config::tmc2130_PWM_AUTOSCALE & 0x01U) << 18U) + | ((uint32_t)(config::tmc2130_freewheel & 0x03U) << 20U); //special freewheeling mode only active in stealthchop when IHOLD=0 and CS=0 (actual current) WriteRegister(params, Registers::PWMCONF, pwmconf); /// TPWMTHRS: switching velocity between stealthChop and spreadCycle.