Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

Timestamp timer problem

Altera_Forum
Honored Contributor II
1,024 Views

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
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
295 Views

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

or use IORW macro.
0 Kudos
Altera_Forum
Honored Contributor II
295 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
295 Views

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.
0 Kudos
Reply