查看了工程demo:EVT\EXAM\TIM\PWM_Output
發(fā)現(xiàn)這個(gè)工程里面默認(rèn)的是TIM1_CH1 也就是PA8管腳。
沒有找到哪兒能設(shè)置通道,比如我想用PB8 TIM4_CH3該怎么配置?
按照這個(gè)例子,我可以配置成TIM10_CH1,同時(shí)輸出波形。但是我不清楚怎么配置成TIM4_CH3。
我參考其他配置通道的用法:
void TIM1_PWMOut_Init( u16 arr, u16 psc, u16 ccp )
{
? ? GPIO_InitTypeDef GPIO_InitStructure={0};
? ? TIM_OCInitTypeDef TIM_OCInitStructure={0};
? ? TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure={0};
? ? TIM_ICInitTypeDef TIM_ICInitStructure = {0};
? ? RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_TIM1 , ENABLE );
? ? RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM4, ENABLE );
? ? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
? ? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
? ? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
? ? GPIO_Init( GPIOA, &GPIO_InitStructure );
? ? GPIO_Init( GPIOB, &GPIO_InitStructure );
? ? TIM_TimeBaseInitStructure.TIM_Period = arr;
? ? TIM_TimeBaseInitStructure.TIM_Prescaler = psc;
? ? TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
? ? TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
? ? TIM_TimeBaseInit( TIM1, &TIM_TimeBaseInitStructure);
? ? TIM_TimeBaseInit( TIM4, &TIM_TimeBaseInitStructure);
#if (PWM_MODE == PWM_MODE1)
? ? TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
#elif (PWM_MODE == PWM_MODE2)
? ? TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
#endif
? ? TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
? ? TIM_OCInitStructure.TIM_Pulse = ccp;
? ? TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
? ? TIM_OC1Init( TIM1, &TIM_OCInitStructure );
? ? TIM_OC1Init( TIM4, &TIM_OCInitStructure );
? ? TIM_CtrlPWMOutputs(TIM1, ENABLE );
? ? TIM_OC1PreloadConfig( TIM1, TIM_OCPreload_Disable );
? ? TIM_ARRPreloadConfig( TIM1, ENABLE );
? ? TIM_Cmd( TIM1, ENABLE );
? ? TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;
? ? TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
? ? TIM_ICInitStructure.TIM_ICFilter = 0x00;
? ? TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;
? ? TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
? ? TIM_ICInit(TIM4, &TIM_ICInitStructure);
? ? TIM_CtrlPWMOutputs(TIM4, ENABLE );
? ? TIM_OC1PreloadConfig( TIM4, TIM_OCPreload_Disable );
? ? TIM_ARRPreloadConfig( TIM4, ENABLE );
? ? TIM_Cmd( TIM4, ENABLE );
}
但是發(fā)現(xiàn)無法生效。
我該如何配置是他作為TIM4_CH3來使用?