高中生
最后登录1970-1-1
在线时间 小时
注册时间2018-3-16
|
用的是stm32F429的开发板,按照上面 想让PC6,PA5产生pwm波 ,但是为什么只有PA5有波形 ,PC6没有 是什么原因啊
void TIM2_PWM_Init(void)
{
GPIO_InitTypeDef GPIO_Init_structure;
TIM_TimeBaseInitTypeDef TIM_TimeBase_structure;
TIM_OCInitTypeDef TIM_OCInit_structure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
//定时器复用引脚
GPIO_PinAFConfig(GPIOA,GPIO_PinSource5,GPIO_AF_TIM2);
GPIO_Init_structure.GPIO_Pin=GPIO_Pin_5 ;
GPIO_Init_structure.GPIO_Mode=GPIO_Mode_AF;
GPIO_Init_structure.GPIO_OType=GPIO_OType_PP;
GPIO_Init_structure.GPIO_PuPd=GPIO_PuPd_NOPULL;
GPIO_Init_structure.GPIO_Speed=GPIO_High_Speed;
GPIO_Init(GPIOA,&GPIO_Init_structure);
TIM_TimeBase_structure.TIM_Period=9000-1;
TIM_TimeBase_structure.TIM_Prescaler=900-1;
TIM_TimeBase_structure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBase_structure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2,&TIM_TimeBase_structure);
TIM_OCInit_structure.TIM_OCMode=TIM_OCMode_PWM1;
TIM_OCInit_structure.TIM_OutputState=TIM_OutputState_Enable;
TIM_OCInit_structure.TIM_Pulse = 3000-1;
TIM_OCInit_structure.TIM_OCPolarity=TIM_OCPolarity_High;
TIM_OC1Init(TIM2,&TIM_OCInit_structure);
TIM_OC1PreloadConfig(TIM2,TIM_OCPreload_Enable);//通道一
//
//
//
// TIM_OC2Init(TIM2,&TIM_OCInit_structure);
// TIM_OC2PreloadConfig(TIM28,TIM_OCPreload_Enable);//通道三
//
TIM_Cmd(TIM2,ENABLE);//时钟使能
}
void TIM8_PWM_Init(void)
{
GPIO_InitTypeDef GPIO_Init_structure;
TIM_TimeBaseInitTypeDef TIM_TimeBase_structure;
TIM_OCInitTypeDef TIM_OCInit_structure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE);
//定时器复用引脚
GPIO_PinAFConfig(GPIOC,GPIO_PinSource6,GPIO_AF_TIM8);
GPIO_Init_structure.GPIO_Pin=GPIO_Pin_6 ;
GPIO_Init_structure.GPIO_Mode=GPIO_Mode_AF;
GPIO_Init_structure.GPIO_OType=GPIO_OType_PP;
GPIO_Init_structure.GPIO_PuPd=GPIO_PuPd_NOPULL;
GPIO_Init_structure.GPIO_Speed=GPIO_High_Speed;
GPIO_Init(GPIOC,&GPIO_Init_structure);
TIM_TimeBase_structure.TIM_Period=9000-1;
TIM_TimeBase_structure.TIM_Prescaler=900-1;
TIM_TimeBase_structure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBase_structure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM8,&TIM_TimeBase_structure);
TIM_OCInit_structure.TIM_OCMode=TIM_OCMode_PWM2;
TIM_OCInit_structure.TIM_OutputState=TIM_OutputState_Enable;
TIM_OCInit_structure.TIM_Pulse = 3000-1;
TIM_OCInit_structure.TIM_OCPolarity=TIM_OCPolarity_High;
TIM_OC1Init(TIM8,&TIM_OCInit_structure);
TIM_OC1PreloadConfig(TIM8,TIM_OCPreload_Enable);//通道一
//
//
//
// TIM_OC2Init(TIM2,&TIM_OCInit_structure);
// TIM_OC2PreloadConfig(TIM28,TIM_OCPreload_Enable);//通道三
//
TIM_Cmd(TIM8,ENABLE);//时钟使能
}
|
|