用Timer2产生PWM正常,但用类似的程序,Timer14没有PWM输出。void timer2_config(void)
{
timer_oc_parameter_struct timer_ocintpara;
timer_parameter_struct timer_initpara;
rcu_periph_clock_enable(RCU_TIMER2);
timer_deinit(TIMER2);
timer_initpara.prescaler = 539;
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(TIMER2, &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(TIMER2, TIMER_CH_0, &timer_ocintpara);
timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_0, 100);
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);
/* auto-reload preload enable */
timer_auto_reload_shadow_enable(TIMER2);
/* auto-reload preload enable */
timer_enable(TIMER2);
}
科技飞速发展,学习永无止境。变压器有载调压,一小时万次切换。
void timer14_config(void)
{
timer_oc_parameter_struct timer_ocintpara;
timer_parameter_struct timer_initpara;
rcu_periph_clock_enable(RCU_TIMER14);
timer_deinit(TIMER14);
timer_initpara.prescaler = 539;
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(TIMER14, &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(TIMER14, TIMER_CH_0, &timer_ocintpara);
timer_channel_output_pulse_value_config(TIMER14, TIMER_CH_0, 100);
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);
/* auto-reload preload enable */
timer_auto_reload_shadow_enable(TIMER14);
/* auto-reload preload enable */
timer_enable(TIMER14);
}
科技飞速发展,学习永无止境。变压器有载调压,一小时万次切换。
void gpio_config(void)
{
/*Configure PB3 PB10 PB11(TIMER1 CH1 CH2 CH3) as alternate function*/
gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_3);
gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_3);
gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_10);
gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_10);
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_3);
gpio_af_set(GPIOB, GPIO_AF_2, GPIO_PIN_10);
gpio_af_set(GPIOB, GPIO_AF_2, GPIO_PIN_11);
//配置 PB4(TIMER2 CH0) 为复用功能
gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_4);
gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_4);
gpio_af_set(GPIOB, GPIO_AF_1, GPIO_PIN_4);
//配置 PB14(TIMER14 CH0) 为复用功能
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_af_set(GPIOB, GPIO_AF_1, GPIO_PIN_14);
}
科技飞速发展,学习永无止境。变压器有载调压,一小时万次切换。
我就是过来看看的
北京玻璃隔断www.bjtjblgd.com 法兰厂家www.zsfl888.com 丁基胶带www.djjd8.com 薄膜开关www.hbhksjdz.com