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.
12455 Discussions

Nios II timer and erroneous usleep() results

Altera_Forum
Honored Contributor II
1,465 Views

I am using a Nios II processor running at 50MHz with a timestamp timer and a system timer. I am noticing that the usleep() function is not returning expected time delays. For the code: 

 

frame_start_time = alt_timestamp(); 

usleep(400); 

frame_stop_time = alt_timestamp(); 

delay = frame_stop_time - frame_start_time; 

 

I get a delay value of 47,342 where I would expect a value of 20,000. Am I misunderstanding how the alt_timestamp() counter is counting or how the usleep() function operates? The alt_timestamp() function does produce expected timing results in another location in the code, I am just not able to get expected delays using the usleep() function.
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
318 Views

usleep() resolution is almost certainly limited by some time interrupt - it will only return after the relevent interrupt. 

In order to guarantee the minumim sleep time it is also likely that one clock period is always added. 

If you preceed the code above with another usleep() call, and then vary the interval you'll see the quantisation (etc).
Reply