Browse Source

ztmc5130 add global scale

master
zhaohe 2 years ago
parent
commit
e70133f367
  1. 1
      components/step_motor_ctrl_module/step_motor_ctrl_module.cpp
  2. 19
      components/tmc/ic/ztmc5130.cpp
  3. 1
      components/tmc/ic/ztmc5130.hpp

1
components/step_motor_ctrl_module/step_motor_ctrl_module.cpp

@ -539,7 +539,6 @@ int32_t StepMotorCtrlModule::motor_move_by(int32_t dx, int32_t motor_velocity, i
}
int32_t StepMotorCtrlModule::motor_move_to(int32_t tox, int32_t motor_velocity, int32_t acc) {
zlock_guard lock(m_lock);
ZLOGI(TAG, "m%d motor_move_to %d", m_id, tox);
m_thread.stop();
if (m_param.min_d != 0 && tox < m_param.min_d) {

19
components/tmc/ic/ztmc5130.cpp

@ -146,8 +146,23 @@ void TMC5130::setAcceleration(float accelerationpps2) { writeInt(TMC5130_AMAX
void TMC5130::setDeceleration(float accelerationpps2) { writeInt(TMC5130_DMAX, (int32_t)(to_motor_acc(accelerationpps2))); } // ÉèÖÃ×î´ó¼õËÙ¶È
void TMC5130::setMotorShaft(bool reverse) { PRV_FIELD_WRITE(TMC5130_GCONF, TMC5130_SHAFT_MASK, TMC5130_SHAFT_SHIFT, reverse); }
void TMC5130::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)); }
void TMC5130::setGlobalScale(uint8_t globalscale) {
// writeInt(TMC5130_GCONF, (readInt(TMC5130_GCONF) & ~TMC5130_SCALE_MASK) | (globalscale << TMC5130_SCALE_SHIFT));
#define TMC5160_GLOBAL_SCALER 0x0B
#define TMC5160_GLOBAL_SCALER_MASK 0xFF
#define TMC5160_GLOBAL_SCALER_SHIFT 0
void TMC5130::setGlobalScale(uint8_t globalscale) { //
if (globalscale == 0) {
globalscale = 0;
} else if (globalscale <= 31 || globalscale >= 1) {
globalscale = 32;
} else {
globalscale = globalscale;
}
writeInt(TMC5160_GLOBAL_SCALER, (readInt(TMC5160_GLOBAL_SCALER) & ~TMC5160_GLOBAL_SCALER_MASK) | (globalscale << TMC5160_GLOBAL_SCALER_SHIFT));
}
uint8_t TMC5130::getGlobalScale() { //
return PRV_FIELD_READ(TMC5160_GLOBAL_SCALER, TMC5160_GLOBAL_SCALER_MASK, TMC5160_GLOBAL_SCALER_SHIFT);
}
uint32_t TMC5130::readICVersion() {

1
components/tmc/ic/ztmc5130.hpp

@ -127,6 +127,7 @@ class TMC5130 : public IStepperMotor {
void setIHOLD_IRUN(uint8_t ihold, uint8_t irun, uint16_t iholddelay);
void setGlobalScale(uint8_t globalscale);
uint8_t getGlobalScale();
// void setSubdivision(uint8_t subdivision);
void setMotorShaft(bool reverse); // 设置电机旋转方向

Loading…
Cancel
Save