Hello,
I have two incremental encode and I connect them to Quadrature Encoder Interface IDX0/PhA0/PhB0 and IDX1/PhA1/PhB1
But I only get QEI1 position will I use QEIPositionGet(QEI1_BASE) function
The QEI0 are return 0 or 1 value .
In addition there is a strange thing that I see only in QEI0, whenever interrupt QEI0IntHandler() happening the ulstatus == QEI_INTDIR.
Thanks
Eran SEgal.
/*****************************************************/
/* For LM4F230H5QR */
/*****************************************************/
#define QEI_PITCH_INDEX_PORT GPIO_PORTD_BASE
#define QEI_PITCH_INDEX_PIN GPIO_PIN_3
#define QEI_PITCH_INDEX_INT INT_GPIOD
#define QEI_PITCH_PHA_PORT GPIO_PORTD_BASE
#define QEI_PITCH_PHA_PIN GPIO_PIN_6
#define QEI_PITCH_PHA_INT INT_GPIOD
#define QEI_PITCH_PHB_PORT GPIO_PORTD_BASE
#define QEI_PITCH_PHB_PIN GPIO_PIN_7
//*****************************************************
#define QEI_ROLL_INDEX_PORT GPIO_PORTC_BASE
#define QEI_ROLL_INDEX_PIN GPIO_PIN_4
#define QEI_ROLL_INDEX_INT INT_GPIOC
#define QEI_ROLL_PHA_PORT GPIO_PORTC_BASE
#define QEI_ROLL_PHA_PIN GPIO_PIN_5
#define QEI_ROLL_PHA_INT INT_GPIOC
#define QEI_ROLL_PHB_PORT GPIO_PORTC_BASE
#define QEI_ROLL_PHB_PIN GPIO_PIN_6
//*****************************************************
//*****************************************************************************
//
// This function prepares the quadrature encoder module for capturing the
// position and speed of the motor.
//
//*****************************************************************************
void
Encoder_Init(unsigned long ulBase)
{
if(ulBase == QEI0_BASE) // PITCH Encoder
{
//
// Enable the peripherals QEI example.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI0);
GPIOPinTypeQEI(QEI_PITCH_PHA_PORT,QEI_PITCH_PHA_PIN);
GPIOPinTypeQEI(QEI_PITCH_PHB_PORT,QEI_PITCH_PHB_PIN);
GPIOPinTypeQEI(QEI_PITCH_INDEX_PORT,QEI_PITCH_INDEX_PIN);
// Set D 0 and 1 to alternative use
GPIODirModeSet(GPIO_PORTD_BASE, GPIO_PIN_3, GPIO_DIR_MODE_HW);//GPIO_DIR_MODE_HW
GPIODirModeSet(GPIO_PORTD_BASE, GPIO_PIN_6, GPIO_DIR_MODE_HW);
GPIODirModeSet(GPIO_PORTD_BASE, GPIO_PIN_7, GPIO_DIR_MODE_HW);
//Enable GPIO for QEI0
//PD3-> IDX0
//PD6-> PHA0
//PD7-> PHB0
GPIOPinConfigure(GPIO_PD3_IDX0);
GPIOPinConfigure(GPIO_PD6_PHA0);
GPIOPinConfigure(GPIO_PD7_PHB0);
//
// Configure the QEI module.
//
QEIConfigure(QEI0_BASE,
(QEI_CONFIG_NO_RESET | QEI_CONFIG_CAPTURE_A_B |
QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), QEI1_POSCNT_MAX-1);
//Set to 0
QEIPositionSet(QEI0_BASE, 100);
QEIVelocityConfigure(QEI0_BASE, QEI_VELDIV_1, 500000); //Configure the Velocity capture Module //500000 is 10ms at 50MHz
QEIVelocityEnable(QEI0_BASE); //Enable the Velocity capture Module
QEIIntEnable(QEI0_BASE, QEI_INTDIR | QEI_INTINDEX); //Enable Interrupt when the Timer is reach 0 on Valocity capture mode
QEIEnable(QEI0_BASE);
//
// Configure the encoder input to generate an interrupt on every rising
// edge.
//
GPIOIntTypeSet(QEI_PITCH_PHA_PORT, QEI_PITCH_PHA_PIN, GPIO_RISING_EDGE);
GPIOPinIntEnable(QEI_PITCH_PHA_PORT, QEI_PITCH_PHA_PIN);
IntEnable(QEI_PITCH_PHA_INT);
//Interrupt Enable
//IntEnable(INT_QEI1);
}
else
if(ulBase == QEI1_BASE) // ROLL Encoder
{
//
// Enable the peripherals QEI example.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI1);
GPIOPinTypeQEI(QEI_ROLL_PHA_PORT,QEI_ROLL_PHA_PIN);
GPIOPinTypeQEI(QEI_ROLL_PHB_PORT,QEI_ROLL_PHB_PIN);
GPIOPinTypeQEI(QEI_ROLL_INDEX_PORT,QEI_ROLL_INDEX_PIN);
// Set F 0 and 1 to alternative use
GPIODirModeSet(GPIO_PORTC_BASE, GPIO_PIN_4, GPIO_DIR_MODE_HW);//GPIO_DIR_MODE_HW
GPIODirModeSet(GPIO_PORTC_BASE, GPIO_PIN_5, GPIO_DIR_MODE_HW);
GPIODirModeSet(GPIO_PORTC_BASE, GPIO_PIN_6, GPIO_DIR_MODE_HW);
//Enable GPIO for QEI1
//PC4-> IDX0
//PC5-> PHA0
//PC6-> PHB0
GPIOPinConfigure(GPIO_PC4_IDX1);
GPIOPinConfigure(GPIO_PC5_PHA1);
GPIOPinConfigure(GPIO_PC6_PHB1);
//
// Configure the QEI module.
//
QEIConfigure(QEI1_BASE,
(QEI_CONFIG_NO_RESET | QEI_CONFIG_CAPTURE_A_B |
QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), QEI1_POSCNT_MAX-1);
//Set to 0
QEIPositionSet(QEI1_BASE, 100);
QEIVelocityConfigure(QEI1_BASE, QEI_VELDIV_1, 500000); //Configure the Velocity capture Module //500000 is 10ms at 50MHz
QEIVelocityEnable(QEI1_BASE); //Enable the Velocity capture Module
QEIIntEnable(QEI1_BASE, QEI_INTDIR | QEI_INTINDEX); //Enable Interrupt when the Timer is reach 0 on Valocity capture mode
QEIEnable(QEI1_BASE);
//
// Configure the encoder input to generate an interrupt on every rising
// edge.
//
GPIOIntTypeSet(QEI_ROLL_PHA_PORT, QEI_ROLL_PHA_PIN, GPIO_RISING_EDGE);
GPIOPinIntEnable(QEI_ROLL_PHA_PORT, QEI_ROLL_PHA_PIN);
IntEnable(QEI_ROLL_PHA_INT);
}
}