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.
The usleep() function sleeps for a specified number of milleseconds, give that a shot.
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.
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.
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.