初级会员

- 积分
- 67
- 金钱
- 67
- 注册时间
- 2018-6-21
- 在线时间
- 10 小时
|
10金钱
我用定时器3生成的pwm波在高电平时会突然有那么几下被拉低,就像我图片里的一样,占空比测出来都是对的,
而且我通过改参数,生成50hz的pwm波也生成不了,求大佬帮忙看一下,谢谢了
下面是我初始化的函数,
void PWM(u16 arr,u16 psc)
{
GPIO_InitTypeDef GPIO_InitStrue;
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStrue;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
GPIO_InitStrue.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStrue.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_InitStrue.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStrue);
GPIO_InitStrue.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1;
GPIO_Init(GPIOB,&GPIO_InitStrue);
TIM_TimeBaseInitStrue.TIM_Period=arr;
TIM_TimeBaseInitStrue.TIM_Prescaler=psc;
TIM_TimeBaseInitStrue.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInitStrue.TIM_ClockDivision=0;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStrue);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //选择定时器模式:TIM脉冲宽度调制模式2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //比较输出使能
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //输出极性:TIM输出比较极性高
TIM_OCInitStructure.TIM_Pulse=500;
TIM_OC1Init(TIM3,&TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM3,ENABLE);
TIM_Cmd(TIM3,ENABLE);
}
|
-
用TIM3生成的pwm波
|