22. lpc17xx_qei Module

Quadrature encoder interface client library functions. Find implementation details in LPC17xx CMSIS-Compliant Standard Peripheral Firmware Driver Library documentation.

class robovero.lpc17xx_qei.QEI_CFG_Type(**kwargs)

Bases: robovero.internals.cstruct

QEI Configuration structure type definition.

  • DirectionInvert: 1-bit Direction invert option:
    • QEI_DIRINV_NONE: QEI Direction is normal
    • QEI_DIRINV_CMPL: QEI Direction is complemented
  • SignalMode: 1-bit Signal mode Option:
    • QEI_SIGNALMODE_QUAD: Signal is in Quadrature phase mode
    • QEI_SIGNALMODE_CLKDIR: Signal is in Clock/Direction mode
  • CaptureMode: 1-bit Capture Mode Option:
    • QEI_CAPMODE_2X: Only Phase-A edges are counted (2X)
    • QEI_CAPMODE_4X: BOTH Phase-A and Phase-B edges are counted (4X)
  • InvertIndex: 1-bit Invert Index Option:
    • QEI_INVINX_NONE: the sense of the index input is normal
    • QEI_INVINX_EN: inverts the sense of the index input
  • ptr: LPC1769 memory address where structure is stored. Use this in place of the C reference operator (&).
robovero.lpc17xx_qei.QEI_CalculateRPM(QEIx, ulVelCapValue, ulPPR)

Calculates the actual velocity in RPM passed via velocity capture value and Pulse Per Round (of the encoder) value parameter input.

Args:

  • QEIx: QEI peripheral, should be LPC_QEI

  • ulVelCapValue: Velocity capture input value from QEI_GetVelocityCap()

    function

  • ulPPR: Pulse per round of encoder

Return: The actual value of velocity in RPM (revolutions per minute)

robovero.lpc17xx_qei.QEI_ConfigStructInit(QIE_InitStruct)

Fills each QIE_InitStruct member with its default value.

  • DirectionInvert = QEI_DIRINV_NONE
  • SignalMode = QEI_SIGNALMODE_QUAD
  • CaptureMode = QEI_CAPMODE_4X
  • InvertIndex = QEI_INVINX_NONE.

Args:

  • QIE_InitStruct: Pointer to a QEI_CFG_Type structure which will be initialized.
robovero.lpc17xx_qei.QEI_DeInit(QEIx)

De-initializes the QEI peripheral registers to their default reset values.

Args:

  • QEIx: QEI peripheral, should be LPC_QEI
robovero.lpc17xx_qei.QEI_GetIndex(QEIx)

Get current index counter of QEI peripheral.

Args:

  • QEIx: QEI peripheral, should be LPC_QEI

Return: Current value of QEI index counter

robovero.lpc17xx_qei.QEI_GetIntStatus(QEIx, ulIntType)

Check whether if specified interrupt flag status in QEI peripheral is set or not.

Args:

  • QEIx: QEI peripheral, should be LPC_QEI
  • ulIntType: Interrupt Flag Status type, should be:
    • QEI_INTFLAG_INX_Int: index pulse was detected interrupt
    • QEI_INTFLAG_TIM_Int: Velocity timer over flow interrupt
    • QEI_INTFLAG_VELC_Int: Capture velocity is less than compare interrupt
    • QEI_INTFLAG_DIR_Int: Change of direction interrupt
    • QEI_INTFLAG_ERR_Int: An encoder phase error interrupt
    • QEI_INTFLAG_ENCLK_Int: An encoder clock pulse was detected interrupt
    • QEI_INTFLAG_POS0_Int: position 0 compare value is equal to the current position interrupt
    • QEI_INTFLAG_POS1_Int: position 1 compare value is equal to the current position interrupt
    • QEI_INTFLAG_POS2_Int: position 2 compare value is equal to the current position interrupt
    • QEI_INTFLAG_REV_Int: Index compare value is equal to the current index count interrupt
    • QEI_INTFLAG_POS0REV_Int: Combined position 0 and revolution count interrupt
    • QEI_INTFLAG_POS1REV_Int: Combined position 1 and revolution count interrupt
    • QEI_INTFLAG_POS2REV_Int: Combined position 2 and revolution count interrupt

Return: New State of specified interrupt flag status (SET or RESET)

robovero.lpc17xx_qei.QEI_GetPosition(QEIx)

Get current position value in QEI peripheral.

Args:

  • QEIx: QEI peripheral, should be LPC_QEI

Return: Current position value of QEI peripheral

robovero.lpc17xx_qei.QEI_GetStatus(QEIx, ulFlagType)

Check whether if specified flag status is set or not.

Args:

  • QEIx: QEI peripheral, should be LPC_QEI
  • ulFlagType: Status Flag Type, should be one of the following:
    • QEI_STATUS_DIR: Direction Status

Return: New Status of this status flag (SET or RESET)

robovero.lpc17xx_qei.QEI_GetTimer(QEIx)

Get current timer counter in QEI peripheral.

Args:

  • QEIx: QEI peripheral, should be LPC_QEI

Return: Current timer counter in QEI peripheral

robovero.lpc17xx_qei.QEI_GetVelocity(QEIx)

Get current velocity pulse counter in current time period.

Args:

  • QEIx: QEI peripheral, should be LPC_QEI

Return: Current velocity pulse counter value

robovero.lpc17xx_qei.QEI_GetVelocityCap(QEIx)

Get the most recently measured velocity of the QEI. When the Velocity timer in QEI is over-flow, the current velocity value will be loaded into Velocity Capture register..

Args:

  • QEIx: QEI peripheral, should be LPC_QEI

Return: The most recently measured velocity value

robovero.lpc17xx_qei.QEI_Init(QEIx, QEI_ConfigStruct)

Initializes the QEI peripheral according to the specified parameters in the QEI_ConfigStruct.

Args:

  • QEIx: QEI peripheral, should be LPC_QEI

  • QEI_ConfigStruct: Pointer to a QEI_CFG_Type structure that contains the

    configuration information for the specified QEI peripheral

robovero.lpc17xx_qei.QEI_IntClear(QEIx, ulIntType)

Clear (force) specified interrupt (pending) in QEI peripheral.

Args:

  • QEIx: QEI peripheral, should be LPC_QEI
  • ulIntType: Interrupt Flag Status type, should be:
    • QEI_INTFLAG_INX_Int: index pulse was detected interrupt
    • QEI_INTFLAG_TIM_Int: Velocity timer over flow interrupt
    • QEI_INTFLAG_VELC_Int: Capture velocity is less than compare interrupt
    • QEI_INTFLAG_DIR_Int: Change of direction interrupt
    • QEI_INTFLAG_ERR_Int: An encoder phase error interrupt
    • QEI_INTFLAG_ENCLK_Int: An encoder clock pulse was detected interrupt
    • QEI_INTFLAG_POS0_Int: position 0 compare value is equal to the current position interrupt
    • QEI_INTFLAG_POS1_Int: position 1 compare value is equal to the current position interrupt
    • QEI_INTFLAG_POS2_Int: position 2 compare value is equal to the current position interrupt
    • QEI_INTFLAG_REV_Int: Index compare value is equal to the current index count interrupt
    • QEI_INTFLAG_POS0REV_Int: Combined position 0 and revolution count interrupt
    • QEI_INTFLAG_POS1REV_Int: Combined position 1 and revolution count interrupt
    • QEI_INTFLAG_POS2REV_Int: Combined position 2 and revolution count interrupt
robovero.lpc17xx_qei.QEI_IntCmd(QEIx, ulIntType, NewState)

Enable/Disable specified interrupt in QEI peripheral.

Args:

  • QEIx: QEI peripheral, should be LPC_QEI
  • ulIntType: Interrupt Flag Status type, should be:
    • QEI_INTFLAG_INX_Int: index pulse was detected interrupt
    • QEI_INTFLAG_TIM_Int: Velocity timer over flow interrupt
    • QEI_INTFLAG_VELC_Int: Capture velocity is less than compare interrupt
    • QEI_INTFLAG_DIR_Int: Change of direction interrupt
    • QEI_INTFLAG_ERR_Int: An encoder phase error interrupt
    • QEI_INTFLAG_ENCLK_Int: An encoder clock pulse was detected interrupt
    • QEI_INTFLAG_POS0_Int: position 0 compare value is equal to the current position interrupt
    • QEI_INTFLAG_POS1_Int: position 1 compare value is equal to the current position interrupt
    • QEI_INTFLAG_POS2_Int: position 2 compare value is equal to the current position interrupt
    • QEI_INTFLAG_REV_Int: Index compare value is equal to the current index count interrupt
    • QEI_INTFLAG_POS0REV_Int: Combined position 0 and revolution count interrupt
    • QEI_INTFLAG_POS1REV_Int: Combined position 1 and revolution count interrupt
    • QEI_INTFLAG_POS2REV_Int: Combined position 2 and revolution count interrupt
  • NewState: New function state, should be:
    • DISABLE
    • ENABLE
robovero.lpc17xx_qei.QEI_IntSet(QEIx, ulIntType)

Sets (forces) specified interrupt in QEI peripheral.

Args:

  • QEIx: QEI peripheral, should be LPC_QEI
  • ulIntType: Interrupt Flag Status type, should be:
    • QEI_INTFLAG_INX_Int: index pulse was detected interrupt
    • QEI_INTFLAG_TIM_Int: Velocity timer over flow interrupt
    • QEI_INTFLAG_VELC_Int: Capture velocity is less than compare interrupt
    • QEI_INTFLAG_DIR_Int: Change of direction interrupt
    • QEI_INTFLAG_ERR_Int: An encoder phase error interrupt
    • QEI_INTFLAG_ENCLK_Int: An encoder clock pulse was detected interrupt
    • QEI_INTFLAG_POS0_Int: position 0 compare value is equal to the current position interrupt
    • QEI_INTFLAG_POS1_Int: position 1 compare value is equal to the current position interrupt
    • QEI_INTFLAG_POS2_Int: position 2 compare value is equal to the current position interrupt
    • QEI_INTFLAG_REV_Int: Index compare value is equal to the current index count interrupt
    • QEI_INTFLAG_POS0REV_Int: Combined position 0 and revolution count interrupt
    • QEI_INTFLAG_POS1REV_Int: Combined position 1 and revolution count interrupt
    • QEI_INTFLAG_POS2REV_Int: Combined position 2 and revolution count interrupt
class robovero.lpc17xx_qei.QEI_RELOADCFG_Type(**kwargs)

Bases: robovero.internals.cstruct

Timer Reload Configuration structure type definition.

  • ReloadOption: Velocity Timer Reload Option, should be:

    • QEI_TIMERRELOAD_TICKVAL: Reload value in absolute value
    • QEI_TIMERRELOAD_USVAL: Reload value in microsecond value
  • ReloadValue: Velocity Timer Reload Value, 32-bit long, should be matched

    with Velocity Timer Reload Option

  • ptr: LPC1769 memory address where structure is stored. Use this in place of

    the C reference operator (&).

robovero.lpc17xx_qei.QEI_Reset(QEIx, ulResetType)

Resets value for each type of QEI value, such as velocity, counter, position, etc.

Args:

  • QEIx: QEI peripheral, should be LPC_QEI
  • ulResetType: QEI Reset Type, should be one of the following:
    • QEI_RESET_POS: Reset Position Counter
    • QEI_RESET_POSOnIDX: Reset Position Counter on Index signal
    • QEI_RESET_VEL: Reset Velocity
    • QEI_RESET_IDX: Reset Index Counter
robovero.lpc17xx_qei.QEI_SetDigiFilter(QEIx, ulSamplingPulse)

Set value of sampling count for the digital filter in QEI peripheral.

Args:

  • QEIx: QEI peripheral, should be LPC_QEI
  • ulSamplingPulse: Value of sampling count to set
robovero.lpc17xx_qei.QEI_SetIndexComp(QEIx, ulIndexComp)

Set value for index compare in QEI peripheral.

Args:

  • QEIx: QEI peripheral, should be LPC_QEI
  • ulIndexComp: Compare Index Value to set
robovero.lpc17xx_qei.QEI_SetMaxPosition(QEIx, ulMaxPos)

Set max position value for QEI peripheral.

Args:

  • QEIx: QEI peripheral, should be LPC_QEI
  • ulMaxPos: Max position value to set
robovero.lpc17xx_qei.QEI_SetPositionComp(QEIx, bPosCompCh, ulPosComp)

Set position compare value for QEI peripheral.

Args:

  • QEIx: QEI peripheral, should be LPC_QEI
  • bPosCompCh: Compare Position channel, should be:
    • QEI_COMPPOS_CH_0: QEI compare position channel 0
    • QEI_COMPPOS_CH_1: QEI compare position channel 1
    • QEI_COMPPOS_CH_2: QEI compare position channel 2
  • ulPosComp: Compare Position value to set
robovero.lpc17xx_qei.QEI_SetTimerReload(QEIx, QEIReloadStruct)

Set timer reload value for QEI peripheral. When the velocity timer is over-flow, the value that set for Timer Reload register will be loaded into the velocity timer for next period. The calculated velocity in RPM therefore will be affect by this value..

Args:

  • QEIx: QEI peripheral, should be LPC_QEI
  • QEIReloadStruct: QEI reload structure
robovero.lpc17xx_qei.QEI_SetVelocityComp(QEIx, ulVelComp)

Set Velocity Compare value for QEI peripheral.

Args:

  • QEIx: QEI peripheral, should be LPC_QEI
  • ulVelComp: Compare Velocity value to set