Encoder input to multiple Arduino Mega pins

Hi.
I’m using an Arduino Mega 2560 to implement an electronc leadscrew for a lathe, based on a project I found on github.
This project basically has to drive the leadscrew motor of the lathe based on the quadrature spindle encoder which provides spindle speed / position feedback to the MCU.
The original project does the following:
-in thread cutting mode the encoder inputs trigger an interrupt, and the ISR fires the correct number of motor steps for each encoder pulse, to keep the carriage in sync with the spindle and cut the thread with the correct pitch.
-in feed mode the program counts the encoder pulses (using the same ISR) for a fixed period of time and derives the speed at which it needs to drive the motor. The speed of the leadscrew motor then remains fixed regardless of the spindle speed, because keeping track of it at high RPM using the ISR would be too intensive for the MCU.

I would like to also keep track of the spindle speed and adjust the leadscrew speed in feed mode, but that means counting 42rps x 600ppr x 4edges pulses every second.
To do so I’d need to use the encoder inputs (or at least one the 2) as a clock signal for one of the arduino timers, but none of the available interrput pins are also connected to a timer clock input.

So the question is: can I somehow connect the encoder A wire to 2 arduino pins, so that I can use its signal both to fire interrupts and to drive a timer (not at the same time)?

Thank you

Have You watched the Youtube guy Claugh 42? We worked with such setups and even sell systems?

Back to You. As You don’t need/use the interrupt pins in feed mode You could use the interrupts in any other way. Tapping the interrupt signal to a suitable pin must be okey.

Hi.
Yes, I saw its version, but in the end I decided to build my own, starting from this project, simplified to remove the features I don’t need, and adapted to the hardware I had laying around (Arduino Mega instead of the UNO, tm1638 module instead of the 20x4 display).

My idea is exactly that, but I was wondering if I can simply connect the A wire to 2 pins at the same time (with a jumper wire connecting the 2 pins) and just use one or the other in the code, or if a more complex circuit is needed to dinamically connect the signal to 1 pin.

Of course you can, what makes you think otherwise?

Whether it's the best solution to your problem is a different question I cannot answer.

Honestly I have no idea, I just wasn’t sure if connecting 2 pins in a PULLUP configuration together could create any kind of issue

As Perry B says in reply #4 It must be possible. To be sure please post a link to the datasheet of the encoder and a handdrawn schematics of the encoder signals.

If your feed is by stepper, why would you need an encoder on it? The feed rate would be proportional to the stepper pulse rate which you already know.

1 Like

Pleas explain that in a pencil schematics! You should not wire both encoder signals together, short circuiting them.

This is the encoder. I don’t have a full datasheet for it, the description states “output NPN open collector”.
With “connecting the 2 PINS together” I don’t mean A and B from the encoder, I mean connecting the A wire both to pin 3 (for the interrupt) and whatever other pin a timer clock is connected to (edit: pin 38 for T0 or 47 for T5)

The encoder tracks the spindle speed / position, the motor drives the leadscrew to move the carriage in sync with the spindle rotation.

OK, gotcha.

Good. That output surely manages 2 Arduino pullups giving a current of 1 mA together.

Perfect, I’ll try to connect the A signal to both pins, update the code and let you know how it goes.
Thank you

It will work. Your welcome. Hope the timer plans work. That question is beyond my comfort zone.

Yep, it works just as expected. I use Timer 5 as a counter of the encoder pulses, and timer 4 to calculate the new spindle speed every 0.2s and update the leadscrew speed accordingly.

1 Like

Thanks for telling it works for You. That was the goal.

Still, running in feed mode the speed is controlled by the stepping rate and measuring speed ought to be unnecessary. But, but, Your setup does what You want.

The speed measurement is for the spindle, while the stepper motor is tied to the leadscrew.
If the ELS is set to advance the carriage 0,1mm/rev, I need to track the spindle RPM to adjust the leadscrew motor speed and keep the increment of 0,1mm/rev.

Yes, You're right. A minor detail slipped by my eye.