Go Down

Topic: Read several (9) Optical Encoders (Read 1 time) previous topic - next topic


I am using 9 optical encoders and am looking for a solution that avoids having to use several micro-controllers in order to maximize the number of interrupts-pins.

Right now i am working with the Arduino Mega (ATmega1280) and am reading in 3 encoders over the offered 6 interrupt pins. Having 9 encoder means, i would need 18 interrupt pins!

I found some discussions online suggesting using PCINT pin change interrupts on normal I/O pins or using an external port expander, but i am skeptical as it seems to require to do the actual data polling outside of the interrupt method, which could mean loss of data and therefore losing precision of the encoder rotation value (encoder = incremental).

Oh, and i should probably add that all of encoders will be in use at the same time, giving each up to 100-600 pulses per second.

Any hints, tips or experience reports would be highly appreciated!



The Avago HCTL-2022 is a high-speed 32-bit quadrature counter.  You can have 9 of them share the data bus (8 pins) and address pins (2 pins) and need an output enable pin for each (9 pins).  You an use a 4-bit decoder to provide the enables from four pins.

If you can find something similar with an I2C or SPI interface that would save a lot of pins.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp
See who has no social life: https://forum.arduino.cc/index.php?action=stats :)


thanks, this looks promising! haven't stumbled over quadrature-decoder chips yet!
i see they also have a 2-channel quad-counter, so i would be able to reduce it to 5 chips.

what i am not completely clear on is, how they would share the data bus?
and why would i need an output-enable pins? couldn't they just be 'always on'?


ok. spend some time with the data sheet and it makes sense now!
the enable-pins would activate only one chip at a time, and then i can use the address-pins to get the 4 consecutive 8-bits (32bit data) and only the activated chip would send  back results on the shared data bus.

the other option seems to be to do pin change interrupts and do my own counting on the arduino. so i can reset the counter myself (which i will do regularly with a reed switch positioned at angle 0).

would you say going with the external-decoder is more advisable, will produce more accurate data?


I believe you can use pin change interrupts to detect any change on any set of pins - thus only one handler is needed (well perhaps 3 as there are 3 groups of pins)
[ I DO NOT respond to personal messages, I WILL delete them unread, use the forum please ]


yes, i started implementing that strategy. but, then i heard that interrupts are actually not able to interrupt other interrupts. which might cause troubles when you have all of them turning at once at a high speed.

now i am considering just polling them all via a timer interrupt. then i need no interrupt-pins. hopefully the processing speed is up for that. The count-change might occur at rates of 0.1-1ms.

Go Up