SLAU847D October 2022 – May 2024 MSPM0L1105 , MSPM0L1106 , MSPM0L1227 , MSPM0L1228 , MSPM0L1228-Q1 , MSPM0L1303 , MSPM0L1304 , MSPM0L1304-Q1 , MSPM0L1305 , MSPM0L1305-Q1 , MSPM0L1306 , MSPM0L1306-Q1 , MSPM0L1343 , MSPM0L1344 , MSPM0L1345 , MSPM0L1346 , MSPM0L2227 , MSPM0L2228 , MSPM0L2228-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 23-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 23.2.3.1.1, if desired.
Example using QEI mode with 2 input signals
The behavior of PHA/PHB follows Table 23-12 and Figure 23-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 |