QDEC

Sample List

This chapter introduces the details of the QDEC sample code. The SDK provides the following samples for the QDEC peripheral.

Functional Overview

As shown in the following figure, QDEC is used to detect the motion state of the rotation-sensing device. When the rotating device moves, it will output two quadrature signals PHA and PHB. QDEC judges the direction of rotation by detecting the phase change of PHA and PHB.

../../../_images/Schematic_Diagram_of_Two_Quadrature_Signals_of_QDEC.png

Schematic Diagram of Two Quadrature Signals of QDEC

Feature List

  • 2 input quadrature decoder

  • Support 3 independent axes (X, Y, Z).

  • Support hardware debounce: debounce time for each axis can be set independently.

  • Support initial phase setting.

  • Support illegal phase change detection.

  • 16-bit phase change counter.

Note

RTL87x3E cannot disable the hardware debounce function. RTL87x3D can disable the hardware debounce function.

Block Diagram

Here is the overall IPs block diagram for QDEC IP¹, which including ‘PAD/PINMUX’ for IO function configuration, ‘QDEC IP’ for QDEC protocol.

../../../_images/QDEC_System_Block_Diagram.png

System Block Diagram of QDEC

Direction Judgment and Counting Method

  1. PHA and PHB are combined into a 2-bit number. PHA is the high bit, and PHB is the low bit.

  2. The phases are divided into four types: 00, 01, 11, and 10.

  3. As shown in the following figure, changes in the order of 00, 01, 11, and 10 are defined as positive. When the counter scale is set to 0, the counter will increase by one when the phase changes once. When the counter scale is set to 1, the counter will increase by one when the phase changes twice.

  4. Changes in the order of 00, 10, 11, and 01 are defined as negative. When the counter scale is set to 0, the counter will decrease by one when the phase changes once. When the counter scale is set to 1, the counter will decrease by one when the phase changes twice.

  5. PHA and PHB should only have one signal change at a time. If both signals change at the same time, the state is considered wrong. When this error state occurs, the counter does not count. Illegal interrupts can be turned on to detect this error condition.

  6. When the counter value is 0x0000, the device rotates in reverse (counter value decreases by 1), causing the counter to underflow and become 0xFFFF, while setting QDEC_FLAG_UNDERFLOW_X or QDEC_FLAG_UNDERFLOW_Y or QDEC_FLAG_UNDERFLOW_Z flag to 1.

  7. When the counter value is 0xFFFF, the device rotates forward (counter value increases by 1), causing the counter to overflow and become 0x0000, while setting QDEC_FLAG_OVERFLOW_X or QDEC_FLAG_OVERFLOW_Y or QDEC_FLAG_OVERFLOW_Z flag to 1.

../../../_images/Schematic_Diagram_of_QDEC_Direction_Judgment.png

Schematic Diagram of QDEC Direction Judgment

Power Manager

The QDEC peripheral is located in the core domain and will be powered off in low power mode. QDEC peripheral store/restore will be automatically performed based on whether the QDEC clock is active. Users can call the API io_dlps_register() to initialize QDEC peripheral store/restore and do not need to worry about QDEC peripheral requiring specific handling.