21ic问答首页 - GD32E230的定时器读出值和CNT寄存器不一致
GD32E230的定时器读出值和CNT寄存器不一致
飞翔的鱼20192021-01-21
如题,用的是TIMER2的输入捕获,能进中断,但是用timer_counter_read(TIMER2);函数读出的值与仿真中CNT中的值差别非常大IO的初始代码
/*config input capture io alternate */
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初始化代码
void timer2_inital(void)
{
timer_parameter_struct timer_parameter;
timer_ic_parameter_struct timer_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);
/* enable and set TIMER2 interrupt */
nvic_irq_enable(TIMER2_IRQn, 1U);
timer_auto_reload_shadow_enable(TIMER2);
timer_interrupt_enable(TIMER2,TIMER_INT_CH2);
timer_enable(TIMER2);
}
请大侠们诊断下,问题出在什么地方
/*config input capture io alternate */
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初始化代码
void timer2_inital(void)
{
timer_parameter_struct timer_parameter;
timer_ic_parameter_struct timer_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);
/* enable and set TIMER2 interrupt */
nvic_irq_enable(TIMER2_IRQn, 1U);
timer_auto_reload_shadow_enable(TIMER2);
timer_interrupt_enable(TIMER2,TIMER_INT_CH2);
timer_enable(TIMER2);
}
请大侠们诊断下,问题出在什么地方
您需要登录后才可以回复 登录 | 注册