现在我需要4路PWM波,现在我是这样设置的,但是,只有一路可以输出,求大神帮忙看一下,这样设置2路PWM波,为什么只有F9有输出,F6没有输出?
void TIM14_PWM_Init(u32 arr,u32 psc)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM14,ENABLE); //TIM14?±??????
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE); //????PORTF?±??
GPIO_PinAFConfig(GPIOF,GPIO_PinSource9,GPIO_AF_TIM14); //GPIOF9???????¨?±?÷14
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //GPIOF9
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //????????
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //????100MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //???ì????????
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //????
GPIO_Init(GPIOF,&GPIO_InitStructure); //??????PF9
TIM_TimeBaseStructure.TIM_Prescaler=psc; //?¨?±?÷·???
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //?ò??????????
TIM_TimeBaseStructure.TIM_Period=arr; //×?????×°????
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM14,&TIM_TimeBaseStructure);//???????¨?±?÷14
//??????TIM14 Channel1 PWM????
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //?????¨?±?÷????:TIM?????í???÷??????2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //±???????????
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //????????:TIM????±?????????
TIM_OC1Init(TIM14, &TIM_OCInitStructure); //?ù??T???¨???????????????èTIM1 4OC1
TIM_OC1PreloadConfig(TIM14, TIM_OCPreload_Enable); //????TIM14??CCR1?????¤×°???????÷
TIM_ARRPreloadConfig(TIM14,ENABLE);//ARPE????
TIM_Cmd(TIM14, ENABLE); //????TIM14
}
void TIM10_PWM_Init(u32 arr,u32 psc)
{
//????·??è????????IO???è??
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB2Periph_TIM10,ENABLE); //TIM14?±??????
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE); //????PORTF?±??
GPIO_PinAFConfig(GPIOF,GPIO_PinSource6,GPIO_AF_TIM10); //GPIOF9???????¨?±?÷14
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //GPIOF9
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //????????
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //????100MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //???ì????????
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //????
GPIO_Init(GPIOF,&GPIO_InitStructure); //??????PF9
TIM_TimeBaseStructure.TIM_Prescaler=psc; //?¨?±?÷·???
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //?ò??????????
TIM_TimeBaseStructure.TIM_Period=arr; //×?????×°????
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM10,&TIM_TimeBaseStructure);//???????¨?±?÷14
//??????TIM14 Channel1 PWM????
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //?????¨?±?÷????:TIM?????í???÷??????2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //±???????????
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //????????:TIM????±?????????
TIM_OC1Init(TIM10, &TIM_OCInitStructure); //?ù??T???¨???????????????èTIM1 4OC1
TIM_OC1PreloadConfig(TIM10, TIM_OCPreload_Enable); //????TIM14??CCR1?????¤×°???????÷
TIM_ARRPreloadConfig(TIM10,ENABLE);//ARPE????
TIM_Cmd(TIM10, ENABLE); //????TIM14
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>