按照例程设置多路输出后上板跑发现只有CH0有输出,可以帮忙看看什么问题吗
/* -----------------------------------------------------------------------
TIMER2 configuration: generate 2 PWM signals:
----------------------------------------------------------------------- */
timer_oc_parameter_struct timer_ocintpara;
timer_parameter_struct timer_initpara;
/*Configure the pin as alternate function*/
gpio_mode_set(GPIOC, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_6);
gpio_output_options_set(GPIOC, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_6);
gpio_mode_set(GPIOC, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_7);
gpio_output_options_set(GPIOC, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_7);
gpio_af_set(GPIOC, GPIO_AF_1, GPIO_PIN_6); /* PWM LED1 */
gpio_af_set(GPIOC, GPIO_AF_1, GPIO_PIN_7); /* PWM LED2 */
rcu_periph_clock_enable(RCU_TIMER2);
timer_deinit(TIMER2);
/* TIMER1 configuration */
#ifdef GD32F330
timer_initpara.prescaler = 0;
#endif /* GD32F330 */
#ifdef GD32F350
timer_initpara.prescaler = 107;
#endif /* GD32F350 */
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = (n_LEDPWMPeriod - 1);
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER2, &timer_initpara);
/* CH0 configuration in PWM mode */
timer_ocintpara.outputstate = TIMER_CCX_ENABLE;
timer_ocintpara.outputnstate = TIMER_CCXN_ENABLE;
timer_ocintpara.ocpolarity = TIMER_OC_POLARITY_HIGH;
timer_ocintpara.ocnpolarity = TIMER_OCN_POLARITY_HIGH;
timer_ocintpara.ocidlestate = TIMER_OC_IDLE_STATE_LOW;
timer_ocintpara.ocnidlestate = TIMER_OCN_IDLE_STATE_LOW;
timer_channel_output_config(TIMER2, TIMER_CH_0, &timer_ocintpara); /* PC6 LED1*/
timer_channel_output_config(TIMER2, TIMER_CH_1, &timer_ocintpara); /* PC7 LED2 */
timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_0, n_LEDPWMPeriod - 1);
timer_channel_output_mode_config(TIMER2, TIMER_CH_0, TIMER_OC_MODE_PWM0);
timer_channel_output_shadow_config(TIMER2, TIMER_CH_0, TIMER_OC_SHADOW_DISABLE);
timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_1, n_LEDPWMPeriod - 1);
timer_channel_output_mode_config(TIMER2, TIMER_CH_1, TIMER_OC_MODE_PWM0);
timer_channel_output_shadow_config(TIMER2, TIMER_CH_1, TIMER_OC_SHADOW_DISABLE);
timer_primary_output_config(TIMER2,ENABLE);
/* auto-reload preload enable */
timer_auto_reload_shadow_enable(TIMER2);
/* auto-reload preload enable */
timer_enable(TIMER2); |