CC2640R2F定时器修改定时时间后启动会延时一段时间才产生定时中断事件

举人 1320 points

CC2640R2F定时器设置定时中断, 如果修改定时时间且定时时间缩短, 定时器开启后不能立即产生定时中断, 这是什么原因?

配置代码:

void TimerHzInit(void){

GPTimerCC26XX_Params params;

hz = 20;
GPTimerCC26XX_Params_init(&params);
params.width = GPT_CONFIG_32BIT;
params.mode = GPT_MODE_PERIODIC;
params.direction = GPTimerCC26XX_DIRECTION_UP;
params.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
Power_setDependency(PowerCC26XX_XOSC_HF); //使能高速时钟
HzGPTimer = GPTimerCC26XX_open(4, &params);

GPTimerCC26XX_Value loadVal = 48000000 / hz - 1; //47999
GPTimerCC26XX_setLoadValue(HzGPTimer, loadVal);
GPTimerCC26XX_registerInterrupt(HzGPTimer, HztimerCallback, GPT_INT_TIMEOUT);
TimerHZStartOrStop(0);

}

void TimerHZStartOrStop(uint8_t flag)
{

if(flag == 1) //打开定时器
{
GPTimerCC26XX_start(HzGPTimer);

}
else if(flag == 0) //关闭定时器
{
GPTimerCC26XX_stop(HzGPTimer);

}
}

void setTimerHZ(uint16_t num)
{
if(num >= 1 && num <= 120) 
{
hz = num;
TimerHZStartOrStop(0);
GPTimerCC26XX_Value loadVal = 48000000 / hz - 1; //47999
GPTimerCC26XX_setLoadValue(HzGPTimer, loadVal);
}
}

7 个回复