|
|
@ -141,8 +141,8 @@ void TMC4361A::setAcceleration(float accelerationpps2) { |
|
|
|
* AMAX [pps2] = AMAX / 237 ?? fCLK^2 |
|
|
|
*/ |
|
|
|
|
|
|
|
accelerationpps2 *= m_scale; |
|
|
|
int32_t acc = (int32_t)accelerationpps2; |
|
|
|
accelerationpps2 = to_motor_acc(accelerationpps2); |
|
|
|
int32_t acc = (int32_t)accelerationpps2; |
|
|
|
writeInt(TMC4361A_AMAX, acc << 2); |
|
|
|
} |
|
|
|
void TMC4361A::setDeceleration(float accelerationpps2) { |
|
|
@ -156,8 +156,8 @@ void TMC4361A::setDeceleration(float accelerationpps2) { |
|
|
|
* a[?v per clk_cycle]= AMAX / 2^37 |
|
|
|
* AMAX [pps2] = AMAX / 237 ?? fCLK^2 |
|
|
|
*/ |
|
|
|
accelerationpps2 *= m_scale; |
|
|
|
int32_t acc = (int32_t)accelerationpps2; |
|
|
|
accelerationpps2 = to_motor_acc(accelerationpps2); |
|
|
|
int32_t acc = (int32_t)accelerationpps2; |
|
|
|
writeInt(TMC4361A_DMAX, acc << 2); |
|
|
|
} |
|
|
|
#define INIT_GPIO(m_pin, pin, ...) \
|
|
|
@ -201,7 +201,7 @@ void TMC4361A::initialize(cfg_t *cfg) { |
|
|
|
driverIC_setIHOLD_IRUN(1, 3, 0); |
|
|
|
} |
|
|
|
|
|
|
|
void TMC4361A::setScale(float scale) { m_scale = scale; } |
|
|
|
void TMC4361A::setScale(int32_t scale) { m_scale = scale; } |
|
|
|
|
|
|
|
uint8_t TMC4361A::reset() { |
|
|
|
// Pulse the low-active hardware reset pin
|
|
|
@ -247,13 +247,13 @@ uint8_t TMC4361A::reset() { |
|
|
|
} |
|
|
|
uint8_t TMC4361A::restore() { return 1; } |
|
|
|
|
|
|
|
int32_t TMC4361A::getXACTUAL() { return readInt(TMC4361A_XACTUAL) / m_scale; } |
|
|
|
void TMC4361A::setXACTUAL(int32_t value) { writeInt(TMC4361A_XACTUAL, value * m_scale); } |
|
|
|
int32_t TMC4361A::getVACTUAL() { return readInt(TMC4361A_VACTUAL) / m_scale; } |
|
|
|
int32_t TMC4361A::getXTARGET() { return readInt(TMC4361A_X_TARGET) / m_scale; } |
|
|
|
int32_t TMC4361A::getENC_POS() { return readInt(TMC4361A_ENC_POS) / m_scale; } |
|
|
|
void TMC4361A::setENC_POS(int32_t value) { writeInt(TMC4361A_ENC_POS, value * m_scale); } |
|
|
|
int32_t TMC4361A::getENC_POS_DEV() { return readInt(TMC4361A_ENC_POS_DEV_RD) / m_scale; } |
|
|
|
int32_t TMC4361A::getXACTUAL() { return to_user_pos(readInt(TMC4361A_XACTUAL)); } |
|
|
|
void TMC4361A::setXACTUAL(int32_t value) { writeInt(TMC4361A_XACTUAL, to_motor_pos(value)); } |
|
|
|
int32_t TMC4361A::getVACTUAL() { return to_user_pos(readInt(TMC4361A_VACTUAL)); } |
|
|
|
int32_t TMC4361A::getXTARGET() { return to_user_pos(readInt(TMC4361A_X_TARGET)); } |
|
|
|
int32_t TMC4361A::getENC_POS() { return to_user_pos(readInt(TMC4361A_ENC_POS)); } |
|
|
|
void TMC4361A::setENC_POS(int32_t value) { writeInt(TMC4361A_ENC_POS, to_motor_pos(value)); } |
|
|
|
int32_t TMC4361A::getENC_POS_DEV() { return to_user_pos(readInt(TMC4361A_ENC_POS_DEV_RD)); } |
|
|
|
void TMC4361A::enableIC(bool enable) { |
|
|
|
SET_PIN(m_ennPin, !enable); |
|
|
|
SET_PIN(m_driverIC_ennPin, !enable); |
|
|
@ -266,15 +266,19 @@ int32_t tmc4361A_discardVelocityDecimals(int32_t value) { |
|
|
|
return value << 8; |
|
|
|
} |
|
|
|
void TMC4361A::rotate(int32_t velocity) { |
|
|
|
velocity *= m_scale; |
|
|
|
// velocity *= m_scale;
|
|
|
|
velocity = to_motor_vel(velocity); |
|
|
|
m_motor_mode = kvelmode; |
|
|
|
PRV_FIELD_WRITE(TMC4361A_RAMPMODE, TMC4361A_OPERATION_MODE_MASK, TMC4361A_OPERATION_MODE_SHIFT, 0); |
|
|
|
writeInt(TMC4361A_VMAX, tmc4361A_discardVelocityDecimals(velocity)); |
|
|
|
} |
|
|
|
void TMC4361A::stop() { rotate(0); } |
|
|
|
void TMC4361A::moveTo(int32_t position, uint32_t velocityMax) { |
|
|
|
position *= m_scale; |
|
|
|
velocityMax *= m_scale; |
|
|
|
// position *= m_scale;
|
|
|
|
// velocityMax *= m_scale;
|
|
|
|
|
|
|
|
position = to_motor_pos(position); |
|
|
|
velocityMax = to_motor_vel(velocityMax); |
|
|
|
|
|
|
|
m_motor_mode = kposmode; |
|
|
|
PRV_FIELD_WRITE(TMC4361A_RAMPMODE, TMC4361A_OPERATION_MODE_MASK, TMC4361A_OPERATION_MODE_SHIFT, 1); |
|
|
@ -387,6 +391,28 @@ void TMC4361A::setRightVirtualLimitSwitch(bool enable, int32_t position) { |
|
|
|
writeInt(TMC4361A_VIRT_STOP_RIGHT, position); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t TMC4361A::to_motor_acc(int32_t acc) { //
|
|
|
|
int32_t val = acc / 60.0 * 51200; |
|
|
|
return val; |
|
|
|
} |
|
|
|
int32_t TMC4361A::to_motor_vel(int32_t vel) { //
|
|
|
|
int32_t val = vel / 60.0 * 51200; |
|
|
|
return val; |
|
|
|
} // rpm
|
|
|
|
int32_t TMC4361A::to_motor_pos(int32_t pos) { //
|
|
|
|
int32_t val = pos * 1.0 / m_scale * 51200.0; |
|
|
|
return val; |
|
|
|
} //
|
|
|
|
|
|
|
|
int32_t TMC4361A::to_user_pos(int32_t pos) { //
|
|
|
|
int32_t val = pos / 51200.0 * m_scale; |
|
|
|
return 0; |
|
|
|
} //
|
|
|
|
int32_t TMC4361A::to_user_vel(int32_t vel) { //
|
|
|
|
int32_t val = vel * 60.0 / 51200.0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|