Altera_Forum
Honored Contributor
19 years agoTimestamp 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