On Sun, Feb 12, 2017 at 11:27:16AM +0000, Mintz, Yuval wrote: > Richard, there are quite a bit of inaccuracies in the calculation here.
Where? If you compare this algorithm with yours, you will discover that it produces significantly lower error for ppm < 60. > Your suggestion seems to: > a. Assume that the required period should be in ns, not in > 16*ns units. > b. mishandles the +8/-8 in the calculation. > c. Doesn't seem to consider the upper bound on period. Duh, you would have to convert the result into the proper form for the HW register and add bounds checking. I mean, that goes without saying. The important fact is that your algorithm it not optimal for ppm < 60. (I assumed that the -8 thing was a typical HW programming effect, where you dial N-1 to get N. The fact that you add 8 back in to calculate the effective ppb confirms that assumption. If this isn't the case, then maybe you can see a way to adapt what I wrote.) > One thing I still don't get is *why* we're trying to optimize this > area of the code - So you prefer using 21 64-bit divisions when using 8 produces better results? *You* need to explain the "why"... Thanks, Richard