|
本帖最后由 tinnu 于 2018-10-4 00:44 编辑
- void pwm_pin_config(void)
- {
- rcu_periph_clock_enable(RCU_GPIOA);
-
- gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLDOWN,
- GPIO_PIN_6|GPIO_PIN_7);
- gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ,
- GPIO_PIN_6|GPIO_PIN_7);
- gpio_af_set(GPIOA, GPIO_AF_5,
- GPIO_PIN_6|GPIO_PIN_7);
- }
- void pwm_timer_config(void)
- {
- timer_parameter_struct timer_initpara;
- timer_oc_parameter_struct pwm_initpara;
-
- pwm_pin_config();
-
- rcu_periph_clock_enable(RCU_TIMER15);
- timer_deinit(TIMER15);
- timer_initpara.prescaler = 1800-1;
- timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
- timer_initpara.counterdirection = TIMER_COUNTER_UP;
- timer_initpara.period = 1200-1;
- timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
- // timer_initpara.repetitioncounter = 0;
- timer_init(TIMER15,&timer_initpara);
- /* TIMERf15通道控制更新中断启用*/
- // timer_interrupt_enable(TIMER16,TIMER_INT_UP);
- // nvic_irq_enable(TIMER16_IRQn,0,1);
-
- pwm_initpara.outputstate = TIMER_CCX_ENABLE;
- //pwm_initpara.outputnstate = TIMER_CCXN_DISABLE;
- pwm_initpara.ocpolarity = TIMER_OC_POLARITY_HIGH;
- pwm_initpara.ocidlestate = TIMER_OC_IDLE_STATE_LOW;
-
- timer_channel_output_config(TIMER15, TIMER_CH_0, &pwm_initpara);
-
- timer_channel_output_mode_config(TIMER15, TIMER_CH_0, TIMER_OC_MODE_PWM1);
-
- timer_channel_output_pulse_value_config(TIMER15, TIMER_CH_0, 1000);
-
- timer_channel_output_shadow_config(TIMER15, TIMER_CH_0, TIMER_OC_SHADOW_ENABLE);
- /* TIMER15计数器启用*/
- timer_enable(TIMER15);
- }
复制代码
实测定时器部分配置是没问题的,用中断闪烁led成功了,但PA6引脚保持低电平没有pwm波产生
|
|