LPC1769 EINT on pin change

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC1769 EINT on pin change

1,482 Views
lpcware
NXP Employee
NXP Employee
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
0 Kudos
5 Replies

676 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_Europe on Sat Jul 30 11:02:15 MST 2011
Hello MaNi,

see Application Note 'AN10898 BLDC motor control with the LPC1700' for some ideas to control a BLDC motor.
0 Kudos

676 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MaNi on Fri Jul 29 10:14:51 MST 2011

Quote: Zero
And where ???
Chapter 9: LPC17xx General Purpose Input/Output (GPIO)


Yes, page 120 chapter 9.2.2 second item.
0 Kudos

676 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Jul 29 10:09:41 MST 2011

Quote: MaNi
But in the user manual it is written: [I]Each port pin can be programmed to generate an interrupt on a rising edge, a falling edge, [COLOR=red]or both[/COLOR].[/I]



And where ???

Chapter 9: LPC17xx General Purpose Input/Output (GPIO)

So again: EINT can't detect rising & falling, so use GPIO :eek:
0 Kudos

676 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MaNi on Fri Jul 29 10:00:45 MST 2011
Thanks Zero for your reply,


Quote: Zero
That's nonsense, you can't use a pin as EINT and GPIO at the same time.


Ok...good to know. I thought it is possible to declare the Pin as an external interrupt and also read the logical level of it.


Quote: Zero
EINT can't detect rising & falling, so use GPIO.


But in the user manual it is written: [I]Each port pin can be programmed to generate an interrupt on a rising edge, a falling edge, [COLOR=Red]or both[/COLOR].[/I]


Quote: Zero
Are you aware that there's a QEI in LPC1769


Yes, i've seen this. But if i understand it right, there's only one QEI. Later i've got 2 motors with 4 hallsensors...so i think i can't use it for all four sensors!?

I don't think the hole code is wrong. With an resolution of 180digits/round the code works.
The only thing i want to improve is to evaluate every change of the both pins EINT0 and EINT1.
I think at the moment it only works with one edge an so i have the lower resolution of 180digits/round and not 360digits/round.

Regards,
MaNi
0 Kudos

676 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Jul 29 09:43:25 MST 2011
That's nonsense, you can't use a pin as EINT and GPIO at the same time. EINT can't detect rising & falling, so use GPIO.
LPC_PINCON->PINSEL4 = 0x00500000;    /* set P2.10 as EINT0 and P2.11 as EINT1*/
  [COLOR=red]LPC_GPIOINT->IO2IntEnF = (1<<10)|(1<<11);    /* Port2.10&11 is falling edge. */[/COLOR]
[COLOR=red] LPC_GPIOINT->IO2IntEnR = (1<<10)|(1<<11);    /* also rising Edge */[/COLOR]

Are you aware that there's a QEI in LPC1769 :eek::eek:
0 Kudos