rcu_periph_clock_enable(RCU_TIMER0);
timer_parameter_struct timer_initpara;
rcu_timer_clock_prescaler_config(RCU_TIMER_PSC_MUL2);
rcu_periph_clock_enable(RCU_GPIOE);
gpio_af_set(GPIOE,GPIO_AF_1,GPIO_PIN_14);
gpio_mode_set(GPIOE,GPIO_MODE_AF, GPIO_PUPD_PULLDOWN,GPIO_PIN_14);
gpio_output_options_set(GPIOE,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_14);
timer_deinit(TIMER0);
// 初始化TIM结构体
timer_struct_para_init(&timer_initpara);
timer_initpara.prescaler = 2 - 1; //TIMER7CLK = SystemCoreClock / ( 1+1 )= 200 / 2 -> 100M 5
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = (SystemCoreClock/2/PWM) - 1; // 18MHz/(1799+1)=10KHz 周期 (100000000/PWM) - 1 899
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER0,&timer_initpara);
timer_oc_parameter_struct timer_ocintpara;
timer_ocintpara.outputstate = TIMER_CCX_ENABLE; //通道输出状态
timer_ocintpara.ocpolarity = TIMER_OC_POLARITY_HIGH; //通道输出极性
timer_ocintpara.ocidlestate = TIMER_OC_IDLE_STATE_LOW; //通道处于空闲时的输出 TIMER_OC_IDLE_STATE_LOW
timer_ocintpara.outputnstate = TIMER_CCXN_ENABLE; //互补通道输出状态
timer_ocintpara.ocnpolarity = TIMER_OCN_POLARITY_HIGH; //互补通道输出极性
timer_ocintpara.ocnidlestate = TIMER_OCN_IDLE_STATE_LOW; //互补通道处于空闲时的输出
timer_channel_output_config(TIMER0,TIMER_CH_3,&timer_ocintpara);
timer_channel_output_mode_config(TIMER0,TIMER_CH_3,TIMER_OC_MODE_PWM0); // TIM1 - CH0 PWM0模式
timer_channel_output_pulse_value_config(TIMER0,TIMER_CH_3,(50* (SystemCoreClock/2/PWM)/100)); // 初始占空比20% 20*(100000000/PWM)/100 99
timer_enable(TIMER0);
这是我按照官方例程写的程序,但是管脚没有生成PWM波,查询时钟的占空比 确实有设置成功 |