STM32 控制步进电机 28BYJ-48

STM32 控制步进电机 28BYJ-48  http://blog.chinaunix.net/uid-12664992-id-300272.html

 

步进电机驱动最简化的逻辑:

//四相八拍:A->AB->B ->BC ->C ->CD ->D ->DA
unsigned char Motor_StepDat[8] = {
     0x08,0x0C,0x04,0x06,0x02,0x03,0x01,0x09};
/* 
A   1000   0x08
AB  1100   0x0C
B   0100   0x04
BC  0110   0x06
C   0010   0x02
CD  0011   0x03
D   0001   0x01
DA  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]
}

 S和STM32的智能步进电机驱动控制模块设计 http://wenku.baidu.com/view/0b0876479ec3d5bbfd0a748a.html 

你可能感兴趣的:(嵌入式)