24.4 Initialization and Configuration
Perform these steps to configure the QEI module to read back an absolute position:
- Enable the QEI clock using the RCGCQEI register in the System Control module (see Section 4.2.100).
- Enable the clock to the appropriate GPIO module via the RCGCGPIO register in the System Control module (see Section 4.2.87).
- In the GPIO module, enable the appropriate pins for their alternate function using the GPIOAFSEL register. To determine which GPIOs to configure, see the device-specific data sheet.
- Configure the PMCn fields in the GPIOPCTL register to assign the QEI signals to the appropriate pins (see Section 17.5.22 and the device-specific data sheet).
- Configure the quadrature encoder to capture edges on both signals and maintain an absolute position by resetting on index pulses. A 1000-line encoder with four edges per line, results in 4000 pulses per revolution; therefore, set the maximum position to 3999 (0xF9F) as the count is zero-based.
- Write the QEICTL register with the value of 0x0000.0018.
- Write the QEIMAXPOS register with the value of 0x0000.0F9F.
- Enable the quadrature encoder by setting bit 0 of the QEICTL register.
NOTE
After the QEI module has been enabled by setting the ENABLE bit in the QEICTL register, it cannot be disabled. The only way to clear the ENABLE bit is to reset the module using the Quadrature Encoder Interface Software Reset (SRQEI) register.
- Delay until the encoder position is required.
- Read the encoder position by reading the QEI Position (QEIPOS) register value.
NOTE
If the application requires the quadrature encoder to have a specific initial position, this value must be programmed in the QEIPOS register after the quadrature encoder has been enabled by setting the ENABLE bit in the QEICTL register.