Mouser Electronics White Papers
Issue link: https://resources.mouser.com/i/1534198
Mouser Electronics White Paper Quadrature encoders are often used in applications that need bidirectional rotation tracking. They are commonly integrated into user interface elements—like dials and knobs to track user input—and into motion control systems to provide the position feedback necessary for precise movement control. These encoders serve several key industries: • Industrial automation and robotics use quadrature encoders for precise positioning of motor-driven systems. • Manufacturers of e-bikes and other mobility products rely on them for motor control and user input. • Consumer electronics implement them in dials, scroll wheels, and other controls. While they are popular, challenges arise when implementing quadrature encoders. Decoding the signals from the encoder requires either dedicated hardware or significant processing resources from the microcontroller. Both design paths involve difficult trade-offs in cost, design complexity, and power consumption. This paper explains how the configurable logic block (CLB) in the Microchip Technology PIC16F13145 family of microcontrollers provides a solution for effectively implementing a quadrature encoder. In doing so, this paper shows how to decode quadrature signals efficiently, reducing power usage, component count, and design effort. How Quadrature Encoded Signals Work Quadrature encoders generate two digital signals that provide information about the position and direction of rotation. The physical construction of quadrature encoders can take several forms, each suited to different applications and environmental conditions: • Mechanical encoders employ contact pairs that open and close as a shaft rotates, making them robust but subject to contact bounce. • Optical encoders use LED and photosensor pairs, with a slotted disk interrupting the light path to generate pulses. These encoders offer high precision and reliability in clean environments. • Magnetic encoders use Hall effect sensors to detect the position of a magnetized wheel, providing good reliability in harsh conditions without mechanical wear. Regardless of the physical implementation, all quadrature encoders produce two output channels, commonly labeled A and B. These channels are intentionally offset by 90 degrees (one-quarter of a cycle, hence "quadrature"). This phase relationship is key to determining the direction of rotation. Direction is determined by examining the phase relationship between channels A and B. When rotation is clockwise (CW), signal A will lead signal B; that is, there will be either a rising or falling edge on channel A followed by the same transition on channel B. Conversely, when rotation is counterclockwise (CCW), signal B will lead signal A (Figure 1). In other words, the quadrature signals form a repeating four- state sequence (Table 1). During clockwise rotation, the states progress in order, 0→1→2→3→0. During counterclockwise rotation, they progress in reverse order, 0→3→2→1→0. State Channel A Channel B 0 0 0 1 1 0 2 1 1 3 0 1 Position can be tracked by maintaining a counter that increments or decrements based on the detected direction. These counters can also be used to determine velocity by recording the time between position changes or by counting the number of changes within a fixed time window. This capability is particularly valuable in motor control applications that require speed regulation. Figure 1: The direction of rotation in a quadrature encoder is determined by the relationship between the A and B channel signals. (Source: Microchip Technology) Table 1 : Quadrature encoders progress through four states