Quadrature Decoders

  • tags Encoder Microcontroller
  • Resources
  • Notes
    • Linear Position Sensors: Theory and Application”, by David S. Nyce ISBN 0-471-23326-9, John Wiley & Sons, Inc. Section 10.7: Quadrature, Page 157:
      • “Modern circuits that read the A quad B signals from a position transducer do not actually wait for a transition to occur and then count that transition.  Instead, its more common to monitor the states of A and B continuously at a higher sampling rate than the transitions are expected to occur.  With this (state, rather than transition) information and, usually, a microcontroller, smoother operation can be obtained with less likelihood of error.”
    • Using the timers to look at the state of the pins and oversampling them is better than directly calling ISR. As in real world noise can get into the system and crash the hardware, but if the pins are oversampled at a rate above these transients then results in a better performance.
    • 1X Decoding
      • Take just** the rising edge of channel A as the input to a counter**. But to tell the direction you have to look at channel B.
      • If we scan form left to right, after channel A rising edge, A and B have different values. Similarly if we scan from right to left after A’s rising edge A and B have the same values. We can check for equality of A and B to tell the direction.
      • 500CPR encoder only gives 500 counts/Rev.
    • 2X Decoding
      • Short coming of the previous method is the count frequency is the same as the frequency of channel A.
      • We can detect both the rising and the falling edge, needs more board space.
      • To tell the direction, the equality test works as well in rising edge and falling edge, you can use the same routine.
      • With 2X decoding our 500 cpr encoder can generate 1000 counts per revolution.
    • 4X Decoding
      • If we examine the edges of both channel A and channel B. There are four edges for each phase of channel A and it is possible to get 2000 counts per revolution from our 500 cpr encoder.
    • If you have a controller that can do pin change interrupts then we can get the count we want.
    • The Atmel AVR ATtiny13 processors, which are 8 pin devices with an internal 9.6MHz clock.
    • Channel A is connected to the INT0 pin and channel B is connected to the INT1 pin. Only the INT0 interrupt is used here as I needed only 1X or 2X decoding.
    • The ATtiny can generate an interrupt on either a rising or a trailing edge. For 2X decoding, the sense of the interrupt is changed after each interrupt so that the routine responds alternately to rising and falling edges.
    • On each interrupt, the direction of the count is determined and a pulse generated on either the count-up or the count-down pin as appropriate. On the processor used, pulse rates as high as 150kHz should be readily detectable.
    • The interrupt routine takes less than 4.5us to execute and rates as high as 220kHz may be possible with inputs that are in perfect quadrature. That is unlikely in practice.
  • Quadrature Decoders

Notes mentioning this note


Here are all the notes in this garden, along with their links, visualized as a graph.