本帖最后由 zhangyh89 于 2022-12-29 19:43 编辑
最近项目中用GD32E103做有刷电机的闭环控制,码盘检测使用的是PA15 PB3,偶尔出现电机运行几十分钟后检测不到码盘脉冲信号的情况,后来示波器监控码盘信号发现PA15那个引脚接的那一相信号异常,另一路电机用的PB6 PB7,检测到的波形都是正常的方波。以下为码盘接口的配置代码。void timer1_timer3_encoder_config(void)
{
timer_oc_parameter_struct timer_ocinitpara;
timer_parameter_struct timer_initpara;
rcu_periph_clock_enable(RCU_TIMER1);
rcu_periph_clock_enable(RCU_TIMER3);
rcu_periph_clock_enable(RCU_GPIOA);
rcu_periph_clock_enable(RCU_AF);
timer_deinit(TIMER1);
timer_deinit(TIMER3);
//TIEMR1 ENCODER -> PA15-DM1A PB3-DM1B
gpio_pin_remap_config(GPIO_SWJ_SWDPENABLE_REMAP, ENABLE);
gpio_pin_remap_config(GPIO_TIMER1_PARTIAL_REMAP0, ENABLE);
gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_15);
gpio_init(GPIOB, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_3);
//TIEMR3 ENCODER -> PB6-DM2A PB7-DM2B
gpio_init(GPIOB, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_6|GPIO_PIN_7);
timer_initpara.prescaler = 0;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 0xFFFF;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER1,&timer_initpara);
timer_quadrature_decoder_mode_config(TIMER1, TIMER_ENCODER_MODE2, TIMER_IC_POLARITY_FALLING, TIMER_IC_POLARITY_FALLING);
timer_enable(TIMER1);
timer_init(TIMER3,&timer_initpara);
timer_quadrature_decoder_mode_config(TIMER3, TIMER_ENCODER_MODE2, TIMER_IC_POLARITY_FALLING, TIMER_IC_POLARITY_FALLING);
timer_enable(TIMER3);
}
|