Remove shifting in config for TMC + add compile-time checks
parent
a8147be803
commit
b61836dd57
|
|
@ -108,12 +108,22 @@ static constexpr IdlerLimits idlerLimits = {
|
||||||
|
|
||||||
// TMC2130 setup
|
// TMC2130 setup
|
||||||
|
|
||||||
static constexpr uint8_t tmc2130_sg_thrs = 3; // @todo 7bit two's complement for the sg_thrs
|
static constexpr int8_t tmc2130_sg_thrs = 3; // @todo 7bit two's complement for the sg_thrs
|
||||||
static constexpr uint32_t tmc2130_coolConf = (((uint32_t)tmc2130_sg_thrs) << 16U);
|
static_assert(tmc2130_sg_thrs >= -64 && tmc2130_sg_thrs <= 63, "tmc2130_sg_thrs out of range");
|
||||||
static constexpr uint16_t tmc2130_coolStepThreshold = 400;
|
|
||||||
static constexpr uint32_t tmc2130_PWM_AMPL = (uint32_t)(240U & 0xFFU) << 0U;
|
static constexpr uint32_t tmc2130_coolStepThreshold = 400; ///< step-based 20bit uint
|
||||||
static constexpr uint32_t tmc2130_PWM_GRAD = (uint32_t)(4U & 0xFFU) << 8U;
|
static_assert(tmc2130_coolStepThreshold <= 0x3ffff, "tmc2130_coolStepThreshold out of range");
|
||||||
static constexpr uint32_t tmc2130_PWM_FREQ = (uint32_t)(2U & 0x03U) << 16U;
|
|
||||||
static constexpr uint32_t tmc2130_PWM_AUTOSCALE = (uint32_t)(1U & 0x01U) << 18U;
|
static constexpr uint32_t tmc2130_PWM_AMPL = 240;
|
||||||
|
static_assert(tmc2130_PWM_AMPL <= 255, "tmc2130_PWM_AMPL out of range");
|
||||||
|
|
||||||
|
static constexpr uint32_t tmc2130_PWM_GRAD = 4;
|
||||||
|
static_assert(tmc2130_PWM_GRAD <= 255, "tmc2130_PWM_GRAD out of range");
|
||||||
|
|
||||||
|
static constexpr uint32_t tmc2130_PWM_FREQ = 2;
|
||||||
|
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");
|
||||||
|
|
||||||
} // namespace config
|
} // namespace config
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ bool TMC2130::Init(const MotorParams ¶ms) {
|
||||||
///check for compatible tmc driver (IOIN version field)
|
///check for compatible tmc driver (IOIN version field)
|
||||||
uint32_t IOIN = ReadRegister(params, Registers::IOIN);
|
uint32_t IOIN = ReadRegister(params, Registers::IOIN);
|
||||||
|
|
||||||
// if the version is incorrect or an always 1st bit is 0
|
// if the version is incorrect or a bit always set to 1 is suddenly 0
|
||||||
// (the supposed SD_MODE pin that doesn't exist on this driver variant)
|
// (the supposed SD_MODE pin that doesn't exist on this driver variant)
|
||||||
if (((IOIN >> 24U) != 0x11) | !(IOIN & (1U << 6U)))
|
if (((IOIN >> 24U) != 0x11) | !(IOIN & (1U << 6U)))
|
||||||
return true; // @todo return some kind of failure
|
return true; // @todo return some kind of failure
|
||||||
|
|
@ -45,7 +45,8 @@ bool TMC2130::Init(const MotorParams ¶ms) {
|
||||||
WriteRegister(params, Registers::TPOWERDOWN, 0);
|
WriteRegister(params, Registers::TPOWERDOWN, 0);
|
||||||
|
|
||||||
///Stallguard parameters
|
///Stallguard parameters
|
||||||
WriteRegister(params, Registers::COOLCONF, config::tmc2130_coolConf);
|
static constexpr uint32_t tmc2130_coolConf = (((uint32_t)config::tmc2130_sg_thrs) << 16U);
|
||||||
|
WriteRegister(params, Registers::COOLCONF, tmc2130_coolConf);
|
||||||
WriteRegister(params, Registers::TCOOLTHRS, config::tmc2130_coolStepThreshold);
|
WriteRegister(params, Registers::TCOOLTHRS, config::tmc2130_coolStepThreshold);
|
||||||
|
|
||||||
///Write stealth mode config and setup diag0 output
|
///Write stealth mode config and setup diag0 output
|
||||||
|
|
@ -54,7 +55,10 @@ bool TMC2130::Init(const MotorParams ¶ms) {
|
||||||
WriteRegister(params, Registers::GCONF, gconf);
|
WriteRegister(params, Registers::GCONF, gconf);
|
||||||
|
|
||||||
///stealthChop parameters
|
///stealthChop parameters
|
||||||
constexpr uint32_t pwmconf = config::tmc2130_PWM_AMPL | config::tmc2130_PWM_GRAD | config::tmc2130_PWM_FREQ | config::tmc2130_PWM_AUTOSCALE;
|
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);
|
||||||
WriteRegister(params, Registers::PWMCONF, pwmconf);
|
WriteRegister(params, Registers::PWMCONF, pwmconf);
|
||||||
|
|
||||||
/// TPWMTHRS: switching velocity between stealthChop and spreadCycle.
|
/// TPWMTHRS: switching velocity between stealthChop and spreadCycle.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue