Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
20 years ago

usleep() accurate ?

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

7 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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...
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

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

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

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

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

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