打算用GDF407的定时器11的PWM模式输出脉冲,代码是从例程改的,现遇到ch0输出不正常(图1),ch1正常,两个通道配置一样,不知道是哪里的问题,所以想请教一下~
代码如下:
void gpio_config(void)
{
rcu_periph_clock_enable(RCU_GPIOB);
gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_14);
gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_14);
gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_15);
gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_15);
gpio_af_set(GPIOB, GPIO_AF_9, GPIO_PIN_14);
gpio_af_set(GPIOB, GPIO_AF_9, GPIO_PIN_15);
}
void timer_config(void)
{
timer_oc_parameter_struct timer_ocintpara;
timer_parameter_struct timer_initpara;
rcu_periph_clock_enable(RCU_TIMER11);
rcu_timer_clock_prescaler_config(RCU_TIMER_PSC_MUL4);
timer_deinit(TIMER11);
/* TIMER11 configuration */
timer_initpara.prescaler = 7;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 199;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER11,&timer_initpara);
/* CH0,CH1 configuration in PWM mode1 */
timer_ocintpara.ocpolarity = TIMER_OC_POLARITY_HIGH;
timer_ocintpara.outputstate = TIMER_CCX_ENABLE;
timer_channel_output_config(TIMER11,TIMER_CH_0,&timer_ocintpara);
timer_channel_output_config(TIMER11,TIMER_CH_1,&timer_ocintpara);
/* CH0 configuration in PWM mode1,duty cycle 50% */
timer_channel_output_pulse_value_config(TIMER11,TIMER_CH_0,99);
timer_channel_output_mode_config(TIMER11,TIMER_CH_0,TIMER_OC_MODE_PWM0);
timer_channel_output_shadow_config(TIMER11,TIMER_CH_0,TIMER_OC_SHADOW_DISABLE);
/* CH1 configuration in PWM mode1,duty cycle 50% */
timer_channel_output_pulse_value_config(TIMER11,TIMER_CH_1,99);
timer_channel_output_mode_config(TIMER11,TIMER_CH_1,TIMER_OC_MODE_PWM0);
timer_channel_output_shadow_config(TIMER11,TIMER_CH_1,TIMER_OC_SHADOW_DISABLE);
/* auto-reload preload enable */
timer_auto_reload_shadow_enable(TIMER11);
/* auto-reload preload enable */
timer_enable(TIMER11);
}
|