usleep VS Timers

I have to periodically sample a memory location in real-time in an infinite loop. I have initially used a usleep command to block and unblock my process to sample the memory location, but I have learned “thanks to mario” that usleep is not 100% accurate especially if placed in an infinite loop (propagation of error). Then is using a timer to generate a pulse to start read cycle accurate? or is there an error that grows once the timer start generating a pulse for couple of days straight, and the frequency of pulse is no longer accurate?

Timer are as precise as the ClockPeriod(). To get accurate timer, you must provide an EXACT multiple of the REAL ClockPeriod().

but don’t you specify the timer iteration in nsec instead of clock period? Lets say that I specifiy my timer to generate pulse every 0.1 sec, will the timer generate pulse exactly at 0.1s interval?

No it will not, there is nothing in this world that is perfect and exact, its all about how much error you can live with. If I tell you if you ask for .1s youll get .09999985 would you be happy with that ;-)

I suggest you read … 826_2.html