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++

usleep() accurate ?

Altera_Forum
Honored Contributor II
2,038 Views

Hello all, 

 

Does anyone have an idea how to make sure the usleep() fonction is accurate. Whatever 

values I set usleep() to (which is in the range of 3 to 50), the resulting pause is in the range 

of 50 to 100us respectively. 

 

Thanks, 

 

eric
0 Kudos
7 Replies
Altera_Forum
Honored Contributor II
769 Views

What Quartus version are u using? (Quartus 4.1 without service pack, had some problems with counters synthesys).  

Furthermore check the timer setting in SOPC (the timer u set in IDE as system timer...), set full featured option...
0 Kudos
Altera_Forum
Honored Contributor II
769 Views

Hello Soin, 

 

I am using Quartus 4.2, SP1 (build 178), with NIOS II IDE version 1.1.0, build 137. 

BTW, I haven't been on the bench yet. I am looking at my simulation and see that 

accesses to certain of my regsiter file are not following the usleep() command. 

 

I am running very simple code, just accessing custom register which have their 

accesses interleaved with usleep() commands. I need accuracy since all my code 

is based on usleep() as I am driving a one-wire interface. Here is trial piece of code: 

 

IOWR_32DIRECT(REGSECT_DGL_0_BASE,0x88,0xBEEF0000); 

usleep(12); 

IOWR_32DIRECT(REGSECT_DGL_0_BASE,0x88,0xBEEF1111); 

usleep(3); 

IOWR_32DIRECT(REGSECT_DGL_0_BASE,0x88,0xBEEF1112); 

usleep(50); 

IOWR_32DIRECT(REGSECT_DGL_0_BASE,0x88,0xBEEF1113); 

usleep(80); 

 

Thanks, 

 

Eric
0 Kudos
Altera_Forum
Honored Contributor II
769 Views

What type of Nios II processor (e,s,f) r u using and at what clock frequency?

0 Kudos
Altera_Forum
Honored Contributor II
769 Views

I am using the /e at 66MHz

0 Kudos
Altera_Forum
Honored Contributor II
769 Views

In this case u will have a "up to 9 DMIPS processor", one instruction each 0.1 us. Perhaps this is critical in the execution of usleep() function...

0 Kudos
Altera_Forum
Honored Contributor II
769 Views

Hello Soin, 

 

I tried the /s, but did not help much....until i figured I was simulating in "debug" mode 

instead of the "release" mode. Last sim in "release" mode this time with /s showed relatively  

good accuracy: ask 3-> got 4.3, 12->13.75 and 50 -> 50.85. I will try with the /e...  

 

I also tried in the meantime with the alt_timestamp() family of functions which would have been an avenue  

to create my own my_usleep() function, but since a few calls are required each time, they  

are not so accurate unless you take into consideration the time for the call to alt_timestamp_start() and 

alt_timestamp() to elapse. But in that case, since comparisons are involved, I guess I would have  

obtained better result having the data cache with the /f (haven't tried). 

 

Thank you very much for your hints. It helped a lot. 

 

Regards, 

 

Eric
0 Kudos
Altera_Forum
Honored Contributor II
769 Views

Hello eboisver, 

reading your last post, i've got another idea: you can try to put -03 optimization level in the project and associated library properties. I think it could be a compilation problem...
0 Kudos
Reply