【本文发布于https://blog.csdn.net/Stack_/article/details/132236329,未经允许不得转载,转载须注明出处】
双极性步进电机(两相四线步进电机),原理的东西就先不讲太多了,还没搞清楚,边查资料边写代码来理解吧。
此电路使用4片CMS6324去驱动2个H桥,每片CMS6324驱动的桥的同一侧,其自带硬件死区,所以不需要考虑死区插入的问题。如果不是这样的电路,则需要注意上下桥臂同时导通短路的问题。
一、电机基本原理图 内部简化图
二、简单的驱动代码
#define MOTOR_A_P_PORT PORT1 //P15 A+
#define MOTOR_A_P_PIN PIN5#define MOTOR_A_N_PORT PORT1 //P14 A-
#define MOTOR_A_N_PIN PIN4#define MOTOR_B_P_PORT PORT1 //P13 B+
#define MOTOR_B_P_PIN PIN3#define MOTOR_B_N_PORT PORT1 //P12 B-
#define MOTOR_B_N_PIN PIN2#define MOTOR_A_P__SET() PORT_SetBit(MOTOR_A_P_PORT, MOTOR_A_P_PIN)
#define MOTOR_A_P__RESET() PORT_ClrBit(MOTOR_A_P_PORT, MOTOR_A_P_PIN)#define MOTOR_A_N__SET() PORT_SetBit(MOTOR_A_N_PORT, MOTOR_A_N_PIN)
#define MOTOR_A_N__RESET() PORT_ClrBit(MOTOR_A_N_PORT, MOTOR_A_N_PIN)#define MOTOR_B_P__SET() PORT_SetBit(MOTOR_B_P_PORT, MOTOR_B_P_PIN)
#define MOTOR_B_P__RESET() PORT_ClrBit(MOTOR_B_P_PORT, MOTOR_B_P_PIN)#define MOTOR_B_N__SET() PORT_SetBit(MOTOR_B_N_PORT, MOTOR_B_N_PIN)
#define MOTOR_B_N__RESET() PORT_ClrBit(MOTOR_B_N_PORT, MOTOR_B_N_PIN)PORT_Init(MOTOR_A_P_PORT, MOTOR_A_P_PIN, OUTPUT); //P15 A+PORT_Init(MOTOR_A_N_PORT, MOTOR_A_N_PIN, OUTPUT); //P14 A-PORT_Init(MOTOR_B_P_PORT, MOTOR_B_P_PIN, OUTPUT); //P13 B+PORT_Init(MOTOR_B_N_PORT, MOTOR_B_N_PIN, OUTPUT); //P12 B-PORT_Init(PORT3, PIN0, OUTPUT); //P30 CMS6021 POWER_EN, 使能CMS6324供电PORT_SetBit(PORT3, PIN0);while(1){#if (0) //四拍#if (0) //四拍正转//A+MOTOR_A_P__SET();MOTOR_B_P__RESET();MOTOR_A_N__RESET();MOTOR_B_N__RESET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);//B+MOTOR_A_P__RESET();MOTOR_B_P__SET();MOTOR_A_N__RESET();MOTOR_B_N__RESET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);//A-MOTOR_A_P__RESET();MOTOR_B_P__RESET();MOTOR_A_N__SET();MOTOR_B_N__RESET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);//B-MOTOR_A_P__RESET();MOTOR_B_P__RESET();MOTOR_A_N__RESET();MOTOR_B_N__SET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);#else //四拍反转//A+MOTOR_A_P__SET();MOTOR_B_P__RESET();MOTOR_A_N__RESET();MOTOR_B_N__RESET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);//B-MOTOR_A_P__RESET();MOTOR_B_P__RESET();MOTOR_A_N__RESET();MOTOR_B_N__SET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);//A-MOTOR_A_P__RESET();MOTOR_B_P__RESET();MOTOR_A_N__SET();MOTOR_B_N__RESET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);//B+MOTOR_A_P__RESET();MOTOR_B_P__SET();MOTOR_A_N__RESET();MOTOR_B_N__RESET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);#endif#else //八拍#if (0) //八拍正向//A+MOTOR_A_P__SET();MOTOR_B_P__RESET();MOTOR_A_N__RESET();MOTOR_B_N__RESET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);//A+ B+MOTOR_A_P__SET();MOTOR_B_P__SET();MOTOR_A_N__RESET();MOTOR_B_N__RESET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);//B+MOTOR_A_P__RESET();MOTOR_B_P__SET();MOTOR_A_N__RESET();MOTOR_B_N__RESET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);//B+ A-MOTOR_A_P__RESET();MOTOR_B_P__SET();MOTOR_A_N__SET();MOTOR_B_N__RESET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);//A-MOTOR_A_P__RESET();MOTOR_B_P__RESET();MOTOR_A_N__SET();MOTOR_B_N__RESET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);//A- B-MOTOR_A_P__RESET();MOTOR_B_P__RESET();MOTOR_A_N__SET();MOTOR_B_N__SET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);//B-MOTOR_A_P__RESET();MOTOR_B_P__RESET();MOTOR_A_N__RESET();MOTOR_B_N__SET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);//B- A+MOTOR_A_P__SET();MOTOR_B_P__RESET();MOTOR_A_N__RESET();MOTOR_B_N__SET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);#else //八拍反向//A+MOTOR_A_P__SET();MOTOR_B_P__RESET();MOTOR_A_N__RESET();MOTOR_B_N__RESET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);//B- A+MOTOR_A_P__SET();MOTOR_B_P__RESET();MOTOR_A_N__RESET();MOTOR_B_N__SET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);//B-MOTOR_A_P__RESET();MOTOR_B_P__RESET();MOTOR_A_N__RESET();MOTOR_B_N__SET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);//A- B-MOTOR_A_P__RESET();MOTOR_B_P__RESET();MOTOR_A_N__SET();MOTOR_B_N__SET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);//A-MOTOR_A_P__RESET();MOTOR_B_P__RESET();MOTOR_A_N__SET();MOTOR_B_N__RESET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);//B+ A-MOTOR_A_P__RESET();MOTOR_B_P__SET();MOTOR_A_N__SET();MOTOR_B_N__RESET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);//B+MOTOR_A_P__RESET();MOTOR_B_P__SET();MOTOR_A_N__RESET();MOTOR_B_N__RESET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);//A+ B+MOTOR_A_P__SET();MOTOR_B_P__SET();MOTOR_A_N__RESET();MOTOR_B_N__RESET();UserTimer_Reset(&timer_delay);while(UserTimer_Read(&timer_delay) < TIMEOUT_1MS);#endif#endif}
黄波形为 A+ |
蓝波形为 B+ |
紫波形为 A- |
绿波形为 B- |
三、抓取步进电机驱动芯片/驱动器的四线波形进行对比
以上为波形研究,待续