Browse Source

更新TMC驱动代码

master
zhaohe 2 years ago
parent
commit
96b3421768
  1. 26
      components/tmc/basic/tmc_ic_interface.hpp
  2. 12
      components/tmc/ic/tmc_driver_ic.hpp
  3. 32
      components/tmc/ic/ztmc4361A.cpp
  4. 30
      components/tmc/ic/ztmc4361A.hpp

26
components/tmc/basic/tmc_ic_interface.hpp

@ -16,33 +16,33 @@ class IStepperMotor {
// virtual void registerListener(MotorEventListener* listener) = 0;
/****************************************************
* *
* *
****************************************************/
/**
* @brief 鸿
* @brief
*
* @param velocity pps
* @param velocity pps
*/
virtual void rotate(int32_t velocity) = 0;
/****************************************************
* *
* *
****************************************************/
/**
* @brief
* @brief
*
* @param position
* @param velocityMax ч pps
* @param position
* @param velocityMax pps
*/
virtual void moveTo(int32_t position, uint32_t velocityMax) = 0;
/**
* @brief 稿Щ
* @brief
*
* @param relativePosition 稿
* @param velocityMax ч pps
* @param relativePosition
* @param velocityMax pps
*/
virtual void moveBy(int32_t relativePosition, uint32_t velocityMax) = 0;
/**
* @brief
* @brief
*/
virtual void stop() = 0;
@ -54,8 +54,8 @@ class IStepperMotor {
virtual int32_t getENC_POS() = 0;
virtual void setENC_POS(int32_t value) = 0;
virtual void setAcceleration(float accelerationpps2) = 0; // 璁剧疆鏈€澶у姞閫熷害
virtual void setDeceleration(float accelerationpps2) = 0; // 璁剧疆鏈€澶у噺閫熷害
virtual void setAcceleration(float accelerationpps2) = 0; // 设置最大加速度
virtual void setDeceleration(float accelerationpps2) = 0; // 设置最大减速度
virtual bool isReachTarget() = 0;
virtual bool isStoped() = 0;

12
components/tmc/ic/tmc_driver_ic.hpp

@ -5,25 +5,25 @@ class TMCDriverICPort {
public:
public:
/**
* @brief
* @brief
*
* @param state
*/
virtual void TMCDriverICPort_setResetPinState(uint16_t channel, bool state) = 0;
/**
* @brief
* @brief 使
*
* @param state
*/
virtual void TMCDriverICPort_setENNPinState(uint16_t channel, bool state) = 0;
/**
* @brief us绾у埆寤舵椂鍑芥暟銆
* @brief us级别延时函数
*
* @param us
*/
virtual void TMCDriverICPort_sleepus(int32_t us) = 0;
/**
* @brief SPI璇诲啓鎺ュ彛
* @brief SPI读写接口
*
* @param data
* @param length
@ -45,9 +45,9 @@ class TMCDriverICInterface {
virtual void writeInt(uint8_t address, int32_t value) = 0;
virtual int32_t readInt(uint8_t address) = 0;
/**
* @brief
* @brief
*
* @return int32_t 樿0x30
* @return int32_t 0x30
*/
virtual int32_t readICVersion() = 0;

32
components/tmc/ic/ztmc4361A.cpp

@ -85,7 +85,7 @@ void TMC4361A::readWriteCover(uint8_t *data, size_t length) {
if (length > 4) writeDatagram(TMC4361A_COVER_HIGH_WR, bytes[7], bytes[6], bytes[5], bytes[4]);
writeDatagram(TMC4361A_COVER_LOW_WR, bytes[3], bytes[2], bytes[1], bytes[0]);
zchip_clock_early_delayus(10 * 1000);
zos_delay(10);
// Read the reply
if (length > 4) {
@ -118,9 +118,9 @@ TMC4361A::TMC4361A(/* args */) {
}
/**
* @brief
* MC-API涓tmc4361A_reset/restore鏃跺TMC-API涓
* ?
* ?
* TMC-API中的tmc4361A_reset/restore时候TMC-API中的方法会初始化整个芯片的寄存器
* ??
* ??
* @param state
*/
void TMC4361A::tmc4361AConfigCallback(ConfigState state) {}
@ -131,14 +131,14 @@ void TMC4361A::writeSubRegister(uint8_t address, uint32_t mask, uint32_t shift,
void TMC4361A::setAcceleration(float accelerationpps2) {
/**
* @brief
* TMC4361A_AMAX:ā
* TMC4361A_AMAX:使
*
* Frequency mode: [pulses per sec2]
* 22 digits and 2 decimal places: 250 mpps^2 ? AMAX ? 4 Mpps^2
* Direct mode: [ per clk cycle]
* a[ per clk_cycle]= AMAX / 2^37
* AMAX [pps2] = AMAX / 237 ? fCLK^2
* 22 digits and 2 decimal places: 250 mpps^2 ?? AMAX ?? 4 Mpps^2
* Direct mode: [?v per clk cycle]
* a[?v per clk_cycle]= AMAX / 2^37
* AMAX [pps2] = AMAX / 237 ?? fCLK^2
*/
int32_t acc = (int32_t)accelerationpps2;
@ -147,13 +147,13 @@ void TMC4361A::setAcceleration(float accelerationpps2) {
void TMC4361A::setDeceleration(float accelerationpps2) {
/**
* @brief
* TMC4361A_DMAX:ā
* TMC4361A_DMAX:使
*
* Frequency mode: [pulses per sec2]
* 22 digits and 2 decimal places: 250 mpps^2 ? AMAX ? 4 Mpps^2
* Direct mode: [ per clk cycle]
* a[ per clk_cycle]= AMAX / 2^37
* AMAX [pps2] = AMAX / 237 ? fCLK^2
* 22 digits and 2 decimal places: 250 mpps^2 ?? AMAX ?? 4 Mpps^2
* Direct mode: [?v per clk cycle]
* a[?v per clk_cycle]= AMAX / 2^37
* AMAX [pps2] = AMAX / 237 ?? fCLK^2
*/
int32_t acc = (int32_t)accelerationpps2;
@ -190,7 +190,7 @@ void TMC4361A::initialize(cfg_t *cfg) {
zchip_clock_early_delayus(300 * 1000);
zchip_clock_early_delayus(300 * 1000);
driverIC_setIHOLD_IRUN(1, 3, 0); // 娉ㄦ剰瑕佸厛璁剧疆IHOLD鍐嶈�缃甀RUN,鍚﹀垯鐢垫満璺戜笉璧锋潵
driverIC_setIHOLD_IRUN(1, 3, 0); // 注意要先设置IHOLD再设置IRUN,否则电机跑不起来
}
uint8_t TMC4361A::reset() {
// Pulse the low-active hardware reset pin
@ -200,7 +200,7 @@ uint8_t TMC4361A::reset() {
SET_PIN(m_resetPin, true);
/**
* @brief ?
* @brief ??
*
*/
for (uint32_t add = 0; add < TMC4361A_REGISTER_COUNT; add++) {

30
components/tmc/ic/ztmc4361A.hpp

@ -68,15 +68,15 @@ class TMC4361A : public IStepperMotor {
TMC4361A(/* args */);
/*******************************************************************************
* ? *
* ?? *
*******************************************************************************/
/**
* @brief 樿MC4361A閰嶇疆鍙傛暟,
* @brief TMC4361A配置参数,使
*
* :
* 1. ¤?
* 2. ?
* :
* 1. 使??
* 2. ??
* @param config
*/
@ -96,26 +96,26 @@ class TMC4361A : public IStepperMotor {
virtual int32_t getVACTUAL();
virtual int32_t getENC_POS();
virtual void setENC_POS(int32_t value);
virtual void setAcceleration(float accelerationpps2); // 璁剧疆鏈€澶у姞閫熷害
virtual void setDeceleration(float accelerationpps2); // 璁剧疆鏈€澶у噺閫熷害
virtual void setAcceleration(float accelerationpps2); // 设置最大加速度
virtual void setDeceleration(float accelerationpps2); // 设置最大减速度
/*******************************************************************************
* *
* *
*******************************************************************************/
/**
* @brief ?
* @brief ??
*
* @param channel SPI閫氶亾鍙?
* @param driver_ic_type ?
* @param channel SPI通道??
* @param driver_ic_type ??
*/
int32_t readICVersion();
uint8_t reset();
uint8_t restore();
/*******************************************************************************
* ? *
* ?? *
*******************************************************************************/
/*******************************************************************************
* *
* *
*******************************************************************************/
void writeDatagram(uint8_t address, uint8_t x1, uint8_t x2, uint8_t x3, uint8_t x4);
void writeInt(uint8_t address, int32_t value);
@ -123,8 +123,8 @@ class TMC4361A : public IStepperMotor {
void readWriteCover(uint8_t *data, size_t length);
void writeSubRegister(uint8_t address, uint32_t mask, uint32_t shift, uint32_t value);
int32_t getENC_POS_DEV(); // ENC_POS鍜孹ACTUAL鐨勫亸宸�€?
uint32_t readEVENTS(); // 璇诲彇浜嬩欢瀵勫瓨鍣?
int32_t getENC_POS_DEV(); // ENC_POS和XACTUAL的偏差??
uint32_t readEVENTS(); // 读取事件寄存??
/*******************************************************
* driverIc function *
*******************************************************/

Loading…
Cancel
Save