I'm in the process of building a wood lathe, and I intend to use a rotary encoder that will have 2 purposes :
Display (on an lcd screen) the current rpm of the spindle
When the lathe is idle, display the angular movement (from a set 0). Idea is to be able to use the encoder as a divider, for example to drill a hole at 0, 90, 180 and 270 degrees precisely.
I have a 400ppr rotary encoder, but the problem is that - in mode 1 (rpm), the lathe can reach about 3000 rpm = 50rps = 50x400 = 20k pulses/second coming from the encoder to the arduino (Mega).
Due to mechanical constraints, I can't really change the gear ratio in order to slow down the encoder.
--> is this amount of inputs per second going to be a problem?
If so (and since I don't need position accuracy in this mode), is there a way to "skip" the reading of like 399/400 pulses and read only one each rotation?
On my lathe, I use a simple reflective sensor pointed at a half black/half white disk, pasted on to one end of the lathe shaft, so there are only two state changes per revolution. It has worked without flaw for years using an Arduino Pro Mini to handle the counts and display RPM.
The Arduino Mega (2560?) has built-in hardware (16-bit) to count pulses. With 16-bits you can count up to 65,535 pulses before the counter overflows and I think 20kHz is well within it's capabilities.
Thanks for your inputs. @jremington : your solution seems perfect for rpm, but has a very poor angular precision
I could go for a dual system (with both an optical sensor for rpm and a rotary encoder for angle detection, but with the pulleys, the braking system, the encoder, and the spindle lock, it's already pretty packed in there (and already a lot of parts to design and make), so I'd rather avoid adding yet another system...
@markd833 : is there a specific pin or a specific type of input to use in order to make sure that the mega (yes, 2560) can keep up?
The two-color disk might have better repeatability than an optical encoder without an index/Z signal. If your encoder just has A&B signals, you can't know where zero is across reboots, while top-dead-center might be right at the white-to-black transition on @jremington's disk.
Does 'idle' mean you're turning the spindle by hand - as in the motor is off? Any possibility of getting a contact closure from the on/off switch or motor contactor?
Yes, it's meant to be used - for example - to drill holes (perpendicular to the workpiece) in a spiral pattern.
Once I determine the spot to drill the first hole (and set the angular 0 there), i have to rotate the piece - say 15° - and drill a second hole at a certain linear distance, then repeat.
The spindle is indeed turned by hand, motor off.
I think my rotary encoder doesn't feature a "Z". It has 4 wires (black, red, green (A or B) and white (B or A).
@DaveX : I don't really care about finding back a specific position across reboots. If I have to stop mid-job, I can always go back to the last hole, set the 0 there and start incrementing again...
So, use @markd833's suggestion (post #3) for RPM. Add some code to sense when RPM is below X. If below switch to angular mode, if above switch to RPM mode.
@anon44338819 : the main shaft of the lathe is 35mm, so the pulley that will drive the encoder belt has to be bigger than that. About 7mm thickness seems a minimum (so 14mm on the diameter). So we have a more or less 50mm driving pulley.
So if I want to significantly decrease the speed of the encoder) I'll need a 100+ mm pulley. But the encoder shaft is 6mm diameter by 18mm.
So even if I find a way to fasten it (that's a veeeery long set screw and thread in the pulley), I really doubt it'll run for years at quite high speeds.
--> I'll try @markd833 's option and - if it doesn't work - probably buy an encoder with a Z signal...