From 537ae09f4287dd27fc94d76663f349c6e3c3f222 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Wed, 8 Mar 2023 10:17:19 +0100 Subject: [PATCH] Clean-up TMC SG trs setting in COOLCONF register --- src/hal/tmc2130.cpp | 15 +++++++++++---- tests/unit/logic/homing/test_homing.cpp | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/hal/tmc2130.cpp b/src/hal/tmc2130.cpp index bff75a1..c517765 100644 --- a/src/hal/tmc2130.cpp +++ b/src/hal/tmc2130.cpp @@ -264,15 +264,22 @@ void TMC2130::SetSGTHRS(const MotorParams ¶ms) { 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); } diff --git a/tests/unit/logic/homing/test_homing.cpp b/tests/unit/logic/homing/test_homing.cpp index 747caf2..6dacc0e 100644 --- a/tests/unit/logic/homing/test_homing.cpp +++ b/tests/unit/logic/homing/test_homing.cpp @@ -207,7 +207,7 @@ void AdaptiveIdlerHoming() { main_loop(); CHECK(mm::motion.CurPosition().v == mm::unitToSteps(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(config::idlerLimits.lenght); uint32_t sgChange = mm::unitToAxisUnit(config::idlerLimits.lenght - 15.0_deg).v;