void timer14_config(void)
{
timer_oc_parameter_struct timer_ocintpara;
timer_parameter_struct timer_initpara;
rcu_periph_clock_enable(RCU_TIMER14);
rcu_periph_clock_enable(RCU_GPIOA);
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_2);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_MAX,GPIO_PIN_2);
gpio_af_set(GPIOA, GPIO_AF_0, GPIO_PIN_2);
timer_deinit(TIMER14);
/* TIMER1 configuration */
timer_initpara.prescaler = 0;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 10800;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER14,&timer_initpara);
/* CH1,CH2 and CH3 configuration in PWM mode */
timer_ocintpara.outputstate = TIMER_CCX_ENABLE;
timer_ocintpara.outputnstate = TIMER_CCXN_DISABLE;
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(TIMER14,TIMER_CH_0,&timer_ocintpara);
timer_channel_output_pulse_value_config(TIMER14,TIMER_CH_0,1);
timer_channel_output_mode_config(TIMER14,TIMER_CH_0,TIMER_OC_MODE_PWM0);
timer_channel_output_shadow_config(TIMER14,TIMER_CH_0,TIMER_OC_SHADOW_DISABLE);
timer_primary_output_config(TIMER14, ENABLE);
// timer_interrupt_flag_clear(TIMER14, TIMER_INT_FLAG_CH0);
// /* enable the TIMER interrupt */
// timer_interrupt_enable(TIMER14, TIMER_INT_CH0);
// nvic_irq_enable(TIMER16_IRQn, 0,0);
/* auto-reload preload enable */
timer_auto_reload_shadow_enable(TIMER14);
/* auto-reload preload enable */
timer_enable(TIMER14);
}
GD32F350定时器14PWM输出
最新推荐文章于 2024-07-29 16:42:48 发布
本文详细描述了如何在STM32中配置定时器14,包括时钟设置、计数器方向、周期、PWM通道配置以及中断处理。重点展示了如何将GPIOA的PIN_2用于PWM输出并启用定时器中断。
摘要由CSDN通过智能技术生成