Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

Not applicable
I tried to use the Timer Apps to get the current time since the timer is started, but it doesn’t seem working;
Look at the following code :
Inside the infinite loop, the value elapsedTime receive the result of TIMER_GetTime(&TIMER_0).
It should increase at each loop right ? However, at the third loop, the value decrease, and increase again.

I configured the App with CCU8, a time interval of 1000 us, and no time interval event.
I don’t need to generate event, but I don’t know how to choose the timer resolution (From 0 to 1 count, the time taken is 1ms for example).
With a time interval of 1000 us, I have the following :
initTime = 119
timerRunning = 1
1. elapsedTime = 62730
2. elapsedTime = 2844
3. elapsedTime = 40827
4. elapsedTime = 41261
5. elapsedTime = 13538

The result should increase at each loop, or it seem random.


int main(void)
{
DAVE_STATUS_t status;
TIMER_STATUS_t timer_status;
uint32_t initTime;
uint32_t elapsedTime;

uint32_t i,j,k = 0;
uint32_t test = 0;
uint8_t timerRunning = 0;
status = DAVE_Init(); /* Initialization of DAVE APPs */

if(status != DAVE_STATUS_SUCCESS)
{
/* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */
XMC_DEBUG("DAVE APPs initialization failed\n");

while(1U)
{

}
}

TIMER_Start(&TIMER_0);
if ( TIMER_GetTimerStatus(&TIMER_0)) // TIMER_GetTimerStatus(&TIMER_0) : return true = timer is running
{

initTime = TIMER_GetTime(&TIMER_0);
timerRunning = 1;
}


/* Placeholder for user application code. The while loop below can be replaced with user application code. */
while(1U)
{

j = 0;
for (i=0; i<365000; i++)
{
j = i+1;
}
j = 0;

elapsedTime = TIMER_GetTime(&TIMER_0);
}
}



Any help please ?


Nicolas
0 Replies