2.22 QEI Driver
2.22.1 Introduction
Overview
The Quadrature Encoder Interface (QEI) provides the interface to incremental encoders for obtaining mechanical position data. Detects position and speed of rotating motion systems.
Features
- Configurable QEI operation mode.
- Configurable Digital noise filter clock frequency.
- Configurable Index and Home pulse polarity.
- QEI input clock prescalar value is user configurable in the Hardware Dependency module (PLIB).
2.22.2 Module Documentation
2.22.2.1 QEI Driver
The Quadrature Encoder Interface (QEI) driver provides the interface to incremental encoders for obtaining mechanical position data and Also Detects position and speed of rotating motion systems using dsPIC MCUs.
2.22.2.1.1 Module description
The Quadrature Encoder Interface (QEI) driver provides the interface to incremental encoders for obtaining mechanical position data and Also Detects position and speed of rotating motion systems using dsPIC MCUs.
2.22.2.1.1.1 Data structures
struct QEI_INTERFACE
Structure containing the function pointers of QEI driver.
2.22.2.1.1.2 Enumerations
enum QEI_MODE { QEI_MODE_FREE_RUNNING = 0, QEI_MODE_RESET_ON_INDEX = 1, QEI_MODE_2 = 2, QEI_MODE_3 = 3, QEI_MODE_4 = 4, QEI_MODE_5 = 5, QEI_MODE_MODULO_COUNT = 6 }
Defines the QEI operating mode.
enum QEI_IMV_STATE { QEI_IMV_STATE_A0B0 = 0, QEI_IMV_STATE_A1B0 = 1, QEI_IMV_STATE_A0B1 = 2, QEI_IMV_STATE_A1B1 = 3, QEI_MAX_IMV_STATE }
Defines the QEI Index Match Value states.
2.22.2.1.1.3 Functions
static void QEI1_Disable (void)
This inline function disables the QEI1 module.
static void QEI1_Enable (void)
This inline function enables the QEI1 module.
static uint32_t QEI1_PositionCountRead (void)
This inline function returns the 32-bit position count value.
static uint16_t QEI1_PositionCount16bitRead (void)
This inline function returns the 16-bit position count value from the QEI1 position count register.
static void QEI1_PositionCountWrite (uint32_t positionCount)
This inline function sets the QEI1 position count value.
static void QEI1_ModuloRangeSet (uint32_t countsPerRevolution)
This inline function sets the 32bit modulo count value when QEI is configured to operate in 'Modulo Count' mode. The lower bound controlled by the QEILEC register is set to 0.
static bool QEI1_PhaseInputSwappedGet (void)
This inline function gets the status of QEI input phase swap configuration.
static void QEI1_PhaseInputSwappedSet (bool swapEnabled)
This inline function sets whether the QEA and QEB pins are swapped prior to quadrature decoder logic.
static void QEI1_PositionCaptureEnable (void)
This inline function enables the QEI position count capture on an index event.
static void QEI1_PositionCaptureDisable (void)
This inline function disables the QEI position count capture on an index event.
static uint32_t QEI1_PositionCaptureGet (void)
This inline function reads the 32-bit position capture value from the QEIICx 32 bit register.
static uint16_t QEI1_PositionCapture16bitGet (void)
This inline function returns the 16-bit position capture value from QEIICL position count capture register.
static void QEI1_PositionCaptureSet (uint32_t initValue)
This inline function initializes the 32 bit position capture register value.
static void QEI1_CounterModeSet (enum QEI_MODE mode)
This inline function sets the QEI Counter mode.
static void QEI1_IMVGatedValueSet (enum QEI_IMV_STATE state)
This inline function sets the QEI Index Match Value.
void QEI1_Initialize (void)
Initializes the QEI module.
void QEI1_Deinitialize (void)
Deinitializes the QEI1 to POR values.
2.22.2.1.1.4 Variables
const struct QEI_INTERFACE QEI1
Structure object of type QEI_INTERFACE with the custom name given by the user in the Melody Driver User interface.
2.22.2.1.2 Function Documentation
2.22.2.1.2.1 QEI1_CounterModeSet()
static void QEI1_CounterModeSet (enum QEI_MODE mode)[inline], [static]
This inline function sets the QEI Counter mode.
in | mode |
- Sets the QEI counter mode |
none |
2.22.2.1.2.2 QEI1_Deinitialize()
void QEI1_Deinitialize (void )
Deinitializes the QEI1 to POR values.
none |
none |
2.22.2.1.2.3 QEI1_Disable()
static void QEI1_Disable (void )[inline], [static]
This inline function disables the QEI1 module.
none |
none |
2.22.2.1.2.4 QEI1_Enable()
static void QEI1_Enable (void )[inline], [static]
This inline function enables the QEI1 module.
none |
none |
2.22.2.1.2.5 QEI1_IMVGatedValueSet()
static void QEI1_IMVGatedValueSet (enum QEI_IMV_STATE state)[inline], [static]
This inline function sets the QEI Index Match Value.
in | mode |
- Sets the QEI Index Match Value |
none |
2.22.2.1.2.6 QEI1_Initialize()
void QEI1_Initialize (void )
Initializes the QEI module.
none |
none |
2.22.2.1.2.7 QEI1_ModuloRangeSet()
static void QEI1_ModuloRangeSet (uint32_t countsPerRevolution)[inline], [static]
This inline function sets the 32bit modulo count value when QEI is configured to operate in 'Modulo Count' mode. The lower bound controlled by the QEILEC register is set to 0.
in | countsPerRevolution |
- Modulus number of counts per wraparound |
none |
2.22.2.1.2.8 QEI1_PhaseInputSwappedGet()
static bool QEI1_PhaseInputSwappedGet (void )[inline], [static]
This inline function gets the status of QEI input phase swap configuration.
none |
true - Phase inputs are swapped false - Phase inputs are not swapped |
2.22.2.1.2.9 QEI1_PhaseInputSwappedSet()
static void QEI1_PhaseInputSwappedSet (bool swapEnabled)[inline], [static]
This inline function sets whether the QEA and QEB pins are swapped prior to quadrature decoder logic.
in | swapEnabled |
- specifies whether QEA and QEB pins need to be swapped prior to quadrature decoder logic |
none |
2.22.2.1.2.10 QEI1_PositionCapture16bitGet()
static uint16_t QEI1_PositionCapture16bitGet (void )[inline], [static]
This inline function returns the 16-bit position capture value from QEIICL position count capture register.
none |
Returns the LSB 16 bits of position capture value |
2.22.2.1.2.11 QEI1_PositionCaptureDisable()
static void QEI1_PositionCaptureDisable (void )[inline], [static]
This inline function disables the QEI position count capture on an index event.
none |
none |
2.22.2.1.2.12 QEI1_PositionCaptureEnable()
static void QEI1_PositionCaptureEnable (void )[inline], [static]
This inline function enables the QEI position count capture on an index event.
none |
none |
2.22.2.1.2.13 QEI1_PositionCaptureGet()
static uint32_t QEI1_PositionCaptureGet (void )[inline], [static]
This inline function reads the 32-bit position capture value from the QEIICx 32 bit register.
none |
Returns position capture value |
2.22.2.1.2.14 QEI1_PositionCaptureSet()
static void QEI1_PositionCaptureSet (uint32_t initValue)[inline], [static]
This inline function initializes the 32 bit position capture register value.
in | initValue |
- 32 bit position capture register value |
none |
2.22.2.1.2.15 QEI1_PositionCount16bitRead()
static uint16_t QEI1_PositionCount16bitRead (void )[inline], [static]
This inline function returns the 16-bit position count value from the QEI1 position count register.
none |
Returns the LSB 16 bits of the QEI1 position count register. |
2.22.2.1.2.16 QEI1_PositionCountRead()
static uint32_t QEI1_PositionCountRead (void )[inline], [static]
This inline function returns the 32-bit position count value.
none |
Returns the 32-bit position count register value |
2.22.2.1.2.17 QEI1_PositionCountWrite()
static void QEI1_PositionCountWrite (uint32_t positionCount)[inline], [static]
This inline function sets the QEI1 position count value.
in | positionCount |
- 32-bit position count value |
none |
2.22.2.1.3 Enumeration Type Documentation
2.22.2.1.3.1 QEI_IMV_STATE
enum QEI_IMV_STATE
Defines the QEI Index Match Value states.
QEI_IMV_STATE_A0B0 |
Index Match Value State : QEA = 0 and QEB = 0 |
QEI_IMV_STATE_A1B0 |
Index Match Value State : QEA = 1 and QEB = 0 |
QEI_IMV_STATE_A0B1 |
Index Match Value State : QEA = 0 and QEB = 1 |
QEI_IMV_STATE_A1B1 |
Index Match Value State : QEA = 1 and QEB = 1 |
QEI_MAX_IMV_STATE |
Maximum configurable Index Match Value State |
2.22.2.1.3.2 QEI_MODE
enum QEI_MODE
Defines the QEI operating mode.
QEI_MODE_FREE_RUNNING |
Index input event does not affect position counter |
QEI_MODE_RESET_ON_INDEX |
Every index input event resets the position counter |
QEI_MODE_2 |
Next index input event initializes the position counter with contents of QEI1IC register |
QEI_MODE_3 |
First index event after home event initializes position counter with contents of QEI1IC register |
QEI_MODE_4 |
Second index event after home event initializes position counter with contents of QEI1IC register |
QEI_MODE_5 |
Resets the position counter when the position counter equals QEI1GEC register |
QEI_MODE_MODULO_COUNT |
Modulo Count mode for position counter |
2.22.2.1.4 Variable Documentation
2.22.2.1.4.1 QEI1
const struct QEI_INTERFACE QEI1
Structure object of type QEI_INTERFACE with the custom name given by the user in the Melody Driver User interface.
The default name e.g. QEI1 can be changed by the user in the QEI user interface. This allows defining a structure with application specific name using the 'Custom Name' field. Application specific name allows the API Portability.
2.22.3 Class Documentation
2.22.3.1 QEI_INTERFACE Struct Reference
Structure containing the function pointers of QEI driver.
2.22.3.1.1 Detailed Description
Structure containing the function pointers of QEI driver.
#include <qei_interface.h>
2.22.3.1.1.1 Public Attributes
void(* Initialize )(void)
Pointer to QEIx_Initialize e.g. QEI1_Initialize.
void(* Deinitialize )(void)
Pointer to QEIx_Deinitialize e.g. QEI1_Deinitialize.
void(* Enable )(void)
Pointer to QEIx_Enable e.g. QEI1_Enable.
void(* Disable )(void)
Pointer to QEIx_Disable e.g. QEI1_Disable.
uint32_t(* PositionCountRead )(void)
Pointer to QEIx_PositionCountRead e.g. QEI1_PositionCountRead.
uint16_t(* PositionCount16bitRead )(void)
Pointer to QEIx_PositionCount16bitRead e.g. QEI1_PositionCount16bitRead.
void(* PositionCountWrite )(uint32_t positionCount)
Pointer to QEIx_PositionCountWrite e.g. QEI1_PositionCountWrite.
void(* ModuloRangeSet )(uint32_t countsPerRevolution)
Pointer to QEIx_ModuloRangeSet e.g. QEI1_ModuloRangeSet.
bool(* PhaseInputSwappedGet )(void)
Pointer to QEIx_PhaseInputSwappedGet e.g. QEI1_PhaseInputSwappedGet.
void(* PhaseInputSwappedSet )(bool swapEnabled)
Pointer to QEIx_PhaseInputSwappedSet e.g. QEI1_PhaseInputSwappedSet.
void(* PositionCaptureEnable )(void)
Pointer to QEIx_PositionCaptureEnable e.g. QEI1_PositionCaptureEnable.
void(* PositionCaptureDisable )(void)
Pointer to QEIx_PositionCaptureDisable e.g. QEI1_PositionCaptureDisable.
uint32_t(* PositionCaptureGet )(void)
Pointer to QEIx_PositionCaptureGet e.g. QEI1_PositionCaptureGet.
uint16_t(* PositionCapture16bitGet )(void)
Pointer to QEIx_PositionCapture16bitGet e.g. QEI1_PositionCapture16bitGet.
void(* PositionCaptureSet )(uint32_t initValue)
Pointer to QEIx_PositionCaptureSet e.g. QEI1_PositionCaptureSet.
void(* CounterModeSet )(enum QEI_MODE mode)
Pointer to QEIx_CounterModeSet e.g. QEI1_CounterModeSet.
void(* IMVGatedValueSet )(enum QEI_IMV_STATE state)
Pointer to QEIx_IMVGatedValueSet e.g. QEI1_IMVGatedValueSet.
2.22.3.1.2 Member Data Documentation
2.22.3.1.2.1 CounterModeSet
void(* CounterModeSet) (enum QEI_MODE mode)
Pointer to QEIx_CounterModeSet e.g. QEI1_CounterModeSet.
2.22.3.1.2.2 Deinitialize
void(* Deinitialize) (void)
Pointer to QEIx_Deinitialize e.g. QEI1_Deinitialize.
2.22.3.1.2.3 Disable
void(* Disable) (void)
Pointer to QEIx_Disable e.g. QEI1_Disable.
2.22.3.1.2.4 Enable
void(* Enable) (void)
Pointer to QEIx_Enable e.g. QEI1_Enable.
2.22.3.1.2.5 IMVGatedValueSet
void(* IMVGatedValueSet) (enum QEI_IMV_STATE state)
Pointer to QEIx_IMVGatedValueSet e.g. QEI1_IMVGatedValueSet.
2.22.3.1.2.6 Initialize
void(* Initialize) (void)
Pointer to QEIx_Initialize e.g. QEI1_Initialize.
2.22.3.1.2.7 ModuloRangeSet
void(* ModuloRangeSet) (uint32_t countsPerRevolution)
Pointer to QEIx_ModuloRangeSet e.g. QEI1_ModuloRangeSet.
2.22.3.1.2.8 PhaseInputSwappedGet
bool(* PhaseInputSwappedGet) (void)
Pointer to QEIx_PhaseInputSwappedGet e.g. QEI1_PhaseInputSwappedGet.
2.22.3.1.2.9 PhaseInputSwappedSet
void(* PhaseInputSwappedSet) (bool swapEnabled)
Pointer to QEIx_PhaseInputSwappedSet e.g. QEI1_PhaseInputSwappedSet.
2.22.3.1.2.10 PositionCapture16bitGet
uint16_t(* PositionCapture16bitGet) (void)
Pointer to QEIx_PositionCapture16bitGet e.g. QEI1_PositionCapture16bitGet.
2.22.3.1.2.11 PositionCaptureDisable
void(* PositionCaptureDisable) (void)
Pointer to QEIx_PositionCaptureDisable e.g. QEI1_PositionCaptureDisable.
2.22.3.1.2.12 PositionCaptureEnable
void(* PositionCaptureEnable) (void)
Pointer to QEIx_PositionCaptureEnable e.g. QEI1_PositionCaptureEnable.
2.22.3.1.2.13 PositionCaptureGet
uint32_t(* PositionCaptureGet) (void)
Pointer to QEIx_PositionCaptureGet e.g. QEI1_PositionCaptureGet.
2.22.3.1.2.14 PositionCaptureSet
void(* PositionCaptureSet) (uint32_t initValue)
Pointer to QEIx_PositionCaptureSet e.g. QEI1_PositionCaptureSet.
2.22.3.1.2.15 PositionCount16bitRead
uint16_t(* PositionCount16bitRead) (void)
Pointer to QEIx_PositionCount16bitRead e.g. QEI1_PositionCount16bitRead.
2.22.3.1.2.16 PositionCountRead
uint32_t(* PositionCountRead) (void)
Pointer to QEIx_PositionCountRead e.g. QEI1_PositionCountRead.
2.22.3.1.2.17 PositionCountWrite
void(* PositionCountWrite) (uint32_t positionCount)
Pointer to QEIx_PositionCountWrite e.g. QEI1_PositionCountWrite.
2.22.4 File Documentation
2.22.4.1 source/qei1.h File Reference
This is the generated driver header file for the QEI1 driver.
#include <xc.h> #include <stdbool.h> #include <stdint.h> #include "qei_types.h" #include "qei_interface.h"
2.22.4.1.1 Functions
static void QEI1_Disable (void)
This inline function disables the QEI1 module.
static void QEI1_Enable (void)
This inline function enables the QEI1 module.
static uint32_t QEI1_PositionCountRead (void)
This inline function returns the 32-bit position count value.
static uint16_t QEI1_PositionCount16bitRead (void)
This inline function returns the 16-bit position count value from the QEI1 position count register.
static void QEI1_PositionCountWrite (uint32_t positionCount)
This inline function sets the QEI1 position count value.
static void QEI1_ModuloRangeSet (uint32_t countsPerRevolution)
This inline function sets the 32bit modulo count value when QEI is configured to operate in 'Modulo Count' mode. The lower bound controlled by the QEILEC register is set to 0.
static bool QEI1_PhaseInputSwappedGet (void)
This inline function gets the status of QEI input phase swap configuration.
static void QEI1_PhaseInputSwappedSet (bool swapEnabled)
This inline function sets whether the QEA and QEB pins are swapped prior to quadrature decoder logic.
static void QEI1_PositionCaptureEnable (void)
This inline function enables the QEI position count capture on an index event.
static void QEI1_PositionCaptureDisable (void)
This inline function disables the QEI position count capture on an index event.
static uint32_t QEI1_PositionCaptureGet (void)
This inline function reads the 32-bit position capture value from the QEIICx 32 bit register.
static uint16_t QEI1_PositionCapture16bitGet (void)
This inline function returns the 16-bit position capture value from QEIICL position count capture register.
static void QEI1_PositionCaptureSet (uint32_t initValue)
This inline function initializes the 32 bit position capture register value.
static void QEI1_CounterModeSet (enum QEI_MODE mode)
This inline function sets the QEI Counter mode.
static void QEI1_IMVGatedValueSet (enum QEI_IMV_STATE state)
This inline function sets the QEI Index Match Value.
void QEI1_Initialize (void)
Initializes the QEI module.
void QEI1_Deinitialize (void)
Deinitializes the QEI1 to POR values.
2.22.4.1.2 Variables
const struct QEI_INTERFACE QEI1
Structure object of type QEI_INTERFACE with the custom name given by the user in the Melody Driver User interface.
2.22.4.1.3 Detailed Description
This is the generated driver header file for the QEI1 driver.
QEI1 Generated Driver Header File
2.22.4.2 source/qei_interface.h File Reference
#include <stdbool.h> #include <stdint.h> #include "qei_types.h"
2.22.4.2.1 Data structures
struct QEI_INTERFACE
Structure containing the function pointers of QEI driver.
2.22.4.2.2 Detailed Description
QEI Generated Driver Interface Header File
2.22.4.3 source/qei_types.h File Reference
This is the generated driver types header file for the QEI driver.
2.22.4.3.1 Enumerations
enum QEI_MODE { QEI_MODE_FREE_RUNNING = 0, QEI_MODE_RESET_ON_INDEX = 1, QEI_MODE_2 = 2, QEI_MODE_3 = 3, QEI_MODE_4 = 4, QEI_MODE_5 = 5, QEI_MODE_MODULO_COUNT = 6 }
Defines the QEI operating mode.
enum QEI_IMV_STATE { QEI_IMV_STATE_A0B0 = 0, QEI_IMV_STATE_A1B0 = 1, QEI_IMV_STATE_A0B1 = 2, QEI_IMV_STATE_A1B1 = 3, QEI_MAX_IMV_STATE }
Defines the QEI Index Match Value states.
2.22.4.3.2 Detailed Description
This is the generated driver types header file for the QEI driver.
QEI Generated Driver Types Header File