现象:
通过插入硬件输出片段观察到定时器更新后10us左右进入了定时器中断,而该定时器设置中断时间为100us,明显不对
原因:
定时器使能时中断标志触发,允许中断后会立马进入中断
解决方案:
在使能定时器中断前插入定时器中断清除语句即可
以定时器 Timer13为例,设置100us中断
void timer13_init(void)
{
timer_parameter_struct timer_parameter;
rcu_periph_clock_enable(RCU_TIMER13);
timer_deinit(TIMER13);
timer_parameter.prescaler = 83;
timer_parameter.alignedmode = TIMER_COUNTER_EDGE;
timer_parameter.counterdirection = TIMER_INT_UP;
timer_parameter.period = 100;
timer_parameter.repetitioncounter = 0;
timer_parameter.clockdivision = TIMER_CKDIV_DIV2;
timer_init(TIMER13,&timer_parameter);
timer_counter_value_config(TIMER13,0);
timer_interrupt_flag_clear(TIMER13, TIMER_INT_FLAG_UP);
timer_interrupt_enable(TIMER13,TIMER_INT_UP);
nvic_irq_enable(TIMER13_IRQn,0,2);
timer_enable(TIMER13);
}
示例代码中:
timer_interrupt_flag_clear(TIMER13, TIMER_INT_FLAG_UP);
插入到对应位置解决定时器初始化立马进入中断问题
|