注册会员
- 积分
- 20
- 威望
- 14
- 贡献
- 6
- 兑换币
- 4
- 注册时间
- 2019-8-31
- 在线时间
- 0 小时
|
今天碰到一个很奇怪的问题,希望大佬们帮助问题如下:
使用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)
{
}
}
|
|