I am working on making an Electronic Lead screw for my Schaublin 70 lathe. I happen to have a high precision optical encoder that Im thinking of using for the Spindle encoder. It has 5,000 lines per disc and interpolates that 10x. so were talking about 50,000 pulses/rev. It can output up to 500khz, so 600rpm on the lathe. I will only be using the ELS for screw cutting anyway so 600rpm is plenty.
Anyway. I'm fairly new to programming and Arduino. I have done some stuff with analog temp sensors and what not, but this is pretty heavy for me. So bear with me, I haven't quite wrapped my head around all of my research.
All of the timer/counter threads I have found seem to be in a much lower frequency range. Is this too fast for the these chips. What about measuring rising and falling edges? If you factor in the phased channels were getting into some pretty quick stuff.
If my system were just to count simple pulses (no rising/falling edge) there will be 50,000 pulses/rev. Im looking at steppers for the X-axis with 1.8 degree steps (200steps/rev or .00025" travel per step). If for example I want to cut a 20tpi thread, I would need the stepper to pulse once for every 250 pulses of the encoder. Can I specify a value for the counter to count up to and trigger an interrupt and reset? Again any guidance is appreciated. At this point Im not even looking for specific code so much as general ideas for how this whole thing can work.
Right now all that I have is an Uno but I can purchase whatever board I need to make this work. Thanks in advance.
At that rate, you will be feeding the pulses into a Tn pin (called "external clock source" in the datasheet). With an Uno you will have to use T0 (connected to timer zero) or T1 (connected to timer one). Apparently, timer two does not support an external clock source. The external clock source for timer two is also one of the crystal pins so the conflict prevents you from using timer two.
So it looks like with a Mega, I can use an external clock source on timer5 through pin47. Then I can just use CTC mode and set my value in the compare match register. Right?
If for example I want to cut a 20tpi thread, I would need the stepper to pulse once for every 250 pulses of the encoder. Can I specify a value for the counter to count up to and trigger an interrupt and reset?
Yes. However, I believe you can do everything you want using features of the timers (everything can be done with hardware). If you can do that, the entire processor time is available to do with as you please. You could show status on a display, allow user input, or play a game.
vonmule:
So it looks like with a Mega, I can use an external clock source on timer5 through pin47.
Why do you believe you need a Mega?
Then I can just use CTC mode and set my value in the compare match register. Right?
I think timer one configured for Fast PWM may work better. I believe that mode will work better for generating a pulse. If the count is always even (e.g. 250, 248, 246) then CTC mode would be an easy fit.
I hadn't realized that the Uno had one of its external clock sources routed to a pin on the board. Why PWM I figured I would just write a little snippet of code that would step(or maybe even micro step) the motor every time the control register value is reached.
I suppose I should specify that the encoder will be reading the rotation of the spindle while the stepper controls the x axis.
Are control register values limited to even numbers?
vonmule:
I hadn't realized that the Uno had one of its external clock sources routed to a pin on the board.
Both are available. However, timer zero is used for millis / micros.
Why PWM
CTC mode works well for toggling a pin. PWM works well for generating a pulse. You stated earlier you need a pulse.
Looking at the datasheet, you may be able to output a pulse using CTC mode.
I figured I would just write a little snippet of code...
The risk with code (an interrupt service routine) is latency. I assume even a tiny delay in outputting the pulse will ruin the part. If you can get the timer to generate the pulse, the latency will be essentially zero.
Are control register values limited to even numbers?
No. My comment about even numbers is in regards to CTC mode and toggling.