您当前的位置:首 页 > FAQ

TIMER8 CH3 PWM输出问题

所属分类:GD32F105系列   浏览数: 520   提问者: xinuaile2012   提问时间: 2017-08-08 10:32:46

问: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输出