最近在调试步进电机控制程序,利用STM32F407的timer10的第一通道,但是我写的程序,电机一直在运行,不能够停止,各路大神帮我看看,如何控制电机运行的圈数啊,谢谢各位,在线等
附代码:
void Tim10_Configuration(void)//PF6-CH1-T10
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM10, ENABLE);
TIM_DeInit(TIM10);
/*TIM10时钟配置*/
TIM_TimeBaseStructure.TIM_Prescaler = 5; //
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //
TIM_TimeBaseStructure.TIM_Period = 0xffff; //
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseInit(TIM10,&TIM_TimeBaseStructure);
/* Channel 1 Configuration in oc mode */
TIM_OCStructInit(&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle; //
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //
TIM_OCInitStructure.TIM_Pulse = S_50HZ; //
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM10,&TIM_OCInitStructure); //通道1
TIM_ClearFlag(TIM10, TIM_FLAG_CC1);
TIM_ITConfig(TIM10, TIM_IT_CC1, DISABLE);
TIM_Cmd(TIM10,DISABLE);
TIM_CtrlPWMOutputs(TIM10,ENABLE);
TIM_ARRPreloadConfig(TIM10, DISABLE);
}
void TIM10_CC_IRQHandler(void)
{
uint16_t capture=0;
uint16_t temp=0;
if(TIM_GetITStatus(TIM1, TIM_IT_CC1) == SET)
{
TIM_ClearITPendingBit(TIM10, TIM_IT_CC1 );
Tulun_i++;
if(Tulun_i == 10 )
{
TIM_Cmd(TIM10,DISABLE);
TIM_ITConfig(TIM10, TIM_IT_CC1, DISABLE);
TIM_CtrlPWMOutputs(TIM10,DISABLE);
}
}
}
/*************************************************************
sudu_max 最大速频率 weiz 圈数 i 方向
**************************************************************/
void step1_runhand(void)
{
if(arror==1)//正转
{
GPIO_ResetBits(GPIOI, GPIO_Pin_4);
}
else
{
GPIO_SetBits(GPIOI, GPIO_Pin_4);
}
TIM_ITConfig(TIM10, TIM_IT_CC1, ENABLE);
TIM_Cmd(TIM10,ENABLE);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
---------------------------------
已经申请加入了,希望共同进步
一周热门 更多>