2.91 Quadrature Encoder Interface (QEI)

The Quadrature Encoder Interface (QEI) module provides the interface to incremental encoders for obtaining mechanical position data. This module provides below features:

  • Four input pins: two phase signals, an index pulse and a home pulse

  • Programmable digital noise filters on inputs

  • Count direction status

  • Index (INDX) pulse to reset the position counter

  • General purpose 32-bit Timer/Counter mode

  • Interrupts generated by QEI or counter events

  • 32-bit velocity counter

  • 32-bit position counter

  • 32-bit index pulse counter

  • 32-bit interval timer

  • 32-bit position Initialization/Capture register

  • 32-bit Compare Less Than and Greater Than registers

Using The Library

Quadrature encoder signals Phase A, Phase B and an optional index signal and an optional home signal are connected to the QEI peripheral. The quadrature decoder in the QEI peripheral processes these signals with an internal counter to get the position, velocity and revolution count. The quadrature decoder increments or decrements the 32-bit Up/Down Counter for each change of state. The counter increments when QEA leads QEB and decrements when QEB leads QEA.

Library Interface

Quadrature Encoder Interface peripheral library provides the following interfaces:

Functions

NameDescription
QEIx_InitializeInitializes given instance of QEI peripheral in quadrature mode
QEIx_StartStarts the given QEI instance counter
QEIx_StopStops the given QEI instance counter
QEIx_PositionGetReads the position from the quadrature encoder
QEIx_VelocityGetReads the velocity counter from the quadrature encoder
QEIx_RevolutionsGetReads the number of revolutions tracked by the quadrature encoder
QEIx_CallbackRegisterRegisters the function to be called from interrupt
QEIx_DeinitializeDe-initializes QEIx peripheral
QEIx_IMVGatedValueSetSets the QEIx Index Match Value Configuration
QEIx_CounterModeSetSets the QEIx Counter mode
QEIx_PositionCaptureSetInitializes the 32 bit position capture register value
QEIx_PositionCapture16bitGetReturns the 16-bit position capture value
QEIx_PositionCaptureGetReads the 32-bit position capture value
QEIx_PositionCaptureDisableDeasserts the QEIx position counter input capture
QEIx_PositionCaptureEnable

Sets the QEIx position counter input capture

QEIx_PhaseInputSwappedSetFacilitates swapping of QEA and QEB
QEIx_PhaseInputSwappedGetGets the status of QEIx input phase swap configuration
QEIx_ModuloRangeSetSets the 32bit modulo count value
QEIx_PositionCountWriteSets the QEIx position count value
QEIx_PositionCount16bitReadReturns the 16-bit position count value
QEIx_PositionCountReadReads the position count value
QEIx_EnableEnables the QEIx peripheral
QEIx_DisableDisables the QEIx peripheral

Data types and constants

NameTypeDescription
QEI_INTERRUPTEnumIdentifies Quadrature mode interrupt source
QEI_STATUSEnumIdentifies Quadrature mode interrupt source mask
QEI_CALLBACKTypedefDefines the function pointer data type and function signature for the qei peripheral callback function
QEI_MODEEnumDefines the QEI operating modes
QEI_IMV_STATEEnumDefines the QEI Index Match Value states
Note: Not all APIs maybe implemented. See the specific device family section for available APIs.