需要用到PB9 Timer16_CH0,参考例程Timer1_CH3的配置,以下同样的配置,PB9不能输出PWM,PB11有PWM输出,是不是Timer16有特殊的设置?求解。。。
#if 1
rcu_periph_clock_enable(RCU_GPIOB);
gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_9);
gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_9);
//gpio_af_set(GPIOB, GPIO_AF_2, GPIO_PIN_9);
gpio_af_set(GPIOB, GPIO_AF_2, GPIO_PIN_9);
timer_oc_parameter_struct timer_ocintpara;
timer_parameter_struct timer_initpara;
rcu_periph_clock_enable(RCU_TIMER16);
timer_deinit(TIMER16);
timer_initpara.prescaler = 1;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 2099;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER16,&timer_initpara);
timer_ocintpara.ocpolarity = TIMER_OC_POLARITY_HIGH;
timer_ocintpara.outputstate = TIMER_CCX_ENABLE;
timer_channel_output_config(TIMER16,TIMER_CH_0,&timer_ocintpara);
timer_channel_output_pulse_value_config(TIMER16,TIMER_CH_0,1049);
timer_channel_output_mode_config(TIMER16,TIMER_CH_0,TIMER_OC_MODE_PWM0);
timer_channel_output_shadow_config(TIMER16,TIMER_CH_0,TIMER_OC_SHADOW_DISABLE);
/* auto-reload preload enable */
timer_auto_reload_shadow_enable(TIMER16);
/* auto-reload preload enable */
timer_enable(TIMER16);
#endif
#if 1
rcu_periph_clock_enable(RCU_GPIOB);
gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_11);
gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_11);
gpio_af_set(GPIOB, GPIO_AF_2, GPIO_PIN_11);
//memset((void*)timer_ocintpara,0,sizeof(timer_ocintpara));
//memset((void*)timer_initpara,0,sizeof(timer_initpara));
timer_oc_parameter_struct timer_ocintparaa;
timer_parameter_struct timer_initparaa;
rcu_periph_clock_enable(RCU_TIMER1);
timer_deinit(TIMER1);
timer_initparaa.prescaler = 1;
timer_initparaa.alignedmode = TIMER_COUNTER_EDGE;
timer_initparaa.counterdirection = TIMER_COUNTER_UP;
timer_initparaa.period = 2099;
timer_initparaa.clockdivision = TIMER_CKDIV_DIV1;
timer_initparaa.repetitioncounter = 0;
timer_init(TIMER1,&timer_initparaa);
timer_ocintparaa.ocpolarity = TIMER_OC_POLARITY_HIGH;
timer_ocintparaa.outputstate = TIMER_CCX_ENABLE;
timer_channel_output_config(TIMER1,TIMER_CH_3,&timer_ocintparaa);
timer_channel_output_pulse_value_config(TIMER1,TIMER_CH_3,1049);
timer_channel_output_mode_config(TIMER1,TIMER_CH_3,TIMER_OC_MODE_PWM0);
timer_channel_output_shadow_config(TIMER1,TIMER_CH_3,TIMER_OC_SHADOW_DISABLE);
/* auto-reload preload enable */
timer_auto_reload_shadow_enable(TIMER1);
/* auto-reload preload enable */
timer_enable(TIMER1);
#endif |
|