Sparky that teensy board is really neat!!
Andrew total agreement, that's what I'd use.
Pekka, commercial encoder per Andrew.
Russell special threads no problem, just depends how you implement the switch processing.
A lookup table for division count per thread switch setting could give any results you care to set up in the table. 6 bits of input would give 64 threads.
It also relieves the processor from doing division. it can be very fast as an algorithm.
Agorithm:
1.) Poll switch setting byte value,
2.) use that as an index to do a lookup in a table, and store the table value found
3.) Increment a count on receiving encoder pulse (interrupt or polling, whatever suits the board)
4.) Compare the count to the stored value
5.) if the count is equal to the stored value, send step pulse, reset count, loop
6.) else loop
Accuracy:
Example:
With a 3 to 1 stepper to leadscrew ratio, and a 10 tpi leadscrew and a 200 step motor, the movement fineness is 6000 steps per inch of carriage movement. That should be plenty.
With a oommon Ebay 600 line encoder at 5 to 1 spindle ratio the fineness of control is 3000 divisions per revolution. The worst rounding error would be in the higher pitches that weren't factors. Let's say 39 tpi was desired for some reason (40 is a factor). The error would be about 0.1% of pitch. Some odball fractional pitch around this fineness of thread could be as bad as 0.7% off. That's theoretical worst case. And coarser threads are better. Oddball fractional pitches around 20 tpi would have a max error of half that. And many common thread pitches are factors.
You could use a finer encoder if this error level was a bother, or you could step up the encoder ratio further -- I don't think it will matter to me on my lathe with its overall tolerances in general. However increasing the pulses per spindle rev increases the noise and calculation speed requirements. I'm not sure that it's worth going further on my lathe.
Another possibility for dealing with rounding errors would be to round down, but accumulate errors in the algorithm, add them, and increment the encoder pulse count when they exceed 1.
I did think about toggle switches for input, and maybe I'd do that later after first going with a dip switch to get things moving. Plus I like the idea I could hide a dip switch more easily.
Ideally a rotary switch with a big metal knob would be a great "old school" solution to fit a traditional looking lathe, I think. You'd have to make one with a PC board and wipers, but it could be done as a later project in itself!
Thank you all for your replies!
