TB6560步进电机驱动不了

2019-10-11 15:42发布

自己尝试写了个PWM程序想要让电机动起来,上网查了些资料后,想自己尝试下驱动TB6560步进电机。
但是并不成功,想请教一下各位哪里出了问题,希望可以得到一些建议。
以下是接线
QQ图片20170316163605.png QQ图片20170316163616.png QQ图片20170316163619.png
接着是程序
void TIM1_PWM_Init(void)
{
    TIM_TimeBaseInitTypeDef    TIM_TimeBaseStructure;
    TIM_OCInitTypeDef TIM_OCInitStructure;
    GPIO_InitTypeDef GPIO_Initstructure;
   
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);   
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
   
    GPIO_Initstructure.GPIO_Mode=GPIO_Mode_AF_PP;
    GPIO_Initstructure.GPIO_Pin=GPIO_Pin_8;
    GPIO_Initstructure.GPIO_Speed=GPIO_Speed_50MHz;
    GPIO_Init(GPIOA,&GPIO_Initstructure);
   
    TIM_TimeBaseStructure.TIM_Prescaler = 720-1;
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
    TIM_TimeBaseStructure.TIM_Period = 1000-1;
    TIM_TimeBaseStructure.TIM_ClockDivision = 0;
    TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
    TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
    TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
    TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
    TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
    TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;

    TIM_OC1Init(TIM1, &TIM_OCInitStructure);
    TIM_OC2Init(TIM1, &TIM_OCInitStructure);
    TIM_OC3Init(TIM1, &TIM_OCInitStructure);
    TIM_OC4Init(TIM1, &TIM_OCInitStructure);
   
    TIM1->CCR1 = 0;
   
    TIM_CtrlPWMOutputs(TIM1, ENABLE);
    TIM_Cmd(TIM1,ENABLE);

}

int main()
{
    while(1)
    {
        GPIO_SetBits(GPIOB, GPIO_Pin_5);
        GPIO_SetBits(GPIOB, GPIO_Pin_6);
        TIM_SetCompare1(TIM1,600);
    }
}




友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
2条回答
andy741520
1楼-- · 2019-10-11 17:15
不是很会发图。。图发多了
正点原子
2楼-- · 2019-10-11 21:54
参考下我们的步进电机驱动器代码吧,http://www.openedv.com/thread-76190-1-1.html

一周热门 更多>