本帖最后由 lianqingde 于 2024-10-30 13:46 编辑
GD32外部脉冲计数片子是管道gd32fvgt6,使用timer0,pe7的remap功能。
void timer_config_M1(void)
{
timer_parameter_struct timer_initpara = {0};
/* RCU */
rcu_periph_clock_enable(RCU_GPIOE);
rcu_periph_clock_enable(RCU_TIMER0);
rcu_periph_clock_enable(RCU_AF);
gpio_pin_remap_config(GPIO_TIMER0_FULL_REMAP, ENABLE);
/* GPIO-ETI */
gpio_init(GPIOE, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_7);
/* TIMER1 config */
timer_deinit(TIMER0);
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(TIMER0,&timer_initpara);
timer_input_trigger_source_select(TIMER0, TIMER_SMCFG_TRGSEL_ETIFP);
timer_external_clock_mode1_config(TIMER0, TIMER_EXT_TRI_PSC_OFF, TIMER_ETP_FALLING, 15);
timer_enable(TIMER0);
}
u32 Encoder=0;
void MotorM1ControlTask(void)
{
gpio_config_M1();
timer_config_M1();
while(1)
{
Encoder = timer_counter_read(TIMER0);
//timer_counter_value_config(TIMER0, 0);
delay_ms(20);
}
}
|