Port to LPC1549. Partially tested, not all features ported

Fork of QEI_hw by Hexley Ball

Embed: (wiki syntax)

« Back to documentation index

QEIHW Class Reference

QEIHW Class Reference

QEI hardware interface class Requires mbed hardware modification: connect encoder PhA to p1.20, and PhB to p1.23. More...

#include <qeihw.h>

Public Member Functions

 QEIHW (uint32_t _dirinv, uint32_t _sigmode, uint32_t _capmode, uint32_t _invinx)
 Create a QEI object and configure it.
void Reset (uint32_t ulResetType)
 Resets value for each type of QEI value, such as velocity, position, etc.
void DeInit ()
 Powers down the QEI block, returns pins to GPIO mode.
FlagStatus Direction ()
 Report direction (QEISTAT bit DIR)
uint32_t GetPosition ()
 Get current position value in QEI peripheral.
void SetMaxPosition (uint32_t ulMaxPos)
 Set max position value for QEI peripheral.
void SetPositionComp (uint8_t bPosCompCh, uint32_t ulPosComp)
 Set position compare value for QEI peripheral.
uint32_t GetIndex ()
 Get current index counter of QEI peripheral.
void SetIndexComp (uint32_t ulIndexComp)
 Set value for index compare in QEI peripheral.
void SetVelocityTimerReload (uint32_t ulReloadValue)
 Set Velocity timer reload value.
void SetVelocityTimerReload_us (uint32_t ulReloadValue)
 Set Velocity timer reload value in microseconds.
uint32_t GetTimer ()
 Get current timer counter in QEI peripheral.
uint32_t GetVelocity ()
 Get current velocity pulse counter in current time period.
uint32_t GetVelocityCap ()
 Get the most recently measured velocity of the QEI.
void SetVelocityComp (uint32_t ulVelComp)
 Set Velocity Compare value for QEI peripheral.
void SetDigiFilter (uint32_t ulSamplingPulse)
 Set value of sampling count for the digital filter in QEI peripheral.
FlagStatus GetIntStatus (uint32_t ulIntType)
 Check whether if specified interrupt flag status in QEI peripheral is set or not.
void IntCmd (uint32_t ulIntType, FunctionalState NewState)
 Enable/Disable specified interrupt in QEI peripheral.
void IntSet (uint32_t ulIntType)
 Asserts specified interrupt in QEI peripheral.
void IntClear (uint32_t ulIntType)
 De-asserts specified interrupt (pending) in QEI peripheral.
void AppendISR (uint32_t ulISRType, void(*fptr)(void))
 Append interrupt handler for specific QEI interrupt source.
void UnAppendISR (uint32_t ulISRType)
 Unappend interrupt handler for specific QEI interrupt source.
uint32_t CalculateRPM (uint32_t ulVelCapValue, uint32_t ulPPR)
 Calculates the actual velocity in RPM passed via velocity capture value and Pulse Per Revolution (of the encoder) value parameter input.

Detailed Description

QEI hardware interface class Requires mbed hardware modification: connect encoder PhA to p1.20, and PhB to p1.23.

Example:

 // Display changes in encoder position and direction 
#include "mbed.h"
 #include "qeihw.h"

 DigitalOut led1(LED1);
 DigitalOut led3(LED3);
 QEIHW qei(QEI_DIRINV_NONE, QEI_SIGNALMODE_QUAD, QEI_CAPMODE_2X, QEI_INVINX_NONE );

 int main() {
     int32_t temp, position = 0;                      
     qei.SetDigiFilter(480UL);
     qei.SetMaxPosition(0xFFFFFFFF);
    
     while(1) {
         while(position == (temp = qei.GetPosition()) );
         position = temp;  
         printf("New position = %d.\r\n", temp);
         led1 = qei.Direction() == SET ? 1 : 0;
         led3 = !led1;
         wait(0.1);
     }
 }

Definition at line 70 of file qeihw.h.


Constructor & Destructor Documentation

QEIHW ( uint32_t  _dirinv,
uint32_t  _sigmode,
uint32_t  _capmode,
uint32_t  _invinx 
)

Create a QEI object and configure it.

Parameters:
_dirinvDirection invert. When = 1, complements the QEICONF register DIR bit
_sigmodeSignal mode. When = 0, PhA and PhB are quadrature inputs. When = 1, PhA is direction and PhB is clock
_capmodeCapture mode. When = 0, count PhA edges only (2X mode). Whe = 1, count PhB edges also (4X mode).
_invinxInvert index. When = 1, inverts the sense of the index signal
_dirinvDirection invert. When = 1, complements the QEICONF register DIR bit
_sigmodeSignal mode. When = 0, PhA and PhB are quadrature inputs. When = 1, PhA is direction and PhB is clock
_capmodeCapture mode. When = 0, count PhA edges only (2X mode). Whe = 1, count PhB edges also (4X mode).
_invinxInvert index. When = 1, inverts the sense of the index signal
Returns:
None

Definition at line 28 of file qeihw.cpp.


Member Function Documentation

void AppendISR ( uint32_t  ulISRType,
void(*)(void)  fptr 
)

Append interrupt handler for specific QEI interrupt source.

Parameters:
[in]ulISRTypeInterrupt 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
Returns:
none

Definition at line 601 of file qeihw.cpp.

uint32_t CalculateRPM ( uint32_t  ulVelCapValue,
uint32_t  ulPPR 
)

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

Parameters:
[in]ulVelCapValueVelocity capture input value that can be got from QEI_GetVelocityCap() function
[in]ulPPRPulse per round of encoder
Returns:
The actual value of velocity in RPM (Revolutions per minute)

Definition at line 498 of file qeihw.cpp.

void DeInit (  )

Powers down the QEI block, returns pins to GPIO mode.

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

Returns:
None

Definition at line 129 of file qeihw.cpp.

FlagStatus Direction (  )

Report direction (QEISTAT bit DIR)

Returns:
State of the DIR bit (SET or RESET)

Definition at line 158 of file qeihw.cpp.

uint32_t GetIndex (  )

Get current index counter of QEI peripheral.

Returns:
Current value of QEI index counter

Definition at line 207 of file qeihw.cpp.

FlagStatus GetIntStatus ( uint32_t  ulIntType )

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

Parameters:
[in]ulIntTypeInterrupt 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
Returns:
New State of specified interrupt flag status (SET or RESET)

Definition at line 392 of file qeihw.cpp.

uint32_t GetPosition (  )

Get current position value in QEI peripheral.

Returns:
Current position value of QEI peripheral

Definition at line 168 of file qeihw.cpp.

uint32_t GetTimer (  )

Get current timer counter in QEI peripheral.

Returns:
Current timer counter in QEI peripheral

Definition at line 310 of file qeihw.cpp.

uint32_t GetVelocity (  )

Get current velocity pulse counter in current time period.

Returns:
Current velocity pulse counter value

Definition at line 320 of file qeihw.cpp.

uint32_t GetVelocityCap (  )

Get the most recently measured velocity of the QEI.

Get the most recently captured velocity of the QEI.

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

Returns:
The most recently measured velocity value

Definition at line 332 of file qeihw.cpp.

void IntClear ( uint32_t  ulIntType )

De-asserts specified interrupt (pending) in QEI peripheral.

De-assert specified interrupt (pending) in QEI peripheral.

Parameters:
[in]ulIntTypeInterrupt 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
Returns:
None

Definition at line 483 of file qeihw.cpp.

void IntCmd ( uint32_t  ulIntType,
FunctionalState  NewState 
)

Enable/Disable specified interrupt in QEI peripheral.

Parameters:
[in]ulIntTypeInterrupt 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
[in]NewStateNew function state, should be:

  • DISABLE
  • ENABLE
Returns:
None

Definition at line 423 of file qeihw.cpp.

void IntSet ( uint32_t  ulIntType )

Asserts specified interrupt in QEI peripheral.

Assert specified interrupt in QEI peripheral.

Parameters:
[in]ulIntTypeInterrupt 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
Returns:
None

Definition at line 455 of file qeihw.cpp.

void Reset ( uint32_t  ulResetType )

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

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

Parameters:
[in]ulResetTypeQEI 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
[in]ulResetTypeQEI 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
Returns:
None

Definition at line 118 of file qeihw.cpp.

void SetDigiFilter ( uint32_t  ulSamplingPulse )

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

Parameters:
[in]ulSamplingPulseValue of sampling count to set
Returns:
None

Definition at line 356 of file qeihw.cpp.

void SetIndexComp ( uint32_t  ulIndexComp )

Set value for index compare in QEI peripheral.

Parameters:
[in]ulIndexCompCompare Index Value to set
Returns:
None

Definition at line 217 of file qeihw.cpp.

void SetMaxPosition ( uint32_t  ulMaxPos )

Set max position value for QEI peripheral.

Parameters:
[in]ulMaxPosMax position value to set
Returns:
None

Definition at line 179 of file qeihw.cpp.

void SetPositionComp ( uint8_t  bPosCompCh,
uint32_t  ulPosComp 
)

Set position compare value for QEI peripheral.

Parameters:
[in]bPosCompChCompare 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
[in]ulPosCompCompare Position value to set
Returns:
None
Parameters:
[in]QEIxQEI peripheral, should be LPC_QEI
[in]bPosCompChCompare 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
[in]ulPosCompCompare Position value to set
Returns:
None

Definition at line 194 of file qeihw.cpp.

void SetVelocityComp ( uint32_t  ulVelComp )

Set Velocity Compare value for QEI peripheral.

Parameters:
[in]ulVelCompCompare Velocity value to set
Returns:
None

Definition at line 344 of file qeihw.cpp.

void SetVelocityTimerReload ( uint32_t  ulReloadValue )

Set Velocity timer reload value.

Parameters:
[in]ulReloadValueVelocity timer reload count
Returns:
None

Definition at line 228 of file qeihw.cpp.

void SetVelocityTimerReload_us ( uint32_t  ulReloadValue )

Set Velocity timer reload value in microseconds.

Parameters:
[in]ulReloadValueVelocity timer reload count
Returns:
None

Definition at line 239 of file qeihw.cpp.

void UnAppendISR ( uint32_t  ulISRType )

Unappend interrupt handler for specific QEI interrupt source.

Parameters:
[in]ulISRTypeInterrupt 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
Returns:
none

Definition at line 637 of file qeihw.cpp.