lpcware

LPC1769 encoder interrupt

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by Shoaib on Sat Aug 16 01:25:27 MST 2014
Hi everyone!

I am working on the QEI of LPC1769 but was facing few issues with the interrupt status register. I want to measure the velocity of the motor whenever the LPC_QEI->QEITIME register overflows.
The problem is that the timer interrupt in the LPC_QEI->QEIINTSTAT becomes high even though the timer has not overflowed. It does it even clear the interrupt when the LPC_QEI->QEICLR is used.

/**** code****/
#ifdef __USE_CMSIS
#include "LPC17xx.h"
#endif

#include <cr_section_macros.h>

uint32_t meas_rpm,i=0,j=0,k=0,test=0,test1=0,test2=0,ans;

void qei_init()
{
   LPC_SC->PCONP    |= 1<<18;          // Power up QEI
   LPC_SC->PCLKSEL1 |= 3;             // Select clock for QEI = cclk/8

   LPC_PINCON->PINSEL3 |= (1<<8);       // configure as MCI0-QEA  - P1.20
   LPC_PINCON->PINSEL3 |= (1<<14);    // configure as MCI1-QEB  - P1.23
   LPC_PINCON->PINSEL3 |= (1<<16);    // configure as MCI2-INDX - P1.24

   LPC_QEI->QEICONF |= (1<<2);       // Set quadrature mode - 4x mode
   LPC_QEI->QEIMAXPOS= 0xFFFFFFFF;      // Maximum pulse count limit after which counter resets
   LPC_QEI->FILTER     = 0;             // Number of clk delays
}

void en_encoderint() [color=#c0f]//Done in two ways[/color]
{
//LPC_QEI->QEIIES |= (1<<5);
//LPC_QEI->QEIIES &= 0xFFFFE002 ;[color=#c0f]1) Used only this line[/color]
LPC_QEI->QEIIES |= (1<<5); [color=#c0f]2) Used this and the following line[/color]
LPC_QEI->QEIIES |= (1<<1);
}

void QEI_IRQHandler()
{
k=k+1;
}

void main(void) {
qei_init();
en_encoderint();
LPC_QEI->QEICLR &=0x00001FFF;[color=#c0f]//INTSTAT = 0x120, expected value = 0 as all bits cleared[/color]
LPC_QEI->QEILOAD = 10000;[color=#c0f]// Has no effect with a smaller value (eg 10)[/color]
while(1) {
ans=LPC_QEI->QEIINTSTAT & 2;
if(ans == 2) [color=#c0f] //the statement if(LPC_QEI->QEIINTSTAT & 2 == 2) is giving incorrect solution (res=1?)[/color]
      {
LPC_QEI->QEICLR &= 0x00001FFF;[color=#c0f]// is not affecting the INTSTAT reg[/color]
meas_rpm = (SystemCoreClock/8)*LPC_QEI->QEICAP*60/(LPC_QEI->QEILOAD*1024*4);
[color=#c0f]// I want to clear the interrupt so that I measure the velocity at the exact instant when the velocity timer reg overflows[/color]
}

}

}
/**** End of code****/

The second problem I am facing is that the code never enters the QEI ISR. I used a test int k to see if ISR code was implemented but it did not change.

Thanks,

Outcomes