步进电机驱动最简化的逻辑:
//四相八拍:A->AB->B ->BC ->C ->CD ->D ->DAunsigned char Motor_StepDat[8] = {0x08,0x0C,0x04,0x06,0x02,0x03,0x01,0x09};/* A 1000 0x08AB 1100 0x0CB 0100 0x04BC 0110 0x06C 0010 0x02CD 0011 0x03D 0001 0x01DA 1001 0x09*/void MotorH_Step1(unsigned char Dir_Flag){ if(Dir_Flag) { Motor1_StepNum++; } else { Motor1_StepNum--; } GPIOB->ODR |= ((unsigned short)Motor_StepDat[Motor1_StepNum]<<12); GPIOB->ODR &= (((unsigned short)Motor_StepDat[Motor1_StepNum]<<12) | 0x0FFF); //驱动电机的引脚是PB12-PB15,将这四位的值设置为Motor_StepDat[Motor1_StepNum]}
步进电机驱动最简化的逻辑:
//四相八拍:A->AB->B ->BC ->C ->CD ->D ->DAunsigned char Motor_StepDat[8] = {0x08,0x0C,0x04,0x06,0x02,0x03,0x01,0x09};/* A 1000 0x08AB 1100 0x0CB 0100 0x04BC 0110 0x06C 0010 0x02CD 0011 0x03D 0001 0x01DA 1001 0x09*/void MotorH_Step1(unsigned char Dir_Flag){ if(Dir_Flag) { Motor1_StepNum++; } else { Motor1_StepNum--; } GPIOB->ODR |= ((unsigned short)Motor_StepDat[Motor1_StepNum]<<12); GPIOB->ODR &= (((unsigned short)Motor_StepDat[Motor1_StepNum]<<12) | 0x0FFF); //驱动电机的引脚是PB12-PB15,将这四位的值设置为Motor_StepDat[Motor1_StepNum]}
举报