diff --git a/components/tmc/basic/tmc_ic_interface.hpp b/components/tmc/basic/tmc_ic_interface.hpp index 0bf0ba5..359ecb3 100644 --- a/components/tmc/basic/tmc_ic_interface.hpp +++ b/components/tmc/basic/tmc_ic_interface.hpp @@ -67,4 +67,16 @@ class IStepperMotor { virtual void setNoAccLimit(bool enable){}; }; +typedef enum { + kmres_256 = 0x00, + kmres_128 = 0x01, + kmres_64 = 0x02, + kmres_32 = 0x03, + kmres_16 = 0x04, + kmres_8 = 0x05, + kmres_4 = 0x06, + kmres_2 = 0x07, + kmres_1 = 0x08, +} mres_type_t; + } // namespace iflytop \ No newline at end of file diff --git a/components/tmc/ic/ztmc5130.cpp b/components/tmc/ic/ztmc5130.cpp index 70aa154..0aa4b2f 100644 --- a/components/tmc/ic/ztmc5130.cpp +++ b/components/tmc/ic/ztmc5130.cpp @@ -62,7 +62,6 @@ void TMC5130::initialize(cfg_t *cfg) { writeInt(TMC5130_XACTUAL, 0x00000000); writeInt(TMC5130_VACTUAL, 0x00000000); - writeInt(TMC5130_VSTART, 100); writeInt(TMC5130_A1, 1000); writeInt(TMC5130_V1, 0); @@ -82,6 +81,33 @@ void TMC5130::initialize(cfg_t *cfg) { enableIC(true); } +void TMC5130::setMRES(mres_type_t value) { + PRV_FIELD_WRITE(TMC5130_CHOPCONF, TMC5130_MRES_MASK, TMC5130_MRES_SHIFT, value); + + m_MRES = value; + if (m_MRES == kmres_256) { + m_onecirclepulse = 51200; + } else if (m_MRES == kmres_128) { + m_onecirclepulse = 25600; + } else if (m_MRES == kmres_64) { + m_onecirclepulse = 12800; + } else if (m_MRES == kmres_32) { + m_onecirclepulse = 6400; + } else if (m_MRES == kmres_16) { + m_onecirclepulse = 3200; + } else if (m_MRES == kmres_8) { + m_onecirclepulse = 1600; + } else if (m_MRES == kmres_4) { + m_onecirclepulse = 800; + } else if (m_MRES == kmres_2) { + m_onecirclepulse = 400; + } else if (m_MRES == kmres_1) { + m_onecirclepulse = 200; + } else { + ZASSERT(false); + } +} + void TMC5130::setNoAccLimit(bool enable) { if (!enable) { writeInt(TMC5130_VSTART, 100); @@ -227,25 +253,28 @@ int32_t TMC5130::readInt(uint8_t address) { return ((uint32_t)data[1] << 24) | ((uint32_t)data[2] << 16) | (data[3] << 8) | data[4]; } int32_t TMC5130::to_motor_acc(int32_t acc) { // - int32_t val = acc / 60.0 * 51200; // 65535 - // if (val > 65535) val = 65535; + int32_t val = acc / 60.0 * m_onecirclepulse; // 65535 + if (val > 65535) val = 65535; return val; } int32_t TMC5130::to_motor_vel(int32_t vel) { // - int32_t val = vel / 60.0 * 51200; + int32_t val = vel / 60.0 * m_onecirclepulse; + if (val > 8388095 /*2^23-512*/) { + val = 8388095; + } return val; } // rpm int32_t TMC5130::to_motor_pos(int32_t pos) { // - int32_t val = pos * 1.0 / m_scale * m_scale_deceleration * 51200.0; + int32_t val = pos * 1.0 / m_scale * m_scale_deceleration * m_onecirclepulse; return val; } // int32_t TMC5130::to_user_pos(int32_t pos) { // - int32_t val = pos / 51200.0 * m_scale / m_scale_deceleration; + int32_t val = pos / m_onecirclepulse * m_scale / m_scale_deceleration; return val; } // int32_t TMC5130::to_user_vel(int32_t vel) { // - int32_t val = vel * 60.0 / 51200.0; + int32_t val = vel * 60.0 / m_onecirclepulse; return val; } #endif diff --git a/components/tmc/ic/ztmc5130.hpp b/components/tmc/ic/ztmc5130.hpp index 8676311..25136ea 100644 --- a/components/tmc/ic/ztmc5130.hpp +++ b/components/tmc/ic/ztmc5130.hpp @@ -91,7 +91,8 @@ class TMC5130 : public IStepperMotor { int32_t m_scale = 10000; int32_t m_scale_deceleration = 1; - // int32_t m_subdivision = 256; + mres_type_t m_MRES = kmres_256; + double m_onecirclepulse = 51200; public: TMC5130(/* args */); @@ -154,6 +155,13 @@ class TMC5130 : public IStepperMotor { void setNoAccLimit(bool enable) override; + /** + * @brief ÉèÖõç»úϸ·Ö + * + * @param value + */ + void setMRES(mres_type_t value); + private: uint32_t haspassedms(uint32_t now, uint32_t last); diff --git a/components/zprotocols/zcancmder_v2 b/components/zprotocols/zcancmder_v2 index 03d55df..0917377 160000 --- a/components/zprotocols/zcancmder_v2 +++ b/components/zprotocols/zcancmder_v2 @@ -1 +1 @@ -Subproject commit 03d55dfe5a8b9fbe0a070211c071e00460e184d0 +Subproject commit 0917377fb1b5afd33c4da50ddbfbfb9bdb574032