void timer16_pwm_config(uint16_t ir)
{
timer_oc_parameter_struct timer_ocintpara;
timer_parameter_struct timer_initpara;
rcu_periph_clock_enable(RCU_GPIOB);
/*ConfigurePB9(TIMER16 CH0) as alternate function*/
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);
rcu_periph_clock_enable(RCU_TIMER16);
timer_deinit(TIMER16);
// timer_initpara.repetitioncounter = 0;
/* TIMER16 configuration */
timer_initpara.prescaler = 4;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 250;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER16,&timer_initpara);
/* CH1,CH2 and CH3 configuration in PWM mode0 */
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,ir);
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); //¼ÆÊýºìÍâ
timer_update_event_disable(TIMER16);
// timer_channel_output_fast_config(TIMER16,TIMER_CH_0, TIMER_OC_FAST_ENABLE);
/* auto-reload preload enable */
timer_auto_reload_shadow_enable(TIMER16);
timer_primary_output_config(TIMER16, ENABLE);
/* auto-reload preload enable */
timer_enable(TIMER16);
}
求教,请问大神们gd32f350 time16动他改变pwm占空比是,启动时间怎么会这么长,示波器测起来有30ms左右,求教怎么处理!上面是配置! |