Pages: [1]   Go Down
Author Topic: External Interrupt "Multiplexer"  (Read 1274 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there a straightforward way to have a state change on any one of several logic lines trigger a state change on a single pin?

Imagine, for example, that I have two quadrature encoders and want to connect them to an Arduino, which only has 2 external interrupts. (Even worse, my Ardumoto shield from Sparkfun uses one of those pins as a PWM output.) Anyway, it seems that I should be able to feed the pulses from all 4 lines to some sort of circuit which would then toggle its output when any of its inputs change. That way I only need one interrupt to call an ISR which then checks the state of four pins and calculates rotation. By the way, I may need the resolution provided by following all 4 transitions, so just interrupting on one of the quadrature lines might not do the trick.

It seems like the solution might be a cascade of flip flops. But I don't want to reinvent the wheel, as it were, if such a thing already exists. This can't be a novel concept, right?

I ran a few searches here and on the internet at large and did not find much. Perhaps I am using the wrong search terms.

Thanks for your help.
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 360
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Use Pin Change Interrupts - there's one for each port of 8 pins, which serves much the same function as you are looking for - the interrupt fires if any of the pins change.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17301
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Anyway, it seems that I should be able to feed the pulses from all 4 lines to some sort of circuit which would then toggle its output when any of its inputs change. That way I only need one interrupt to call an ISR which then checks the state of four pins and calculates rotation. By the way, I may need the resolution provided by following all 4 transitions, so just interrupting on one of the quadrature lines might not do the trick.

As Aeturnalus stated there is pin change interrupt function.

But for the record what you wish to do using an existing external user interrupt pin is pretty easy to do, just wire a common OR gate using two diodes and one pull-up resistor. Wire each channel to a diode cathode and also to a digital input pin and set the interrupt to CHANGE mode. Encoder common wires to ground. Then in the ISR read the digital input pins and compare with last reading and decide if its a + or - step.

Lefty
« Last Edit: August 10, 2011, 11:15:02 pm by retrolefty » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Excellent. Thanks! I was limiting myself to the basic core Arduino language and didn't know about pin change interrupts: http://arduino.cc/playground/Main/PcInt

That will solve the problem. As for the OR gate, I thought about that, but the problem is I need to trigger the interrupt not only on the change from 00 to 01, but also on the change from 01 to 11, or 11 to 10, and so on. I looked at the truth table for a bit and saw that I need a memory element like a flip flop because the new output turns out to be a function of the inputs and the previous output.

Anyway, it's all moot. ATMEL did something useful inside the chip and I don't need to worry about what that something was. Pin change interrupts it is!

Thanks
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34547
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
As for the OR gate, I thought about that, but the problem is I need to trigger the interrupt not only on the change from 00 to 01, but also on the change from 01 to 11, or 11 to 10, and so on.
Then you need an XOR gate and trigger of both edges.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I took a look at the XOR too, but then thought that it wouldn't help because it doesn't change state on the transition from 00 to 11 or 10 to 01.

HOWEVER, what are the chances of that?  In fact, on a quadrature encoder (or Gray code encoder for that matter), the chances are ZERO. So yeah, I guess the XOR gate actually does serve the purpose.

That just serves to remind me that theory and practice are different things. That is, the pure theory of my application (toggling an output on a state change of any one of several inputs) leads to a different solution when I take the real-life constraints of my inputs into account (in this case, that only one bit can change at a time).
Logged

Pages: [1]   Go Up
Jump to: