I have a problem reading encoder position using _position = QEIPositionGet(QEI0_BASE);
Part if LM4F231
code:
//////////////////////////////////
int _position;
int _velocity;
void QEI0IntHandler(void)
{
unsigned long status2, status1;
status1 = QEIIntStatus(QEI0_BASE,false);
if ( (status1 & QEI_INTTIMER) == QEI_INTTIMER)
{
QEIIntClear(QEI0_BASE, QEI_INTTIMER);
_position = QEIPositionGet(QEI0_BASE);
_velocity = QEIVelocityGet(QEI0_BASE);
}
if ( (status1 & QEI_INTDIR) == QEI_INTDIR)
{
QEIIntClear(QEI0_BASE, QEI_INTDIR);
}
if ( (status1 & QEI_INTDIR) == QEI_INTERROR)
{
QEIIntClear(QEI_BASE, QEI_INTERROR);
}
volatile int ix = 0; while(ix < 1000) { ix++; }
}
static void Qei0Init() {
//
// Enable the QEI peripheral.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI0);
SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_QEI0);
// wait to make syre periph. enabled
volatile int ix = 0; while(ix < 1000) { ix++; }
QEIDisable(QEI0_BASE);
//
// Configure the QEI pins.
//
GPIOPinConfigure(GPIO_PF0_PHA0);
GPIOPinConfigure(GPIO_PF1_PHB0);
//GPIOPinConfigure(GPIO_PF4_IDX0);
GPIOPinTypeQEI(GPIO_PORTF_BASE, (GPIO_PIN_0 | GPIO_PIN_1));
//GPIOPinTypeQEI(GPIO_PORTF_BASE, GPIO_PIN_4);
//
// Configure the operation
//
QEIConfigure(QEI0_BASE,(QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_NO_RESET | QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), 20000);
QEIEnable(QEI0_BASE);
QEIPositionSet(QEI0_BASE, 1000);
//Timer Interval 1s/1000 = 1ms
QEIVelocityConfigure(QEI0_BASE, QEI_VELDIV_1, SysCtlClockGet()/1000);
//
//Enable the Velocity capture Module
//
QEIVelocityEnable(QEI0_BASE);
QEIIntRegister(QEI0_BASE,*QEI0IntHandler);
IntEnable(INT_QEI0);
QEIIntEnable(QEI0_BASE,QEI_INTDIR | QEI_INTTIMER);
//
// Loop forever
//
while(1)
{
ix = 0;
while(ix < 1000) { ix++; }
}
}
/////////////////////////////////////////
When code is run _velocity changes. _position doesn't change; or at least doesn't change much - it may drift from 1000 one or two counts there and there, but with no pattern.
Enabling Index pin doesn't have an effect.
Reading values outside of ISR doesn't have an effect.
Reading value from register directly using HWREG doesn't have an effect.
Monitoring register content using IAR debugger confirms observation: value of QEI0POS doesn't change.
Errata has couple entries on QEI operations, but doesn't seem to have that affect.
What am I missing here?
Thank you