Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.

Timestamp timer problem

Altera_Forum
Honored Contributor II
858 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
129 Views

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

or use IORW macro.
Altera_Forum
Honored Contributor II
129 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
Altera_Forum
Honored Contributor II
129 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.
Reply