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

## Measure Run time of a function in TC399

Level 2
Level 2

Hello,

I need to measure run time of a function on TC399. For that, I am making use of GPT12 timer module.

I have written the following snippet.

initial_value = IfxGpt12_T3_getTimerValue(&MODULE_GPT120);

My_custom_function();

final_value = IfxGpt12_T3_getTimerValue(&MODULE_GPT120);

// Note: I have set the timer direction down.

// Calculate the elapsed timer ticks
if (final_value <= initial_value) {
elapsedTicks = initial_value - final_value ;
} else {
// Timer has wrapped around :: MAX_VALUE=0xFFFF;
elapsedTicks = (MAX_VALUE - final_value ) + initial_value + 1;
}

uint32 timerFrequency = IfxGpt12_T3_getFrequency(&MODULE_GPT120);
uint32 elapsedMilliseconds = (elapsedTicks * 1000) / timerFrequency;

However, sometimes, the run time value is showed as 0ms. I am sure, there is something going wrong. Can you please help me?

Also, does  'IfxGpt12_T3_getTimerValue' this return ticks?

Please guide me through the process.

1 Solution

## Re: Measure Run time of a function in TC399

Level 5
Level 5

Hi @AC2

How about getting STM timer from STMX.TIM.X.U?

in my case, for calculating function runtime, accessing STM module directly.

it is working  well

3 Replies

## Re: Measure Run time of a function in TC399

Level 2
Level 2

Hi,

Can I please get some support?

Thanks in advance! 🙂

## Re: Measure Run time of a function in TC399

Level 5
Level 5

Hi @AC2

How about getting STM timer from STMX.TIM.X.U?

in my case, for calculating function runtime, accessing STM module directly.

it is working  well

## Re: Measure Run time of a function in TC399

Level 2
Level 2

@DownyK  Thanks for the lead! 🙂 It works.