|
@ -28,7 +28,9 @@ static const uint8_t tmc5130_defaultRegisterAccess[TMC5130_REGISTER_COUNT] = { |
|
|
0x42, 0x01, 0x02, 0x01, ____, ____, ____, ____, ____, ____, ____, ____, ____, ____, ____, ____ // 0x70 - 0x7F
|
|
|
0x42, 0x01, 0x02, 0x01, ____, ____, ____, ____, ____, ____, ____, ____, ____, ____, ____, ____ // 0x70 - 0x7F
|
|
|
}; |
|
|
}; |
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#define TMC5160_GLOBAL_SCALER 0x0B
|
|
|
|
|
|
#define TMC5160_GLOBAL_SCALER_MASK 0xFF
|
|
|
|
|
|
#define TMC5160_GLOBAL_SCALER_SHIFT 0
|
|
|
/***********************************************************************************************************************
|
|
|
/***********************************************************************************************************************
|
|
|
* 工具�? * |
|
|
* 工具�? * |
|
|
***********************************************************************************************************************/ |
|
|
***********************************************************************************************************************/ |
|
@ -57,6 +59,25 @@ void TMC51X0::initialize(int mid, TMC51X0Cfg cfg) { |
|
|
|
|
|
|
|
|
stop(); |
|
|
stop(); |
|
|
|
|
|
|
|
|
|
|
|
ZASSERT(m_cache.activeReg(TMC5130_CHOPCONF)); |
|
|
|
|
|
ZASSERT(m_cache.activeReg(TMC5130_PWMCONF)); |
|
|
|
|
|
ZASSERT(m_cache.activeReg(TMC5130_GCONF)); |
|
|
|
|
|
ZASSERT(m_cache.activeReg(TMC5130_IHOLD_IRUN)); |
|
|
|
|
|
ZASSERT(m_cache.activeReg(TMC5160_GLOBAL_SCALER)); |
|
|
|
|
|
|
|
|
|
|
|
ZASSERT(m_cache.activeReg(TMC5130_VMAX)); |
|
|
|
|
|
ZASSERT(m_cache.activeReg(TMC5130_VSTART)); |
|
|
|
|
|
ZASSERT(m_cache.activeReg(TMC5130_A1)); |
|
|
|
|
|
ZASSERT(m_cache.activeReg(TMC5130_AMAX)); |
|
|
|
|
|
ZASSERT(m_cache.activeReg(TMC5130_V1)); |
|
|
|
|
|
ZASSERT(m_cache.activeReg(TMC5130_DMAX)); |
|
|
|
|
|
ZASSERT(m_cache.activeReg(TMC5130_D1)); |
|
|
|
|
|
ZASSERT(m_cache.activeReg(TMC5130_VSTOP)); |
|
|
|
|
|
ZASSERT(m_cache.activeReg(TMC5130_TZEROWAIT)); |
|
|
|
|
|
ZASSERT(m_cache.activeReg(TMC5130_ENCMODE)); |
|
|
|
|
|
ZASSERT(m_cache.activeReg(TMC5130_ENC_CONST)); |
|
|
|
|
|
ZASSERT(m_cache.activeReg(TMC5130_XENC)); |
|
|
|
|
|
|
|
|
writeInt(TMC5130_PWMCONF, 0x000500C8); |
|
|
writeInt(TMC5130_PWMCONF, 0x000500C8); |
|
|
writeInt(TMC5130_CHOPCONF, 0x000100c3); |
|
|
writeInt(TMC5130_CHOPCONF, 0x000100c3); |
|
|
writeInt(TMC5130_IHOLD_IRUN, 0x00051A00); |
|
|
writeInt(TMC5130_IHOLD_IRUN, 0x00051A00); |
|
@ -67,11 +88,11 @@ void TMC51X0::initialize(int mid, TMC51X0Cfg cfg) { |
|
|
writeInt(TMC5130_TZEROWAIT, 0); |
|
|
writeInt(TMC5130_TZEROWAIT, 0); |
|
|
|
|
|
|
|
|
setVstart(100); |
|
|
setVstart(100); |
|
|
setA1(30); |
|
|
|
|
|
setAmax(50); |
|
|
|
|
|
|
|
|
setA1(15); |
|
|
|
|
|
setAmax(15); |
|
|
setV1(500); |
|
|
setV1(500); |
|
|
setDmax(50); |
|
|
|
|
|
setD1(30); |
|
|
|
|
|
|
|
|
setDmax(15); |
|
|
|
|
|
setD1(15); |
|
|
setVstop(100); |
|
|
setVstop(100); |
|
|
setTzerowait(100); |
|
|
setTzerowait(100); |
|
|
|
|
|
|
|
@ -79,6 +100,13 @@ void TMC51X0::initialize(int mid, TMC51X0Cfg cfg) { |
|
|
enable(false); |
|
|
enable(false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TMC51X0::refreshcfg() { |
|
|
|
|
|
m_cache.foreach ([this](TMCReg *item) { |
|
|
|
|
|
ZLOGI(TAG, "refreshcfg %x,%x", item->reg, item->val); |
|
|
|
|
|
writeInt(item->reg, item->val); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
/*******************************************************************************
|
|
|
* 驱动器寄存器读写方法 * |
|
|
* 驱动器寄存器读写方法 * |
|
|
*******************************************************************************/ |
|
|
*******************************************************************************/ |
|
@ -95,6 +123,7 @@ void TMC51X0::writeDatagram(uint8_t address, uint8_t x1, uint8_t x2, uint8_t x3, |
|
|
readWriteArray(&data[0], 5); |
|
|
readWriteArray(&data[0], 5); |
|
|
} |
|
|
} |
|
|
void TMC51X0::writeInt(uint8_t address, int32_t value) { //
|
|
|
void TMC51X0::writeInt(uint8_t address, int32_t value) { //
|
|
|
|
|
|
m_cache.setReg(address, value); |
|
|
writeDatagram(address, BYTE(value, 3), BYTE(value, 2), BYTE(value, 1), BYTE(value, 0)); |
|
|
writeDatagram(address, BYTE(value, 3), BYTE(value, 2), BYTE(value, 1), BYTE(value, 0)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -187,6 +216,8 @@ void TMC51X0::stop() { |
|
|
} else { |
|
|
} else { |
|
|
rotate(0); |
|
|
rotate(0); |
|
|
} |
|
|
} |
|
|
|
|
|
m_isMoveToEnd = false; |
|
|
|
|
|
// rotate(0);
|
|
|
} |
|
|
} |
|
|
void TMC51X0::rotate(int32_t velocity) { |
|
|
void TMC51X0::rotate(int32_t velocity) { |
|
|
zlock_guard lkg(m_mutex); |
|
|
zlock_guard lkg(m_mutex); |
|
@ -194,6 +225,7 @@ void TMC51X0::rotate(int32_t velocity) { |
|
|
velocity = to_motor_vel(velocity); |
|
|
velocity = to_motor_vel(velocity); |
|
|
writeInt(TMC5130_VMAX, abs(velocity)); |
|
|
writeInt(TMC5130_VMAX, abs(velocity)); |
|
|
writeInt(TMC5130_RAMPMODE, (velocity >= 0) ? TMC5130_MODE_VELPOS : TMC5130_MODE_VELNEG); |
|
|
writeInt(TMC5130_RAMPMODE, (velocity >= 0) ? TMC5130_MODE_VELPOS : TMC5130_MODE_VELNEG); |
|
|
|
|
|
m_isMoveToEnd = false; |
|
|
} |
|
|
} |
|
|
void TMC51X0::moveTo(int32_t position, uint32_t velocityMax) { |
|
|
void TMC51X0::moveTo(int32_t position, uint32_t velocityMax) { |
|
|
zlock_guard lkg(m_mutex); |
|
|
zlock_guard lkg(m_mutex); |
|
@ -203,10 +235,15 @@ void TMC51X0::moveTo(int32_t position, uint32_t velocityMax) { |
|
|
writeInt(TMC5130_RAMPMODE, TMC5130_MODE_POSITION); |
|
|
writeInt(TMC5130_RAMPMODE, TMC5130_MODE_POSITION); |
|
|
writeInt(TMC5130_VMAX, velocityMax); |
|
|
writeInt(TMC5130_VMAX, velocityMax); |
|
|
writeInt(TMC5130_XTARGET, position); |
|
|
writeInt(TMC5130_XTARGET, position); |
|
|
|
|
|
m_isMoveToEnd = false; |
|
|
} |
|
|
} |
|
|
void TMC51X0::moveToEnd(int32_t direction, uint32_t velocityMax) { |
|
|
void TMC51X0::moveToEnd(int32_t direction, uint32_t velocityMax) { |
|
|
zlock_guard lkg(m_mutex); |
|
|
zlock_guard lkg(m_mutex); |
|
|
|
|
|
|
|
|
|
|
|
// @WARNING:
|
|
|
|
|
|
// the motor will stop running(1000RPM) for about 10 minutes
|
|
|
|
|
|
// If you really need to use this feature, reset XACTUAL every 30s
|
|
|
|
|
|
setXACTUAL(0); |
|
|
if (direction >= 0) { |
|
|
if (direction >= 0) { |
|
|
writeInt(TMC5130_RAMPMODE, TMC5130_MODE_POSITION); |
|
|
writeInt(TMC5130_RAMPMODE, TMC5130_MODE_POSITION); |
|
|
writeInt(TMC5130_VMAX, to_motor_vel(velocityMax)); |
|
|
writeInt(TMC5130_VMAX, to_motor_vel(velocityMax)); |
|
@ -216,8 +253,12 @@ void TMC51X0::moveToEnd(int32_t direction, uint32_t velocityMax) { |
|
|
writeInt(TMC5130_VMAX, to_motor_vel(velocityMax)); |
|
|
writeInt(TMC5130_VMAX, to_motor_vel(velocityMax)); |
|
|
writeInt(TMC5130_XTARGET, INT32_MIN / 1.5 + 1000); |
|
|
writeInt(TMC5130_XTARGET, INT32_MIN / 1.5 + 1000); |
|
|
} |
|
|
} |
|
|
|
|
|
m_isMoveToEnd = true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TMC51X0::refreshMoveToEnd() { setXACTUAL(0); } |
|
|
|
|
|
bool TMC51X0::isMoveToEnd() { return m_isMoveToEnd; } |
|
|
|
|
|
|
|
|
void TMC51X0::moveBy(int32_t relativePosition, uint32_t velocityMax) { // determine actual position and add numbers of ticks to move
|
|
|
void TMC51X0::moveBy(int32_t relativePosition, uint32_t velocityMax) { // determine actual position and add numbers of ticks to move
|
|
|
zlock_guard lkg(m_mutex); |
|
|
zlock_guard lkg(m_mutex); |
|
|
|
|
|
|
|
@ -322,9 +363,6 @@ void TMC51X0::setIHOLD_IRUN(uint8_t ihold, uint8_t irun, uint16_t iholddelay) { |
|
|
writeInt(TMC5130_IHOLD_IRUN, (iholddelay << TMC5130_IHOLDDELAY_SHIFT) | (irun << TMC5130_IRUN_SHIFT) | (ihold << TMC5130_IHOLD_SHIFT)); |
|
|
writeInt(TMC5130_IHOLD_IRUN, (iholddelay << TMC5130_IHOLDDELAY_SHIFT) | (irun << TMC5130_IRUN_SHIFT) | (ihold << TMC5130_IHOLD_SHIFT)); |
|
|
} |
|
|
} |
|
|
void TMC51X0::setGlobalScale(uint8_t globalscale) { |
|
|
void TMC51X0::setGlobalScale(uint8_t globalscale) { |
|
|
#define TMC5160_GLOBAL_SCALER 0x0B
|
|
|
|
|
|
#define TMC5160_GLOBAL_SCALER_MASK 0xFF
|
|
|
|
|
|
#define TMC5160_GLOBAL_SCALER_SHIFT 0
|
|
|
|
|
|
zlock_guard lkg(m_mutex); |
|
|
zlock_guard lkg(m_mutex); |
|
|
if (isTMC5130()) { |
|
|
if (isTMC5130()) { |
|
|
return; |
|
|
return; |
|
|