我这配置两路PWM输出的代码哪里也有问题啊?求助
[mw_shl_code=applescript,true] GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO,ENABLE);
GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3,ENABLE);//开启部分重映射
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;//初始化PB.5
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5|GPIO_Pin_4;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStructure);
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;//配置定时器
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInitStructure.TIM_Prescaler=psc;
TIM_TimeBaseInitStructure.TIM_Period=arr;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStructure);
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM2;//输出模时2,计数值比比较值小时为无效电平
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;//输出极性高电平有效
TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;//比较输出使能
TIM_OC2Init(TIM3,&TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM3,TIM_OCPreload_Enable);
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM2;//输出模时2,计数值比比较值小时为无效电平
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;//输出极性高电平有效
TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;//比较输出使能
TIM_OC1Init(TIM3,&TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM3,TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM3,ENABLE);//预装载寄存器立即生效
TIM_Cmd(TIM3,ENABLE);
}[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>