Timer accuracy issue

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Timer accuracy issue

1,575件の閲覧回数
sachin1296
Contributor I

Hi everyone
I am trying to create a timer for 1000 milliseconds using TIMER0 in NXP PN7462 but it will generate a ~1050 milliseconds timer
and that will create an issue for me so help me to resolve this issue.

Here I share the code for that timer.

static void vAPP_TXTime_Off_Timer_Callback(void)
{
//GPIO LOW
}

void vAPP_Timer0_ConfigureTimer (phhalTimer_Timers_t * psTimer,uint32_t dwTimePeriod, pphhalTimer_CallbackFun_t pCallBackFunc)
{
phStatus_t Status = PH_ERR_INVALID_PARAMETER;
//set callback function and time period
psTimer->pCallBackFunc = pCallBackFunc;
psTimer->dwTimePeriod = dwTimePeriod;

//Set fix count for 1 sec
psTimer->dwTimeOutRegVal = 3412;//count for 1 sec
Status = PH_ERR_SUCCESS;
}

Timer_StartTimer (
phhalTimer_Timers_t * psTimer,
phhalTimer_Mode_t eRunMode)
{
phhalTimer_Regs_t *psTimerRegs;
phhalTimer_Id_t eTMode;
eTMode = psTimer->bTimerId;

psTimerRegs = (phhalTimer_Regs_t *)(TIMERS_TIMER0_CONTROL_REG + (uint32_t)(eTMode * PHHAL_HWTIMER_REGS_SIZE));

psTimerRegs->dwCtrlReg = (uint32_t)eRunMode;

/* set timeout wrt units. */
psTimerRegs->dwTimeoutReg = psTimer->dwTimeOutRegVal;

if (psTimer->dwTimeOutRegVal)
{
/* Enable interrupt. */
PH_REG_SET(TIMERS_INT_SET_ENABLE_REG, (1UL << eTMode) );
}

return PH_ERR_SUCCESS;
}

void vAPP_Timer0_Start ( uint32_t dwTimerInterval, void *pTimerCallback )
{
uint32_t dwTimerVal = 0;
phhalTimer_Units_t eTimerUnit = E_TUNIT_MILLI_SECS;

// Check if the Timer Period passed in greater than specified milliseconds
// and needs to be converted into seconds.

if(dwTimerInterval > 4096)
{
dwAPP_Tx_Off_TimerInterval_Remaining = dwTimerInterval - 4096;
dwTimerVal = 4096;
}
else
{
dwAPP_Tx_Off_TimerInterval_Remaining = 0;
dwTimerVal = dwTimerInterval;
}

// Request the Timer 0
if (phAPP_Timer_RequestTimer0(eTimerUnit, &pstHAL_HostTxOffTimer) != PH_ERR_SUCCESS)
return;

// Configure the Timer with the Time Period and Call back
vAPP_Timer0_ConfigureTimer(pstHAL_HostTxOffTimer, dwTimerVal , (pphhalTimer_CallbackFun_t)pTimerCallback);

// Start the timer in free running mode
Timer_StartTimer(pstHAL_HostTxOffTimer, E_TIMER_FREE_RUNNING);

// Set the Timer Status as Timer Started
bAPP_Tx_Off_Timer_Status = 1;
}

main()
{
//GPPIO HIGH
vAPP_Timer0_Start(3412,&vAPP_TXTime_Off_Timer_Callback)
}

0 件の賞賛
返信
2 返答(返信)

1,517件の閲覧回数
sachin1296
Contributor I

Thanks, Daniel 

But timer 2 and timer 3 are used for another purpose in my code and I have to use timer 1. So please suggest any solution

0 件の賞賛
返信

1,530件の閲覧回数
danielchen
NXP TechSupport
NXP TechSupport

Hi sachin:

 

The PN7462 family IC provides four general-purpose timers. Timer0 and timer1 are 12bit timers at 3kz frequency . Timer2 and Timer3 are 32-bit at 20Mhz frequency, so timer2 and timer3 have a higher accuracy.  I would suggest you use timer2 or timer3.

The Timer HAL provides APIs to manage the lifecycle of an HW timer.

danielchen_0-1644449310105.png

 

Regards

Daniel