I've mostly been following, but why are you limited to selecting a thread with some (seemingly significant) error %? Is this a function of the discretization of the encoder/motor pulses? Or a concern to stay away from floating point math?
You struck a nerve, but in a good way. Made me think.
My first pass at this showed the error just as a drift. Today, decided to add in the effect of the Bresenham algorithm with its discrete math and stepper control. What I see for the 100 TPI case is an overall drift due to the pitch error, and quantization due to the discrete nature of the algorithm. I plotted the pitch error in % between the ideal position and that given by the discrete Bresenham, vs. the number of thread pitches. Due to laziness, I only plotted out to 24 pitches. At 24 threads, there is a cumulative error of 1.3%
of the thread pitch, or 0.013 x 0.01 = 0.00013". Yes, that is 1.3 tenths. So for 100 threads, it would be 0.00013 x 100/24 = 0.00054 or 5.4 tenths. That would mean the thread pitch for the 100th pitch would be 0.01000 - 0.00054 = 0.00946" instead of 0.01000".
I suspect the error won't be a practical issue, but have to agree it doesn't look pretty! Would be nice if the error was 0 and a flat line.
The advantage of the Bresenham algorithm is it is extremely simple to implement and executes very quickly. My version will execute at spindle RPM's over 6000, which is 3 times faster than my chuck is rated for. The disadvantage is the sawtooth error, and the pitch error. The overall pitch error can be controlled by how many decimal points we choose in the truncated fraction that is needed. Not sure how to control the sawtooth amplitude, but I haven't thought much about that yet.
For the example above I used 4 points after the decimal and have -0.53% error at 10 pitches, using N=469, D=10000. If I use 5 decimal places after the decimal, (N=293, D=6250) I can reduce the error to -0.11 %. However the peak quantization error of 0.5% stays pretty much the same.
In the case of N=3, D = 64, the ratio is exact compared to what is required. Then all we have is quantization error, of 0.5% of thread pitch. There is no cumulative error.
So thanks for forcing me to think about this. Will do a more exhaustive search for the ratios to reduce my error.