Saving interrupts

I want to connect two 5v rotary 4bit encoders like the one from sparkfun to an arduino pro 5V.

The program will do some stuff, but priority one is monitoring the encoders, so normally I want to connect both channels to the interrupt pins for full resolution triggering.

The problem is that 4bit means 2 pins per encoder and arduino pro has only 2 interrupts.

I was thinking to connect the 4 channels to normal I/O pins and then connecting each pair of channels through a 1N4148 diode to one interrupt.

To better understand what I mean, the electrical connections will be like that.

ENC_A_CH_A-------1N4148-------INTERRUPT1
ENC_A_CH_A-----------------------I/O1
ENC_A_CH_B ----- 1N4148 ------ INTERRUPT1
ENC_A_CH_B-----------------------I/O2

ENC_B_CH_A-------1N4148-------INTERRUPT2
ENC_B_CH_A-----------------------I/O3
ENC_B_CH_B ----- 1N4148 ------ INTERRUPT2
ENC_B_CH_B-----------------------I/O4

Do you think that will work electrically? Maybe the 1V drop is too much? Would a shottky work at such low currents?

Or perhaps I should just use a fast OR gate IC? Any suggestions on that?

And some noob questions about how the interrupts work...

What happens if both encoders trigger their interrupt at the same time?
What happens if interrupt 2 triggers while interrupt1 is still executing its stuff?
What if interrupt 1 triggers again while the stuff from the previous trigger is still executing?
Do they stuck in a LIFO style?

What happens if both encoders trigger their interrupt at the same time?
What happens if interrupt 2 triggers while interrupt1 is still executing its stuff?
What if interrupt 1 triggers again while the stuff from the previous trigger is still executing?
Do they stuck in a LIFO style?

Here is my best guess at your questions. Certainly not an expert but have played around with having two encoders wired to my Arduino clone and using both user interrupt channels to service them.

  1. Whichever interrupt pin the AVR interrupt logic detects first will get serviced. The other will, I suspect get missed.

  2. Interrupt 1's ISR routine first disables any other interrupts, so #2 interrupt would be missed if it happens while the #1 ISR is active.

  3. Same, I don't think the AVR interrupt logic has any pending interrupt holding flags, so no new interrupts will be detected while in a ISR routine.

That at least is my read on the matter. I might be wrong and certainly I'm not an expert. One method that might prevent missing interrupts while servicing prior ones is to use the attach interrupt on LOW option. That way when the first ISR finishes and interrupts are re-enabled then if the pin signal is still low on the second interrupt pin then it should be detected at that time. This would prevent sensing interrupts on every transition (four per step) of the encoder A&B signals and thus lower the PPR resolution.

Using external or'ing logic (using diodes and a pull-up, or a real or gate) to combine encoder channels wired to a interrupt pins should work in theory I think. The same encoder signals would also have to wire to other input pins so the ISR routine could read all the encoder channels and determine which encoder generated the interrupt and in which direction.

A lot is related to what the encoders are being used for. If they are just user manual input controls to say scroll through a menu or move stepper motors or servos, then missing a interrupt now and then may not be a big deal or even noticeable. However if it was to keep track of the absolute position of a rotating shaft, then it would be a bigger deal.

Lefty