Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

Timestamp timer problem

Hi ,

I am having some problems in using the timestamp timer. Basically , when i am measuring the time to perform a single instruction, i occasionally(but not always) get a negative answer.I have taken care to call alt_timestamp_start() whenever I use the timer, to ensure that it does not overflow.

Also when i don't change the program and run it again, each time i get a slightly different number for the number of cycles taken. What could be the reason?

My code is as follows :

//CODE

if(alt_timestamp_start() < 0)

{

printf("Timer init failed \n");

exit(0);

}

time1 = alt_timestamp();

time2 = alt_timestamp();

timer_overhead = time2 - time1;

printf("\n timer overhead is %d",timer_overhead);

.........

..........

.......

time1 = alt_timestamp();

*(peripheral_base ) = 0x210f1007

time2 = alt_timestamp();

printf("\n time to perform 1 write to hw is %d" ,(time2 - time1 - timer_overhead));

printf("\n time1 is %lu",time1);

printf("\n time2 is %lu",time2);

//END OF CODE

I get the following output :

//OUTPUT

timer overhead is 246

time to perform 1 write to hw is -12

time1 is 143

time2 is 377

//END OF OUTPUT

Any suggestions ? Am i missing out something ?

Thanks,

Karthik

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    you have to turn on bit31 of the address to uncache the io port access.

    or use IORW macro.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    feynyan :

    you have this problem but otherwise you can read value returned by

    al_timestamp() funciont.

    In my case this function returns always 0

    I cannot understand why

    Do you have some idea?

    ciao

    walter
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You need to start the timestamp first.

    Also the timestamp doesn't roll over, so if it has reached its maximum value it needs to be started again.