Clean-up TMC SG trs setting in COOLCONF register

pull/266/head
D.R.racer 2023-03-08 10:17:19 +01:00
parent f4aaff98c8
commit 537ae09f42
2 changed files with 12 additions and 5 deletions

View File

@ -264,15 +264,22 @@ void TMC2130::SetSGTHRS(const MotorParams &params) {
union SGTHRSU {
struct __attribute__((packed)) S {
uint16_t zero;
uint16_t sgthrs;
constexpr S(uint16_t sgthrs)
int8_t sgthrs : 7;
uint8_t reserved : 1;
uint8_t sfilt : 1;
uint8_t reserved1 : 7;
constexpr explicit S(int8_t sgthrs)
: zero(0)
, sgthrs(sgthrs) {}
, sgthrs(sgthrs)
, reserved(0)
, sfilt(0)
, reserved1(0) {}
} s;
uint32_t dw;
constexpr SGTHRSU(uint16_t sgthrs)
constexpr explicit SGTHRSU(int8_t sgthrs)
: s(sgthrs) {}
};
static_assert(sizeof(SGTHRSU) == 4);
//uint32_t tmc2130_coolConf = (((uint32_t)params.sg_thrs) << 16U);
WriteRegister(params, Registers::COOLCONF, SGTHRSU(params.sg_thrs).dw);
}

View File

@ -207,7 +207,7 @@ void AdaptiveIdlerHoming() {
main_loop();
CHECK(mm::motion.CurPosition<mm::Idler>().v == mm::unitToSteps<mm::I_pos_t>(config::IdlerOffsetFromHome) + 1); // magic constant just to tune the motor steps
CHECK(mi::idler.axisStart == config::IdlerOffsetFromHome.v + 2);
CHECK(mm::axes[mm::Idler].sg_thrs == 32767); // @@TODO sg_thrs is int8_t by default
CHECK(mm::axes[mm::Idler].sg_thrs == 63);
// do exact number of steps before triggering SG
uint32_t idlerSteps = mm::unitToSteps<mm::I_pos_t>(config::idlerLimits.lenght);
uint32_t sgChange = mm::unitToAxisUnit<mm::I_pos_t>(config::idlerLimits.lenght - 15.0_deg).v;