Thread: precision delays

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    10

    precision delays

    Hi.
    I am creating a program that performs pwm. In order to do so, I need the most precise timing possible, in order to refresh the image at a professor designed rate. It is a fairly easy assignment, except for the timing issue. We have been using the Sleep function for delays in between refreshing the image, however it is almost completely inaccurate, especially when we input a fixed frequency. We were hoping to find a function that works on clock ticks alone, rather than the sleep function. I imagine that I could make a loop that would stop after so many interupts (depending of course on the speed of the system- which would alos need to be queried) and therefore create the correct delay. Mind you, this delay is not in seconds, but rather milliseconds and less, so it needs to be extra acurate. If anyone has any bright ideas, please help. In the meantime, I will continue to search libraries for this type of function.

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    202
    The usleep() function sleeps for a specified number of milleseconds, give that a shot.

    starX
    www.axisoftime.com

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    10

    Usleep?

    Is that more accurate than the sleep() function? I am looking for something more along the lines of running with the clockrate... real time interupts if possible.
    -Marc

  4. #4
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    DESCRIPTION

    The usleep() function will cause the calling thread to be suspended from execution until either the number of real-time microseconds specified by the argument useconds has elapsed or a signal is delivered to the calling thread and its action is to invoke a signal-catching function or to terminate the process. The suspension time may be longer than requested due to the scheduling of other activity by the system.

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    10

    ...

    Ok I have tried that. It seems to work on my computer fine with timing, however, as I transfer computers, its values are way off, which is the same exact problem as the sleep() function. I was looking for something that would have very similar results across processing speeds. I obviously was way too vague about the issue before.
    -Marc

  6. #6
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    If you're using windows

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Setting Precision Confusion
    By dnguyen1022 in forum C++ Programming
    Replies: 11
    Last Post: 01-14-2009, 10:38 AM
  2. Format Precision & Scale
    By mattnewtoc in forum C Programming
    Replies: 1
    Last Post: 09-16-2008, 10:34 AM
  3. Replies: 1
    Last Post: 04-03-2008, 01:17 AM
  4. Precision based floating-point
    By Mario F. in forum C++ Programming
    Replies: 4
    Last Post: 07-17-2006, 10:35 AM
  5. International Limits on Precision
    By Davros in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-20-2004, 06:32 AM