问答

汇集网友智慧,解决技术难题

飞翔的鱼2019

TA的家园币:171  

  • GD32E230的定时器读出值和CNT寄存器不一致

    如题,用的是TIMER2的输入捕获,能进中断,但是用timer_counter_read(TIMER2);函数读出的值与仿真中CNT中的值差别非常大IO的初始代码/*configinputcaptureioalternate*/gpio_mode_set(GPIOB,GPIO_MODE_AF,GPIO_PUPD_PULLUP,GPIO_PIN_0|GPIO_PIN_1);gpio_af_set(GPIOB,GPIO_AF_1,GPIO_PIN_0);gpio_af_set(GPIOB,GPIO_AF_4,GPIO_PIN_1);TIMER2初始化代码voidtimer2_inital(void){timer_parameter_structtimer_parameter;timer_ic_parameter_structtimer_ic_parameter;rcu_periph_clock_enable(RCU_TIMER2);timer_parameter.alignedmode=TIMER_COUNTER_EDGE;timer_parameter.clockdivision=TIMER_CKDIV_DIV1;timer_parameter.counterdirection=TIMER_COUNTER_UP;timer_parameter.period=0xffff;timer_parameter.prescaler=24;timer_parameter.repetitioncounter=0;timer_init(TIMER2,&timer_parameter);timer_ic_parameter.icfilter=0;timer_ic_parameter.icpolarity=TIMER_IC_POLARITY_RISING;timer_ic_parameter.icprescaler=TIMER_IC_SELECTION_DIRECTTI;timer_ic_parameter.icselection=TIMER_IC_PSC_DIV1;timer_input_capture_config(TIMER2,TIMER_CH_2,&timer_ic_parameter);/*enableandsetTIMER2interrupt*/nvic_irq_enable(TIMER2_IRQn,1U);timer_auto_reload_shadow_enable(TIMER2);timer_interrupt_enable(TIMER2,TIMER_INT_CH2);timer_enable(TIMER2);}请大侠们诊断下,问题出在什么地方