0
\$\begingroup\$

I need to count the pulses from a high-res quadrature encoder but the prohibitively high frequency means I can't use my main processor.

I looked into the HCTL-2022 IC which does exactly what I need, although the part now appears to be obsolete.

Are there any other chips which would serve as a suitable substitution? Alternatively, how would I implement a circuit to count the pulses?

\$\endgroup\$
  • 1
    \$\begingroup\$ What does "high frequency" mean to you? \$\endgroup\$ – Elliot Alderson Sep 9 '19 at 17:08
  • 1
    \$\begingroup\$ And what is your main processor? The actual algorithm to implement quadrature encoder counts is pretty small. \$\endgroup\$ – TimWescott Sep 9 '19 at 17:11
  • 1
    \$\begingroup\$ Some uC’s have (hardware) peripherals to handle QEI. \$\endgroup\$ – Tyler Sep 9 '19 at 17:12
  • \$\begingroup\$ A PIC or other small auxiliary micro, programmed as a decoder that talks on SPI or I2C. \$\endgroup\$ – TimWescott Sep 9 '19 at 17:12
  • \$\begingroup\$ @ElliotAlderson, high enough that it would block the processor from executing its other tasks. \$\endgroup\$ – 19172281 Sep 9 '19 at 17:17
1
\$\begingroup\$

I'm not familiar with that chip but a quick scan of the datasheet shows that it has four external interrupts. All that should be required is to monitor, say, one of the encoder outputs with an interrupt pin and when triggered count up or down depending on the status of the other encoder output.

enter image description here

Figure 1. Encoder signals and resultant count.

Pseudo code
// Triggered by encoder output A
interrupt {
  if(B) {
    encoder--    // Encoder is running anti-clockwise.
  } else {
    encoder++    // Encoder is running clockwise.
  }
}

You make the encoder variable as many bits long as required for the accuracy you need.

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

Ok, as far I understood from your comments you have a LPC1768 with QEI, but the real problem is that you want signed math. Well it's not a problem at all, you have just to define or parse the QEI output (let say 32 bit unsigned integer uint) to signed integer int.

You may do all the signed or unsigned math you want. If you subtract actual value in uint format with other uint, you get the uint result, which will give you always the same direction. For the sake of simplification, let we have a compass 0(360)-359 degrees. If you subtract 350-20 you get 330, but if you subtract 20-350 you get 30. The angle difference is always 30 degrees, but you get two different results.

Now suppose you do signed math, same angles 20 and -10, 20--10=30, -10-20=-30. You see, when using signed math, you always get the shortest distance and direction.

Same rules apply when using binary numbers: signed will always give you shortest path - so you don't have to care about roll-over with sign (direction, in which direction should I turn to reach the target with a shortest move).

I give you an advice: there is no roll over problem ever, try to use the calculator and you will understand.

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

Many microcontrollers have hardware quadrature encoder support:

|improve this answer|||||
\$\endgroup\$

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