2
\$\begingroup\$

What, in your opinion, would be the most efficient way to interface muptiple (let's say, >20) incremental rotary encoders to GPIO-limited microcontroller (for example, ATxmega128A4U, 44 pin)?

Requirements:

  • It should be possible to operate multiple encoders at the same time.
  • Encoders have integrated push switches.

What I have tried:

  • To search for multi-channel quadrature decoder IC. No luck.
  • To search quadrature decoder to serial IC (Encoder-to-SPI, I2C, etc). No luck.
  • To build a multiplexer-alike logic that would allow to connect as much encoders as possible while saving GPIO's. No luck.
| improve this question | | | | |
\$\endgroup\$
  • \$\begingroup\$ The best way would be to get the appropriate micro for the job. However, if the micro has few other inputs, most 44 pin micros should be able to read 20 inputs. \$\endgroup\$ – Olin Lathrop Dec 22 '15 at 16:16
  • 4
    \$\begingroup\$ You can solder a 64 pin TQFP with a soldering iron. \$\endgroup\$ – Olin Lathrop Dec 22 '15 at 16:24
  • 2
    \$\begingroup\$ Wanting to avoud leadless packages is understandable but leaded SMT packages are relatively approachable and avoiding them would really, really constrain your options. Remaining choices might be a bunch of DIP MCU's as slaves each handling a few encoders, a small FPGA on a premade carrier PCB, or several of the DIP propellers. If you know your encodes are quite slow you might be able to poll them through a GPIO expander. \$\endgroup\$ – Chris Stratton Dec 22 '15 at 16:32
  • 1
    \$\begingroup\$ "quadrature decoder to serial IC (Encoder-to-SPI, I2C, etc). No luck" why not program a small uC to do just this? Depending on or physical setp, it might also make your wiring much simpler. \$\endgroup\$ – Wouter van Ooijen Dec 22 '15 at 17:00
  • 1
    \$\begingroup\$ @StainlessSteelRat - I'm glad it made you laugh. It isn't a joke. The electronics teacher at a local school showed me the technique some years ago. He already taught 13yo children to solder electronics that way. It is faster for a class-room full of children than soldering irons, gives better results, with a higher rate of success. Even better, they use SMD parts, so it looks like modern electronics, which the kids prefer to through-hole. \$\endgroup\$ – gbulmer Dec 23 '15 at 10:11
3
\$\begingroup\$

I am assuming each rotary encoder will have two signals, and may have one more for a switch.

Use multiple microcontrollers (MCUs), with each one handling a subset of the rotary encoders.

Designate one microcontroller as the 'coordinator'. Have the other MCUs ('handlers') communicate with it. If the 'coordinator' actually runs as a communication slave for SPI, I2C or some other convenient interface, the 'handlers' can drive the communication interface interrupt. That way the 'coordinator' will only get triggered when something happens. (Otherwise, the 'coordinator' will have to repeatedly read the other MCU, called polling, which may be less convenient for your system)

You'll need to devise a simple protocol to communicate which encoder has changed, and by how much. That will very likely be more than one byte, which may add a bit of complexity.

Depending on your experience, you might look at microcontrollers which containe quadrature decoder hardware. As an example, ST Micros STM32F parts have timers which can also decode and track quadrature signals.

| improve this answer | | | | |
\$\endgroup\$
2
\$\begingroup\$

Ignoring the pushbutton switches associated with the encoders, a 50-step/second step rate suggests that you can use external multiplexers to read the encoder outputs. You can find 16-to-1 multiplexers (74HC150, 74HC4067), and connect these to the two phases. Drive the address lines of the multiplexers with 4 IO lines, and use 2 lines to read the phases. You can add a 3rd multiplexer to look at the switch contacts.

You can expand the multiplexers as well, using 1 or 2 more lines as select lines.

This

schematic

simulate this circuit – Schematic created using CircuitLab shows a 32-line multiplexer, using 5 select address lines and an external inverter for the most significant address. You can use two IO lines for the MSA, but you must be sure that only one is low at any time.

In practice, you would (at intervals less than 20 msec) read all of the encoder phases, then analyze each pair of bits to determine if the encoder has moved, and take whatever actions are required. For an Atmel, 20 msec is a long time, but it would be important that the software not get involved in some other task and miss a read. If the encoder has moved by 2 steps, there is no way to determine direction.

A complete setup would require 6 multiplexers - 2 per phase and 2 to read the switches, plus 3 inverters (1/2 of a hex inverter chip such as a 7HC04). Total MCU lines would be 8. 5 address lines and 3 inputs.

Total IO operations is 64. 32 address select writes, and 32 data reads. Of course, if you're only using, let's say, 20 encoders, you would only need 40 operations.

| improve this answer | | | | |
\$\endgroup\$
  • \$\begingroup\$ You'd likely need to poll faster than 20 ms. The PEC11 encoders move through all 4 states on each detent, rather than switching between states, and so you have to watch them more quickly to see each transition to tell what is going on. \$\endgroup\$ – whatsisname Dec 22 '15 at 18:10
  • \$\begingroup\$ @whatshisname - OP said 50 step/sec. I interpreted that to mean 50 quadrature changes. \$\endgroup\$ – WhatRoughBeast Dec 22 '15 at 18:30
  • \$\begingroup\$ that's probably what the OP means, but I doubt he knows the specific behavior of this encoder, as 50 detents/sec will result in 200 state changes/sec on the encoder outputs. \$\endgroup\$ – whatsisname Dec 22 '15 at 18:43
  • \$\begingroup\$ @whatsisname is correct. I meant detents per sec, which evaluates to 200 state changes per sec. Apologies. I like this aproach. Will this work with 200 steps per sec? \$\endgroup\$ – Andrejs Cainikovs Dec 22 '15 at 20:33
  • \$\begingroup\$ @AndrejsCainikovs - Well, that depends on what you're doing with the system. At 200 steps/sec, you need to sample at 200 samples/sec, or every 5 msec. And you must not miss any samples. So, can you sample, process the data to extract the phase change, and perform any other tasks required in 5 msec? \$\endgroup\$ – WhatRoughBeast Dec 22 '15 at 21:44
2
\$\begingroup\$

US digital make the LFLS7184-S which interfaces the quadrature A/B outputs to give up/down countes suitable for feeding a logic chip. It's only a single channel but if you are into logic circuits rather than MCUs it might appeal to you.

You can even get a serial output version and a dual version.

It might be worth taking a look at their website.

Here's another dual device from Avago and ELM404 is another device worth considering and, from memory I think TI do one.

Here's the link I used for googling.

| improve this answer | | | | |
\$\endgroup\$
  • \$\begingroup\$ Thanks for the links. ELM404 looks very interesting, but after I found it's price of 8.5$ per piece, I've changed my mind :) \$\endgroup\$ – Andrejs Cainikovs Dec 23 '15 at 14:29
1
\$\begingroup\$

You can simply poll the encoders at a reasonable rate (500Hz-1000Hz perhaps) and apply simple logic to the sequential readings. This can be done in an ISR.

That means you have to read a total of 60 or so inputs and react to them every 1-2msec.. so the routines shouldn't take too much time- preferably in the low 100's of usec. The encoders can be addressed by using several multiplexers per input. I would connect each A input to a 1-of-20 MUX and thence to a single port pin (say bit 0).

I suspect an AVR running at 20MHz and coded in assembly is up to this, and a single 4MHz PIC is probably not. Or use a 32-bit micro (eg. Atmel Cortex M7 running at 300MHz) and relax with everything coded in C. With a 144 PQFP (114 I/O) you probably don't need any additional chips.

| improve this answer | | | | |
\$\endgroup\$
0
\$\begingroup\$

For anyone living in 2018+, try these I2C encoders: https://www.tindie.com/products/Saimon/i2c-encoder-v2/

| improve this answer | | | | |
\$\endgroup\$
  • 5
    \$\begingroup\$ Welcome to EE.SE. Link only answers are discouraged as they are useless when the link dies. To improve the answer you should edit to give a part number, explain the features or benefits and supply a link to the datasheet for further reading. \$\endgroup\$ – Transistor Oct 27 '18 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.