Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Wrong calculations in the timing chapter in one part of the documentation?: (1 Item)
   
Wrong calculations in the timing chapter in one part of the documentation?  
Dear all,

I am currently trying to get into QNX development (Neutrino, 6.5.0 SP1). I think I generally have understood the 
pitfalls regarding timers, timer jitter, tick granularity and so on. But even with all the will in the world, I can't 
understand the math which is given in one of the respective chapters of the documentation, and to be honest, I think the
 documentation is wrong.

Since there is very little time to finish our project (1 week), and since I never had to do anything with QNX until 
three days ago, I hope somebody can help me out here.

Let's look at this document: http://www.qnx.com/developers/docs/6.5.0_sp1/index.jsp?topic=%2Fcom.qnx.doc.
neutrino_getting_started%2Fs1_timer.html&cp=13_4_5

In the section titled "Clock interrupt sources", the author (correctly) states that the timer is driven by 1.1931816 MHz
 (IBM PC). Doing my own math, this means that there are 1,193,181.6 "ticks" per second from the oscillator. If we want a
 tick every 10 ms, this means that we want 100 ticks per second. Thus, to compute the divisor we need, we have to divide
 the oscillator frequency by 100, yielding a result of 11,931.816. Of course, this number can't be but into an integer 
divisor register, and since (at least according to the documentation) some standard says that the faster rate must be 
chosen in such situations, choosing 11931 as the divisor is natural and logic. Until this point, I agree with the author
.

But how on earth could he state that the actual interrupt period is 9.9999296004 ms? When a divisor of 11931 divides an 
input clock of 1,193,181.6 ticks per second, the resulting frequency is 100.00683932612522001509 Hz (ticks per second). 
To get the respective period length, take the inverse of this number; the result is 0.00999931611416066088 s which is 9.
99931611416066088 ms.

So, who of us is right?

In another part of the documentation (http://www.qnx.com/developers/docs/6.5.0_sp1/index.jsp?topic=%2Fcom.qnx.doc.
neutrino_prog%2Ftiming.html&cp=13_7_4), it is stated at multiple places that, if you request one tick every ms, there is
 an offset of 153 ns between the requested and real duration between two ticks because the real tick distance is 0.
999847 ms (on an IBM PC). This seems correct to me:

Doing the same as shown above, if I have an input frequency of 1,193,181.6 ticks per second, and I want to make 1000 
ticks per second from that, the divisor I need obviously is 1,193.1816. Once again, this can't be put into an integer 
register, so 1193 is chosen as divisor. Dividing the input frequency (1,193,181.6) by that divisor, the resulting 
frequency is 1000.15222129086336965633 Hz, which corresponds to a period time of 0.00099984780187693139 s, which is 0.
99984780187693139 ms.

Thus, since I get the same result as the authors of _this_ part of the documentation, I suspect I have a basic 
understanding of how the ticks work. Nevertheless, could anybody explain the calculations which are done in the _first_ 
document mentioned above and tell me if I am right or the respective authors are right?

A bonus question: If the real period time is 0.99984780187693139 ms, why did QNX chose to make that 999847 ns (instead 
of 999848 ns as when rounding normally)?

Thank you very much,

Pitt