|
|
@ -202,69 +202,30 @@ void TMC4361A::init() { |
|
|
|
|
|
|
|
driverIC_writeInt(0x81, 0x07); |
|
|
|
driverIC_writeInt(0x80, 0x12200); |
|
|
|
driverIC_writeInt(0x90, 0x00071600); |
|
|
|
driverIC_writeInt(0x91, 0x0a); |
|
|
|
driverIC_writeInt(0x94, 200); |
|
|
|
driverIC_writeInt(0x95, 50); |
|
|
|
driverIC_writeInt(0xEE, 0x70025); |
|
|
|
driverIC_writeInt(0xF0, 0x404FF); |
|
|
|
driverIC_writeInt(0xEC, 0x03010223); |
|
|
|
driverIC_writeInt(0xED, 0x100a220); |
|
|
|
|
|
|
|
tmc4361_writeInt(0x24, 0); |
|
|
|
tmc4361_writeInt(0x21, 0); |
|
|
|
tmc4361_writeInt(0x37, 0); |
|
|
|
|
|
|
|
driverIC_writeInt(0x6D, 0x6d); |
|
|
|
driverIC_writeInt(0x6c, 0); |
|
|
|
|
|
|
|
#if 0
|
|
|
|
tmc4361_writeInt(0x54, 4000); // Encoder resolution = 4000/rev
|
|
|
|
tmc4361_writeInt(0x1C, 0xff00ff); // CL_BETA=CL_GAMMA=255
|
|
|
|
tmc4361_writeInt(0x5C, 0x10000); // cl_p = 1.0
|
|
|
|
|
|
|
|
// cl calibration:
|
|
|
|
tmc4361_writeInt(0x20, 0x06); // hold+pos mode
|
|
|
|
tmc4361_writeInt(0x24, 0x100000); // slow vel
|
|
|
|
tmc4361_writeInt(0x07, 0x400000); // turn on cl
|
|
|
|
tmc4361_writeInt(0x37, 0x80); // move to FS position
|
|
|
|
tmc4361_writeInt(0x07, 0x1400000); // turn on cl calibration
|
|
|
|
osDelay(100); |
|
|
|
tmc4361_writeInt(0x07, 0x400000); // turn off cl calibration
|
|
|
|
tmc4361_writeInt(0x24, 0); // v=0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// S-shaped Ramps setup:
|
|
|
|
tmc4361_writeInt(0x20, 0x06); // s-ramp + pos mode
|
|
|
|
tmc4361_writeInt(0x24, 0x31A8000); // vmax=800kpps
|
|
|
|
tmc4361_writeInt(0x28, 30000); // amax
|
|
|
|
tmc4361_writeInt(0x29, 15000); // dmax
|
|
|
|
tmc4361_writeInt(0x2D, 0x100); // bow1
|
|
|
|
tmc4361_writeInt(0x2E, 0x100); // bow2
|
|
|
|
tmc4361_writeInt(0x2F, 0x100); // bow3
|
|
|
|
tmc4361_writeInt(0x30, 0x100); // bow4
|
|
|
|
|
|
|
|
// cl operation setup:
|
|
|
|
#if 0
|
|
|
|
tmc4361_writeInt(0x60, 250000); // emf_vmin =
|
|
|
|
tmc4361_writeInt(0x61, 450000); // emf_vadd = -> emf_vmax =
|
|
|
|
tmc4361_writeInt(0x62, 0xffffff); // emf_vel0_timer
|
|
|
|
tmc4361_writeInt(0x63, 0x2000864); // enc vel filter settings
|
|
|
|
|
|
|
|
tmc4361_writeInt(0x5F, 5); // cl_tolerance=20
|
|
|
|
tmc4361_writeInt(0x5C, 0x10000); // cl_p=1.0
|
|
|
|
tmc4361_writeInt(0x5A, 3000); // cl_vlimit_p=200
|
|
|
|
tmc4361_writeInt(0x5B, 300); // cl_vlimit_i=50
|
|
|
|
tmc4361_writeInt(0x5D, 1000); // cl_vlimit_diclip=1000
|
|
|
|
tmc4361_writeInt(0x5E, 200000); // cl_vlimit=200kpps
|
|
|
|
|
|
|
|
tmc4361_writeInt(0x06, 0x32ff64); // cl scaling values
|
|
|
|
tmc4361_writeInt(0x18, 600); // cl_upscale=1000
|
|
|
|
tmc4361_writeInt(0x19, 200000); // cl_dnscale=10000
|
|
|
|
|
|
|
|
tmc4361_writeInt(0x07, 0xa400000); // cl with gamma correction and vlimit
|
|
|
|
tmc4361_writeInt(0x05, 0x80); // cl scaling on
|
|
|
|
#endif
|
|
|
|
driverIC_writeInt(0x90, 0x00070700); // ihold=20, iholddelay=5, irun=20
|
|
|
|
driverIC_writeInt(0x91, 0x0a); // TZEROWAIT=10
|
|
|
|
driverIC_writeInt(0x94, 200); // TCOOLTHRS
|
|
|
|
driverIC_writeInt(0x95, 50); // THIGH
|
|
|
|
driverIC_writeInt(0xEE, 0x70025); // DCCTRLSG=5, DC_TIME=37
|
|
|
|
driverIC_writeInt(0xF0, 0x404FF); // PWMCONF
|
|
|
|
driverIC_writeInt(0xEC, 0x00010223); // CHOPCONF
|
|
|
|
driverIC_writeInt(0xED, 0x100a220); // COOLCONF
|
|
|
|
driverIC_writeInt(0x8b, 0x00); // global scaler = 0
|
|
|
|
|
|
|
|
tmc4361_writeInt(0x24, 0); // v=0
|
|
|
|
tmc4361_writeInt(0x21, 0); // xact=0
|
|
|
|
tmc4361_writeInt(0x37, 0); // xtarg=0
|
|
|
|
|
|
|
|
tmc4361_writeInt(0x6D, 0x80); // GCONF
|
|
|
|
tmc4361_writeInt(0x6C, 0x00); // 0x12200 diag1=index, pushpull, direct_mode = off --> SD mode
|
|
|
|
|
|
|
|
tmc4361_writeInt(0x20, 0x06); // s-ramp + pos mode
|
|
|
|
tmc4361_writeInt(0x2D, 0x100); // bow1
|
|
|
|
tmc4361_writeInt(0x2E, 0x100); // bow2
|
|
|
|
tmc4361_writeInt(0x2F, 0x100); // bow3
|
|
|
|
tmc4361_writeInt(0x30, 0x100); // bow4
|
|
|
|
tmc4361_writeInt(TMC4361A_AMAX, 10000); // amax
|
|
|
|
tmc4361_writeInt(TMC4361A_DMAX, 10000); // dmax
|
|
|
|
} |
|
|
|
|
|
|
|
uint8_t TMC4361A::reset() { |
|
|
@ -279,41 +240,87 @@ uint8_t TMC4361A::reset() { |
|
|
|
zchip_clock_early_delayus(1000); |
|
|
|
tmc4361_writeInt(TMC4361A_RESET_REG, 0); |
|
|
|
|
|
|
|
init(); |
|
|
|
|
|
|
|
// 发送 0x4440128C to SPI_OUT_CONF 寄存器 0x04。
|
|
|
|
// 发送 0xEC 到 COVER_HIGH 寄存器 0x6D 及 0x000100C3 到 COVER_LOW 寄存器 0x6C。
|
|
|
|
// 发送 0x90 到 COVER_HIGH 寄存器 0x6D 及 0x00061F0A 到 COVER_LOW 寄存器 0x6C。
|
|
|
|
// 发送 0x91 到 COVER_HIGH 寄存器 0x6D 及 0x0000000A 到 COVER_LOW 寄存器 0x6C。
|
|
|
|
// 发送 0x80 到 COVER_HIGH 寄存器 0x6D 及 0x00000004 到 COVER_LOW 寄存器 0x6C。
|
|
|
|
// 发送 0x93 到 COVER_HIGH 寄存器 0x6D 及 0x000001F4 到 COVER_LOW 寄存器 0x6C。
|
|
|
|
#if 0
|
|
|
|
tmc4361_writeInt(0x04, 0x4440128C); |
|
|
|
|
|
|
|
tmc4361_writeInt(0x6D, 0xEC); |
|
|
|
tmc4361_writeInt(0x6C, 0x000100C3); |
|
|
|
|
|
|
|
tmc4361_writeInt(0x6D, 0x90); |
|
|
|
tmc4361_writeInt(0x6C, 0x00061F0A); |
|
|
|
|
|
|
|
tmc4361_writeInt(0x6D, 0x91); |
|
|
|
tmc4361_writeInt(0x6C, 0x0000000A); |
|
|
|
|
|
|
|
tmc4361_writeInt(0x6D, 0x80); |
|
|
|
tmc4361_writeInt(0x6C, 0x00000004); |
|
|
|
|
|
|
|
tmc4361_writeInt(0x6D, 0x93); |
|
|
|
tmc4361_writeInt(0x6C, 0x000001F4); |
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// 将 0x4440128D 发送至 SPI_OUT_CONF 寄存器 0x04。
|
|
|
|
// 发送 0x80 至 COVER_HIGH 寄存器 0x6D,发送 0x00010000 至 COVER_LOW 寄存器 0x6C。
|
|
|
|
// 发送 0xEC 至 COVER_HIGH 寄存器 0x6D,发送 0x000100C3 至 COVER_LOW 寄存器 0x6C。
|
|
|
|
// 发送 0x90 至 COVER_HIGH 寄存器 0x6D,发送 0x00000A0A 至 COVER_LOW 寄存器 0x6C。
|
|
|
|
tmc4361_writeInt(0x04, 0x4440128D); |
|
|
|
|
|
|
|
tmc4361_writeInt(0x6D, 0x80); |
|
|
|
tmc4361_writeInt(0x6C, 0x00010000); |
|
|
|
|
|
|
|
tmc4361_writeInt(0x6D, 0xEC); |
|
|
|
tmc4361_writeInt(0x6C, 0x000100C3); |
|
|
|
|
|
|
|
tmc4361_writeInt(0x6D, 0x90); |
|
|
|
tmc4361_writeInt(0x6C, 0x00000A0A); |
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/**
|
|
|
|
* @brief 重置芯片镜像寄存?? |
|
|
|
* |
|
|
|
*/ |
|
|
|
// for (uint32_t add = 0; add < TMC4361A_REGISTER_COUNT; add++) {
|
|
|
|
// if (!TMC_IS_RESETTABLE(m_registerAccessTable[add])) {
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
// tmc4361_writeInt(add, m_defaultRegisterResetState[add]);
|
|
|
|
// }
|
|
|
|
for (uint32_t add = 0; add < TMC4361A_REGISTER_COUNT; add++) { |
|
|
|
if (!TMC_IS_RESETTABLE(m_registerAccessTable[add])) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
tmc4361_writeInt(add, m_defaultRegisterResetState[add]); |
|
|
|
} |
|
|
|
|
|
|
|
init(); |
|
|
|
// init();
|
|
|
|
|
|
|
|
// uint8_t driver, dataLength;
|
|
|
|
// uint32_t value;
|
|
|
|
// // Setup SPI
|
|
|
|
// switch (m_driver_ic_type) {
|
|
|
|
// case IC_TMC2130:
|
|
|
|
// case IC_TMC2160:
|
|
|
|
// driver = 0x0C;
|
|
|
|
// dataLength = 0;
|
|
|
|
// break;
|
|
|
|
// case IC_TMC2660:
|
|
|
|
// driver = 0x0B;
|
|
|
|
// dataLength = 0;
|
|
|
|
// break;
|
|
|
|
// default:
|
|
|
|
// driver = 0x0F;
|
|
|
|
// dataLength = 40;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// value = 0x44400040 | (dataLength << 13) | (driver << 0);
|
|
|
|
// tmc4361_writeInt(TMC4361A_SPIOUT_CONF, value);
|
|
|
|
// tmc4361_writeInt(TMC4361A_CURRENT_CONF, 0x00000003);
|
|
|
|
// tmc4361_writeInt(TMC4361A_SCALE_VALUES, 0x00000000);
|
|
|
|
uint8_t driver, dataLength; |
|
|
|
uint32_t value; |
|
|
|
// Setup SPI
|
|
|
|
switch (m_driver_ic_type) { |
|
|
|
case IC_TMC2130: |
|
|
|
case IC_TMC2160: |
|
|
|
driver = 0x0C; |
|
|
|
dataLength = 0; |
|
|
|
break; |
|
|
|
case IC_TMC2660: |
|
|
|
driver = 0x0B; |
|
|
|
dataLength = 0; |
|
|
|
break; |
|
|
|
default: |
|
|
|
driver = 0x0F; |
|
|
|
dataLength = 40; |
|
|
|
break; |
|
|
|
} |
|
|
|
value = 0x44400040 | (dataLength << 13) | (driver << 0); |
|
|
|
tmc4361_writeInt(TMC4361A_SPIOUT_CONF, value); |
|
|
|
tmc4361_writeInt(TMC4361A_CURRENT_CONF, 0x00000003); |
|
|
|
tmc4361_writeInt(TMC4361A_SCALE_VALUES, 0x00000000); |
|
|
|
#endif
|
|
|
|
return 1; |
|
|
|
} |
|
|
|
uint8_t TMC4361A::restore() { return 1; } |
|
|
|