lpcware

LPC1769 EINT on pin change

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by MaNi on Fri Jul 29 09:21:58 MST 2011
Hello Folks,

i am new in the LPC Community (my first week) and at the moment I try to understand the external interrupt.
For a project with an motorencoder (hallsensors) i'll need 2 pin change interrupts to resolve the relativ position and later the velocity/acceleration of the motor.
Hardware is the LPC1769 LPCXpresso-Board.

So i used the external interrupts 0&1 and declared them to detect falling and also rising edges. Here's the init of the EINT's:

uint32_t EINTInit( void )
{
  LPC_PINCON->PINSEL4 = 0x00500000;    /* set P2.10 as EINT0 and P2.11 as EINT1*/

  LPC_GPIOINT->IO2IntEnF = (1<<10)|(1<<11);    /* Port2.10&11 is falling edge. */
  LPC_GPIOINT->IO2IntEnR = (1<<10)|(1<<11);    /* also rising Edge */

  LPC_SC->EXTMODE = EINT0_EDGE |EINT1_EDGE;        /* INT0&1 edge trigger */
  LPC_SC->EXTPOLAR = 0;                /*falling edge by default */

  NVIC_EnableIRQ(EINT0_IRQn);
  NVIC_EnableIRQ(EINT1_IRQn);

  return(1);
}
After that i wrote the code for the IRQHandler 0:

void EINT0_IRQHandler (void)
{
NVIC_DisableIRQ(EINT0_IRQn);

  if( ((LPC_GPIOINT->IO2IntStatF)& (1<<10)) ) //INT0 Falling Edge
      {
      if( (LPC_GPIO2->FIOPIN & (1<<11)) )    //INT1 is High
          eint_counter++;
      else                                    //INT1 is Low
          eint_counter--;

      LPC_SC->EXTPOLAR |= (1<<EXTPOLAR0);    //Next Time Rising Edge
      }

  if( ((LPC_GPIOINT->IO2IntStatR)& (1<<10)) ) //INT0 Rising Edge
        {
        if( (LPC_GPIO2->FIOPIN & (1<<11)) )    //INT1 is High
            eint_counter--;
        else                                    //INT1 is Low
            eint_counter++;

        LPC_SC->EXTPOLAR &= ~(1<<EXTPOLAR0);    //Next Time Falling Edge
        }

  new_data=1;                        //Flag for UART function in main-loop

  NVIC_EnableIRQ(EINT0_IRQn);
  LPC_SC->EXTINT = EINT0;        /* clear interrupt */
}
and IRQHandler 1:

void EINT1_IRQHandler (void)
{
NVIC_DisableIRQ(EINT1_IRQn);

    if( ((LPC_GPIOINT->IO2IntStatF)& (1<<11)) ) // INT1 Falling Edge
          {
          if( (LPC_GPIO2->FIOPIN & (1<<10)) )    // INT0 High
              eint_counter--;
          else                                    // INT0 Low
              eint_counter++;

          LPC_SC->EXTPOLAR |= (1<<EXTPOLAR1);    //Next time Rising Edge
          }

    if( ((LPC_GPIOINT->IO2IntStatR)& (1<<11)) ) //INT1 Rising Edge
          {
            if( (LPC_GPIO2->FIOPIN & (1<<10)) )    //INT0 High
                eint_counter--;
            else                                    //INT0 Low
                eint_counter++;

            LPC_SC->EXTPOLAR &= ~(1<<EXTPOLAR1);    //Next time Falling Edge
            }

    new_data=1;                            //Flag for UART function in main-loop

NVIC_EnableIRQ(EINT1_IRQn);
LPC_SC->EXTINT = EINT1;        /* clear interrupt */
}
UART3 is used in the main function to put out the rounds (eint_counter) of the motor. The flag new_data is used to signalize that new data are present and print/cleare it in the main function.

Now i have the problem that only 180 digits/round are detected and not like suggested 360 digits/round. So i think something is wrong with the toggle between the rising/falling edge detection.

Does anyone of the experienced LPC-Users see the fault?
Or is the init / IRQ Code of the EINT's right?

Sorry because of my bad bad bad....english.

Regards
MaNi

Outcomes