This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello.
I am working with the TIva TM4C123G with ccs5.4.
I am having a problem with enabling the QEI1 index interrupt.
I know that the index works since when working with index reset the QEI resets every time I pass the index location.
But when I try to work with the index interrupt things don't work any more.
Can anyone find any problem with the code?
/// the interrupt routine ///
void QEI1IntHandler(void) {
unsigned long status1;
status1 = QEIIntStatus(QEI1_BASE, false);
if ((status1 & QEI_INTINDEX) == QEI_INTINDEX)
{
_IndexPosition = QEIPositionGet(QEI1_BASE) % 10000;
QEIIntClear(QEI1_BASE, QEI_INTINDEX);
}
}
/////////// Main Configuration ////////
SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
//
// Enable port PC5 for QEI1 PHA1
//
GPIOPinConfigure(GPIO_PC5_PHA1);
GPIOPinTypeQEI(GPIO_PORTC_BASE, GPIO_PIN_5);
//
// Enable port PC6 for QEI1 PHB1
//
GPIOPinConfigure(GPIO_PC6_PHB1);
GPIOPinTypeQEI(GPIO_PORTC_BASE, GPIO_PIN_6);
//
// Enable port PC4 for QEI1 IDX1
//
GPIOPinConfigure(GPIO_PC4_IDX1);
GPIOPinTypeQEI(GPIO_PORTC_BASE, GPIO_PIN_4);
// Enable processor interrupts.
//
IntMasterEnable();
QEIConfigure(QEI1_BASE,
(QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_RESET_IDX
| QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), 2000000);
QEIEnable(QEI1_BASE);
QEIPositionSet(QEI1_BASE, 100000);
IntEnable(INT_QEI1);
QEIIntEnable(QEI1_BASE, QEI_INTINDEX);
Thanks
Asi.
A quick look over the code doesn't show anything glaringly wrong to me. I would recommend reworking your interrupt handler a bit because they way you have it now, you run the risk of seeing phantom calls to the handler. If you clear the interrupt right before exiting the handler, it is possible that the write to the QEI interrupt clear register won't have completed by the time the CPU exits the exception and you'll end up being re-interrupted immediately. Try moving the QEIIntClear call immediately under the QEIIntStatus call and use status1 as the set of flags to clear so that anything that is pending is cleared there.
Could you post a bit more information on what you are seeing when you run this? Is your QEI1 handler ever being called? Which, if any QEI interrupt sources are marked as active when it is called? When the code doesn't work, what state is it in? Has it faulted or is it sitting in the default interrupt handler function (rather than just not seeing any interrupt, this would suggest a bug in the logic or a problem in your vector table)?
HI, thanks for the reply.
After playing with the QEI a bit more I found out that the handler dose get called for other interrupts like the change direction. So I started to check what can be the problem with the Index interrupt, and found out that if the QEI configuration is NOT set to index reset the interrupt dose NOT called. meaning that if I wanted to get incremental position i.e. to know how many cycles are done or go to more that one round in each direction I can't do it with knowing when the index has passed (in order to decrees accumulated error).
So the work around i found is to use a GPIO interrupt instead of the QEI index interrupt. I connected the index line from the encoder reader to an input GPIO and using a level sensitive interrupt ( to reduce noise effect on the system) I was able to operate with getting the correct index location every time the index passes.
The confusing thing about it that i haven't found any reference to the operation mode of the index interrupt or any consideration that need to be taken in order to work with it. farther more I find it hard to imagine the need of the interrupt while in reset mode, rather than the need of it when not using the reset mode.
If any one have a suggestion about this behavior it would be nice to here and know about other workarounds.
Asi.
Hi Dave,
As far as I understand the QEI Index interrupt is only activated if the QEI is configured to set the counter to zero every time the index pulse is crossing the reader?
thanks Asi.