![]() |
|
| Rabbit RIO User's Manual |
|
8. Quadrature Decoder
8.1 Overview
A quadrature decoder is a specialized up/down counter, where it is the phase relationship of the two inputs that determines the count direction. Quadrature decoders are widely used in applications requiring motion feedback.
The advantage of using the Rabbit RIO for this purpose is to free up resources that would otherwise be used by the processor to perform quadrature decoding. This is especially important for processors without this functionality built into the hardware.
8.1.1 Block Diagram
8.2 Dependencies
Begin/End
Pin
Interrupt
8.3 Operation
Each Rabbit RIO I/O block provides one Quadrature Decoder channel. Each channel of the Quadrature Decoder accepts an in-phase (I) and a quadrature-phase (Q) signal. A source of the quadrature signal, such as a quadrature wheel, can be tracked in its motion by the relative phase of the I and Q signals. An example of such a signal is shown below where the quadrature signals first increment the counter, then decrement it.
Choosing which pin is the in-phase signal and which pin is the quadrature-phase signal is arbitrary, but generally, these two signals should be connected such that the direction considered forward results in incrementing the counter and the backward direction should decrement the counter. In this case, incrementing and decrementing the counter depends on the transition of the I and Q inputs. For example, if the I and Q inputs were to transition from 10b to 11b to 01b and finally to 00b, the counter will increment as shown for the first two cycles of the waveform above. However, if the I and Q inputs were to transition from 01 to 11 to 10 and finally to 00, the counter will decrement as shown for the last two cycles of the waveform above.
Common quadrature wheels have either 500 or 512 steps, which would require count limits of either 0x7CF (1999) or 0x1FF (2047), as each step leads to a count of four, with each of the four counts corresponding to a rising or falling edges of the I and Q signals. One can get the quadrature count by reading the value from the 16-bit Count Value Registers. This is the typical use of the quadrature decoder.
8.3.1 Setup
The following steps explain how to set up a Quadrature Decoder channel.
- Enable the counter mode in the Mode Register
- Set the interrupts, if desired, in the Interrupt Enable Register
- Define the in-phase signal and the quadrature signal in the Increment/In-Phase/Begin Control Register and the Decrement/Quadrature/End Control Register.
8.3.2 Example
The input signals in Figure 8-1 will increment the counter by 20 counts when the following registers are written.
Similarly, the phase shift in Figure 8-2 will decrement the counter by 20. Keep in mind that each step, or complete transition cycle, leads to a count of four.
8.4 Other Comments
8.4.1 General-Purpose I/O
Any pins not in use for the quadrature decoder can be used for general-purpose I/O.
8.4.2 External Synchronization
As previously mentioned, the synch pin can be defined to reset the counter. Doing so can provide a point of reference from which to start counting so that accurate determination of position is possible when reading shaft rotation.
8.4.3 Interrupts
If desired, an interrupt can be generated from either the counter rollover, an in-phase signal, or a quadrature signal. It can be useful to service an interrupt that will get the value of CVLR and CVMR when an interrupt signal occurs. However, simple polling may be more effective since servicing interrupts every time the shaft moves may be a lot of overhead.
| Rabbit Semiconductor www.rabbit.com |