四路PWM, 分别PB4 ,PB5 ,PB6 ,PB7
关联是
//LA脚=PB4=TIMER2_CH0
//LB脚=PB5=TIMER2_CH1
//RA脚=PB6==TIMER15_CH0
//RB脚=PB7==TIMER16_CH0
TIMER2的CH0和CH1都能正常的输出PWM,切换正反也OK,调占空比都OK的.10KHZ
可相同的配置 PB6,PB7 对应的TIMER15,TIMER16 怎么也不出来,大佬看看?
------------------------------------------------------------------------------------------------------------------------------------
rcu_periph_clock_enable(RCU_GPIOB);
gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_6);
gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_6);
gpio_af_set(GPIOB, GPIO_AF_2, GPIO_PIN_6);
rcu_periph_clock_enable(RCU_GPIOB);
gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_7);
gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_7);
gpio_af_set(GPIOB, GPIO_AF_2, GPIO_PIN_7);
------------------------------------------------------------------------------------------------------------------------------------
void pwm_timer15_ch0(void)
{
timer_oc_parameter_struct timer_ocintpara;
timer_parameter_struct timer_initpara;
rcu_periph_clock_enable(RCU_TIMER15);
timer_deinit(TIMER15);
timer_initpara.prescaler = 72-1;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 100-1;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER15,&timer_initpara);
timer_ocintpara.outputstate = TIMER_CCX_ENABLE;
timer_ocintpara.ocpolarity = TIMER_OC_POLARITY_HIGH;
timer_channel_output_config(TIMER15,TIMER_CH_0,&timer_ocintpara);
timer_channel_output_pulse_value_config(TIMER15,TIMER_CH_0,49);
timer_channel_output_mode_config(TIMER15,TIMER_CH_0,TIMER_OC_MODE_PWM1);
timer_channel_output_shadow_config(TIMER15,TIMER_CH_0,TIMER_OC_SHADOW_DISABLE);
timer_auto_reload_shadow_enable(TIMER15);
timer_enable(TIMER15);
}
------------------------------------------------------------------------------------------------------------------------------------
void pwm_timer16_ch0(void)
{
timer_oc_parameter_struct timer_ocintpara;
timer_parameter_struct timer_initpara;
rcu_periph_clock_enable(RCU_TIMER16);
timer_deinit(TIMER16);
timer_initpara.prescaler = 72-1;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 100-1;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER16,&timer_initpara);
timer_ocintpara.outputstate = TIMER_CCX_ENABLE;
timer_ocintpara.ocpolarity = TIMER_OC_POLARITY_HIGH;
timer_channel_output_config(TIMER16,TIMER_CH_0,&timer_ocintpara);
timer_channel_output_pulse_value_config(TIMER16,TIMER_CH_0,49);
timer_channel_output_mode_config(TIMER16,TIMER_CH_0,TIMER_OC_MODE_PWM1);
timer_channel_output_shadow_config(TIMER16,TIMER_CH_0,TIMER_OC_SHADOW_DISABLE);
timer_auto_reload_shadow_enable(TIMER16);
timer_enable(TIMER16);
}
|
|