SLAU893B October 2023 – July 2024 MSPM0C1103 , MSPM0C1103-Q1 , MSPM0C1104 , MSPM0C1104-Q1
QEI is used to decode signals from optical position encoders. Optical position encoders typically output 2 signals (PHA/PHB) which are often used to measure rotary or linear movement of physical items with rotating shafts, such as 3-phase motors. The measurement provided by the interface is incremental, which means as movement occurs, the interface provides the ability to capture the relative change from the previous position.
When operating in QEI mode, a counter accumulates the incremental updates, deriving current position from initial position and the accumulated change. The initial position can be determined by the signal of the IDX input (3-signal QEI mode) or by other software means (software directly setting the initial position). The capture and compare register can be used to store the position value by defining a capture condition.
When a direction change (DC) occurs, a DC interrupt is generated in the RIS register.
Figure 15-18 shows the state machine in the QEI interface to detect the directional rotation from the two CCP input signals, PHA and PHB.
QEI 2-Signal Mode Configuration
Configure input capture settings as described in Section 15.2.3.1.1, if desired.
Example using QEI mode with 2 input signals
The behavior of PHA/PHB follows Table 15-12 and Figure 15-19.
Current State (PHA, PHB) | Next State (PHA, PHB) | Direction (DIR) | Counter Action |
---|---|---|---|
00 | 10 | 1 (Up) | +1 (If TIMx.CTR = LOAD, then CTR = 0) |
10 | 11 | ||
11 | 01 | ||
01 | 00 | ||
00 | 01 | 0 (Down) | -1 (If TIMx.CTR = 0, then CTR = TIMx.LOAD) |
01 | 11 | ||
11 | 10 | ||
10 | 00 |