本帖最后由 风来吴山 于 2021-3-27 15:49 编辑
#21ic问答#我想将PC6这个引脚作为TIMER2_CH0使用输出PWM,按照手册的说明进行了如下初始化,但是PC6这个引脚在初始化之后,使用示波器查看,没有PWM输出,请问这里是哪的问题呢?
初始化的源码已贴,望大佬指点,万分感谢了。
static void init_laser_output_io(void)
{
rcu_periph_clock_enable(RCU_GPIOA | RCU_GPIOB | RCU_GPIOC | RCU_AF);
gpio_pin_remap_config(GPIO_SWJ_SWDPENABLE_REMAP, ENABLE);
gpio_pin_remap_config(GPIO_TIMER0_PARTIAL_REMAP, ENABLE);
gpio_pin_remap_config(GPIO_TIMER2_PARTIAL_REMAP, ENABLE);
gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_11 | GPIO_PIN_15);
gpio_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_6);
gpio_init(GPIOC, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_6);
}
void init_laser_3(void)
{
timer_oc_parameter_struct timer_ocintpara;
timer_parameter_struct timer_initpara;
rcu_periph_clock_enable(RCU_TIMER2);
timer_deinit(TIMER2);
/* TIMER2 configuration */
timer_initpara.prescaler = 9;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 5400;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER2, &timer_initpara);
/* CH0 configuration in PWM mode1 */
timer_ocintpara.ocpolarity = TIMER_OC_POLARITY_HIGH;
timer_ocintpara.outputstate = TIMER_CCX_ENABLE;
timer_ocintpara.ocnpolarity = TIMER_OCN_POLARITY_HIGH;
timer_ocintpara.outputnstate = TIMER_CCXN_DISABLE;
timer_ocintpara.ocidlestate = TIMER_OC_IDLE_STATE_LOW;
timer_ocintpara.ocnidlestate = TIMER_OCN_IDLE_STATE_LOW;
timer_channel_output_config(TIMER2, TIMER_CH_0, &timer_ocintpara);
/* CH0 configuration in PWM mode1,duty cycle 50% */
timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_0, 2700);
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);
/* enable */
timer_enable(TIMER2);
}
|