Forum Topic - Timemeasurement & Sleep:
   
Timemeasurement & Sleep  
Hello guys,

I try to run some measurements on my TQMa28 Board with QNX. For that I created a very easy program.

strt = ClockCycles();
usleep(5);
end = ClockCycles();
elapsed_clks = end - strt;
elapsed_ns[count] = messwerte * 1000000000 / SYSPAGE_ENTRY(qtime)->cycles_per_sec;

First of all, I use ClockCycles(), because the clock_gettime() somehow only delievers 0.000000 even though I specified "
CLOCK_REALTIME" as the clock.

After the execution I saved the values in a .txt-file so I could read them and I was a little bit astounded because of 
them.

Every value was around 2.000.000 nanoseconds and I thought that is simply impossible. Afterwards I tried the same method
 without the usleep(5) (so basicly only the 2 ClockCycles()-calls) and the results were around 500ns (with my board it's
 impossible to measure below 500ns because the SYSPAGE_ENTRY(qtime)->cycles_per_sec; delivers a number around 2.000.000)
.

So the 500ns was a value I did expect, with usleep I expected something around 5500ns (the usleep(x) function let's the 
system sleep for x microseconds). The problem is: I need the usleep function but with results like this...

Does somebody know what I can do about this? If you have any further questions don't hesitate and ask me.

Yours sincerely
Adrian

PS: I didn't change anything of the properties everything is the default values from Momentics.
Re: Timemeasurement & Sleep  
Have a look at the following two topics in the QNX Documentation to understand the behaviour you are seeing and how 
timers (including usleep) works in QNX Neutrino.

In the product document titled: "QNX Software Development Platform > Programming > Programmer's Guide" see the section 
titled; Tick, Tock: Understanding the Microkernel's Concept of Time
In that entry there is also a link to: "Clocks, Timers, and Getting a Kick Every So Oftern (Getting started with QNX 
Neutrino)"

Basically, for the timing calls that you are using, timer resolution can be no finer than your system's ticksize, which 
defaults to 1 ms.