|
dSPIN_Regs_Struct_Reset(&dSPIN_RegsStruct);
/* Acceleration rate settings to dSPIN_CONF_PARAM_ACC in steps/s2, range 14.55 to 59590 steps/s2 */
dSPIN_RegsStruct.ACC = AccDec_Steps_to_Par(600);
/* Deceleration rate settings to dSPIN_CONF_PARAM_DEC in steps/s2, range 14.55 to 59590 steps/s2 */
dSPIN_RegsStruct.DEC = AccDec_Steps_to_Par(600);
/* Maximum speed settings to dSPIN_CONF_PARAM_MAX_SPEED in steps/s, range 15.25 to 15610 steps/s */
dSPIN_RegsStruct.MAX_SPEED = MaxSpd_Steps_to_Par(3000);
/* Full step speed settings dSPIN_CONF_PARAM_FS_SPD in steps/s, range 7.63 to 15625 steps/s */
dSPIN_RegsStruct.FS_SPD = FSSpd_Steps_to_Par(800);
#if defined(L6470)
/* Minimum spe4ed settings to dSPIN_CONF_PARAM_MIN_SPEED in steps/s, range 0 to 976.3 steps/s */
dSPIN_RegsStruct.MIN_SPEED = MinSpd_Steps_to_Par(0);
/* Acceleration duty cycle (torque) settings to dSPIN_CONF_PARAM_KVAL_ACC in %, range 0 to 99.6% */
dSPIN_RegsStruct.KVAL_ACC = Kval_Perc_to_Par(10);
/* Deceleration duty cycle (torque) settings to dSPIN_CONF_PARAM_KVAL_DEC in %, range 0 to 99.6% */
dSPIN_RegsStruct.KVAL_DEC = Kval_Perc_to_Par(10);
/* Run duty cycle (torque) settings to dSPIN_CONF_PARAM_KVAL_RUN in %, range 0 to 99.6% */
dSPIN_RegsStruct.KVAL_RUN = Kval_Perc_to_Par(10);
/* Hold duty cycle (torque) settings to dSPIN_CONF_PARAM_KVAL_HOLD in %, range 0 to 99.6% */
dSPIN_RegsStruct.KVAL_HOLD =Kval_Perc_to_Par(5);
/* Thermal compensation param settings to dSPIN_CONF_PARAM_K_THERM, range 1 to 1.46875 */
dSPIN_RegsStruct.K_THERM = KTherm_to_Par(1);
/* Intersect speed settings for BEMF compensation to dSPIN_CONF_PARAM_INT_SPD in steps/s, range 0 to 3906 steps/s */
dSPIN_RegsStruct.INT_SPD = IntSpd_Steps_to_Par(200);
/* BEMF start slope settings for BEMF compensation to dSPIN_CONF_PARAM_ST_SLP in % step/s, range 0 to 0.4% s/step */
dSPIN_RegsStruct.ST_SLP = BEMF_Slope_Perc_to_Par(0.038);
/* BEMF final acc slope settings for BEMF compensation to dSPIN_CONF_PARAM_FN_SLP_ACC in% step/s, range 0 to 0.4% s/step */
dSPIN_RegsStruct.FN_SLP_ACC = BEMF_Slope_Perc_to_Par(0.063);
/* BEMF final dec slope settings for BEMF compensation to dSPIN_CONF_PARAM_FN_SLP_DEC in% step/s, range 0 to 0.4% s/step */
dSPIN_RegsStruct.FN_SLP_DEC = BEMF_Slope_Perc_to_Par(0.063);
/* Stall threshold settings to dSPIN_CONF_PARAM_STALL_TH in mA, range 31.25 to 4000mA */
dSPIN_RegsStruct.STALL_TH = StallTh_to_Par(1500);//StallTh_to_Par(3000);//StallTh_to_Par(dSPIN_CONF_PARAM_STALL_TH);
/* Set Config register according to config parameters */
/* clock setting, switch hard stop interrupt mode, */
/* supply voltage compensation, overcurrent shutdown */
/* slew-rate , PWM frequency */
dSPIN_RegsStruct.CONFIG = (uint16_t)dSPIN_CONF_PARAM_CLOCK_SETTING |
(uint16_t)dSPIN_CONF_PARAM_SW_MODE |
(uint16_t)dSPIN_CONF_PARAM_VS_COMP |
(uint16_t)dSPIN_CONF_PARAM_OC_SD |
(uint16_t)dSPIN_CONF_PARAM_SR |
(uint16_t)dSPIN_CONF_PARAM_PWM_DIV |
(uint16_t)dSPIN_CONF_PARAM_PWM_MUL;
#endif /* defined(L6470) */
/* Overcurrent threshold settings to dSPIN_CONF_PARAM_OCD_TH in mA */
dSPIN_RegsStruct.OCD_TH = dSPIN_OCD_TH_1500mA;
/* Alarm settings to dSPIN_CONF_PARAM_ALARM_EN */
dSPIN_RegsStruct.ALARM_EN = dSPIN_CONF_PARAM_ALARM_EN;
/* Step mode and sycn mode settings via dSPIN_CONF_PARAM_SYNC_MODE and dSPIN_CONF_PARAM_STEP_MODE */
dSPIN_RegsStruct.STEP_MODE = dSPIN_STEP_SEL_1_128;
/* Program all dSPIN registers */
dSPIN_Registers_Set(&dSPIN_RegsStruct);
dSPIN_Move(FWD, (uint32_t)(10000));
while(dSPIN_Busy_HW());
dSPIN_Run(REV, Speed_Steps_to_Par(400));
dSPIN_Delay(0x004FFFFF);
dSPIN_Hard_Stop();
dSPIN_Move(FWD, (uint32_t)(10000));
while(dSPIN_Busy_HW());
GPIO_SetBits(GPIOE,GPIO_Pin_5);
while(1);
使用官方的程序,如果只执行 move指令,电机运行没有问题。
dSPIN_Move(FWD, (uint32_t)(10000));
while(dSPIN_Busy_HW());
但是如果如上执行一个move指令,在执行一个RUN指令,在执行一个MOVE指令后,电机就一直转,且方向也不会变。
|
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|