测试了很多种方法还是不行,代码如下
rcu_periph_clock_enable(RCU_TIMER2);
timer_deinit(TIMER2);
timer_initpara.prescaler = 9;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 4000; //频率值
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER2,&timer_initpara);
/* CH1 configuration in PWM mode */
timer_ocintpara.outputstate = TIMER_CCX_ENABLE;
timer_ocintpara.ocpolarity = TIMER_OC_POLARITY_HIGH;
timer_ocintpara.ocidlestate = TIMER_OC_IDLE_STATE_LOW;
timer_channel_output_config(TIMER2,TIMER_CH_1,&timer_ocintpara);
timer_channel_output_pulse_value_config(TIMER2,TIMER_CH_1,2000); //占空比值
timer_channel_output_mode_config(TIMER2,TIMER_CH_1,TIMER_OC_MODE_PWM0);
timer_channel_output_shadow_config(TIMER2,TIMER_CH_1,TIMER_OC_SHADOW_DISABLE);
timer_primary_output_config(TIMER2,ENABLE);
timer_enable(TIMER2);
调节占空比是比较简单, timer_channel_output_pulse_value_config(TIMER2,TIMER_CH_1,PWM); //占空比值赋值到PWM然后调节PWM值就行了,但是频率值是不行的,
我把频率值赋值后发现调不了,大家帮我看一下咋回事,因为我调节范围比较小,所以没有去调分频之类的,那样的话调节一下频率就会变化很多,
|