RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_TIMER8, ENABLE);
RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOC , ENABLE);
RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_AF , ENABLE);
void TIM8_GPIO_Configuration(void)
{
GPIO_InitPara GPIO_InitStructure;
/* PC8设置为功能脚(PWM) */
GPIO_InitStructure.GPIO_Pin = CHARGE_PWM_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
GPIO_Init(CHARGE_PWM_PORT, &GPIO_InitStructure);
}
void TIM8_PWM_Configuration(void)
{
TIMER_BaseInitPara TIMER_TimeBaseStructure;
TIMER_OCInitPara TIMER_OCInitStructure;
/* TIMER8 configuration */
TIMER_DeInit(TIMER8);
//TIMERxCLK = SystemCoreClock / 72 = 1MHz
TIMER_TimeBaseStructure.TIMER_Prescaler = 71;
TIMER_TimeBaseStructure.TIMER_CounterMode = TIMER_COUNTER_UP;
//TIMERx Period 10000 (1MHz / 10000 = 100Kz)
TIMER_TimeBaseStructure.TIMER_Period = 9999;
TIMER_TimeBaseStructure.TIMER_ClockDivision = TIMER_CDIV_DIV1;
TIMER_BaseInit(TIMER8,&TIMER_TimeBaseStructure);
/* CHx Configuration in PWM mode */
TIMER_OCInitStructure.TIMER_OCMode = TIMER_OC_MODE_PWM1;
TIMER_OCInitStructure.TIMER_OCPolarity = TIMER_OC_POLARITY_HIGH;
TIMER_OCInitStructure.TIMER_OutputState = TIMER_OUTPUT_STATE_ENABLE;
TIMER_OCInitStructure.TIMER_OCIdleState = TIMER_OC_IDLE_STATE_RESET;
//TIMERx Channel3 duty cycle = (2500 / 10000) * 100 = 25%
TIMER_OCInitStructure.TIMER_Pulse = 2499;
TIMER_OC3_Init(TIMER8, &TIMER_OCInitStructure);
TIMER_OC3_Preload(TIMER8,TIMER_OC_PRELOAD_DISABLE);
/* Auto-reload preload enable */
TIMER_CARLPreloadConfig(TIMER8,ENABLE);
/* TIMER enable counter*/
TIMER_Enable(TIMER8, ENABLE );
}
上面的代码有哪出问题?
在引脚上没有PWM输出
|