智能车制作
标题:
stm32 pwm经过八个周期后失灵
[打印本页]
作者:
IdelMan
时间:
2019-9-1 15:17
标题:
stm32 pwm经过八个周期后失灵
今天碰到一个很奇怪的问题,希望大佬们帮助问题如下:
使用stm32的TIM3_CH2通道输出pwm控制电机,驱动板是tb6621fng,发现前八个周期都会按照程序正常输出,但是8个周期后,就一直输出高电平。
程序如下:
void TIM3_PWM_Init(u16 arr,u16 psc, u16 pulse){
GPIO_InitTypeDef GPIOA_InitStruct;
TIM_TimeBaseInitTypeDef TIM3_TimeBaseInitStruct;
TIM_OCInitTypeDef TIM3_OCInitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
GPIOA_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
GPIOA_InitStruct.GPIO_Pin = GPIO_Pin_7;
GPIOA_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIOA_InitStruct);
TIM3_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
TIM3_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
TIM3_TimeBaseInitStruct.TIM_Period = arr - 1;
TIM3_TimeBaseInitStruct.TIM_Prescaler = psc - 1;
TIM3_TimeBaseInitStruct.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM3, &TIM3_TimeBaseInitStruct);
TIM3_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM1;
TIM3_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;
TIM3_OCInitStruct.TIM_Pulse = pulse;
TIM3_OCInitStruct.TIM_OCNPolarity = TIM_OCPolarity_High;
TIM_OC2Init(TIM3, &TIM3_OCInitStruct);
TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_Cmd(TIM3, ENABLE);
TIM_ARRPreloadConfig(TIM3, ENABLE);
}
int main()
{
TIM3_PWM_Init(4000,72, 2000);
while(1)
{
}
}
欢迎光临 智能车制作 (http://111.231.132.190/)
Powered by Discuz! X3.2