LPC 1114 externl interrupt

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

LPC 1114 externl interrupt

2,007 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Forrest on Fri Feb 17 05:55:21 MST 2012
Hi all,

I have problem with generating external interrupt at port 0. I use 3 pins (P0.7 P0.6 P0.3) this pins are configured as gpio inputs and set to generate interrupt at rising adge.

Code:
[I]GPIOSetDir(INPUT_25_PORT, INPUT_25_BIT, 0);
GPIOSetDir(INPUT_26_PORT, INPUT_26_BIT, 0);
GPIOSetDir(INPUT_27_PORT, INPUT_27_BIT, 0);
GPIOSetInterrupt(INPUT_25_PORT,INPUT_25_BIT, 0, 0, 0);
GPIOSetInterrupt(INPUT_26_PORT,INPUT_26_BIT, 0, 0, 0);
GPIOSetInterrupt(INPUT_27_PORT,INPUT_27_BIT, 0, 0, 0);
GPIOIntEnable(INPUT_25_PORT, INPUT_25_BIT);
GPIOIntEnable(INPUT_26_PORT, INPUT_26_BIT);
GPIOIntEnable(INPUT_27_PORT, INPUT_27_BIT);[/I]

[I]NVIC_SetPriority(UART_IRQn, 5);
NVIC_SetPriority(TIMER_16_0_IRQn, 4);
NVIC_SetPriority(SysTick_IRQn, 3);
NVIC_SetPriority(EINT0_IRQn, 1);
NVIC_SetPriority(EINT2_IRQn, 1);[/I]

And interrupt handler looks like this.
[I]unsigned int inputs = 0; //global wariable
void PIOINT0_IRQHandler(void)
{
    unsigned int source = LPC_GPIO0->MIS;
    inputs |= source;
    LPC_GPIO0->IC |= source;
}[/I]

So problem is that I connect function generator(square 5Hz) parallel to at all pins. Sometimes any enterrupt miss and I miss edge.

Have you any idea? Becouse I think that MCU cant correctly generate interrupt.
Thanks Forrest
0 Kudos
Reply
6 Replies

1,398 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_Europe on Sun Feb 19 14:51:55 MST 2012
Hello forrest,

I agree with gbm ... you changed the priorities of the interrupts. Try to use the original values first.

Your schematic is not the best way of using an opto-coupler ... better way is to use the transistor as switch to ground, attach pull-up resistors to V+.

A large capacitor is used, that means less steep flanks.

Try first to connect the function generator directly on the input of the controller. Test the software and try to optimize it and then put the opto-coupler back into your schematic again.
0 Kudos
Reply

1,398 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Sun Feb 19 12:47:45 MST 2012
The key to your problem is "critical section".
The simplest solution is to set all interrupts using "inputs" variable to the same priority level. Simply don't change the default priorities.
0 Kudos
Reply

1,398 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Forrest on Sun Feb 19 12:17:19 MST 2012
OK I detaily all explain.

As you can see in my code above Im using cmsis library.

Pins are set to gpio inputs and interrupt is set to generate interrupt at rising edge.

Firstly I check EXTINT example and I think my code is same(of cource little diferrent).

There image is about pins schematic. This part is same for every three pins.
http://imageshack.us/photo/my-images/651/schemak.jpg/

How I know that interrupt working correctly? Im using system timer set to 100usec and decode input_1 variable. If bit in variable is set I increment pins counter. So If i connect signal paralelly I think counters will be same value. But isnt.

So full code look like this.

[I]volatile unsigned int inputs_1 = 0;[/I]
[I]main()
{
GPIOInit();    //global init all pins[/I]
[I]GPIOSetDir(INPUT_25_PORT, INPUT_25_BIT, 0); //pin set as input
GPIOSetDir(INPUT_26_PORT, INPUT_26_BIT, 0);
GPIOSetDir(INPUT_27_PORT, INPUT_27_BIT, 0);
GPIOSetInterrupt(INPUT_25_PORT,INPUT_25_BIT, 0, 0, 0); //set interrupt at rising edge
GPIOSetInterrupt(INPUT_26_PORT,INPUT_26_BIT, 0, 0, 0);
GPIOSetInterrupt(INPUT_27_PORT,INPUT_27_BIT, 0, 0, 0);
GPIOIntEnable(INPUT_25_PORT, INPUT_25_BIT);
GPIOIntEnable(INPUT_26_PORT, INPUT_26_BIT);
GPIOIntEnable(INPUT_27_PORT, INPUT_27_BIT);[/I]

[I]NVIC_SetPriority(UART_IRQn, 5);
NVIC_SetPriority(TIMER_16_0_IRQn, 4);
NVIC_SetPriority(SysTick_IRQn, 3);
NVIC_SetPriority(EINT0_IRQn, 1);
NVIC_SetPriority(EINT2_IRQn, 1);[/I]
[I]
if (SysTick_Config(SystemCoreClock / 10000))    //1000=1msec 10000=100usec 100000=10usec 20000=50usec
        while (1);


while(1)
{
//uart communication atc...
}
[/I][I]}

/*----------------------------------------------------------------------------*/
void PIOINT0_IRQHandler(void)
{
    unsigned int source = LPC_GPIO0->MIS;
    inputs_1 |= source;
    LPC_GPIO0->IC |= source;
    test_flags = 1;
}
/*----------------------------------------------------------------------------*/
void SysTick_Handler(void)    //100uSec
{
    __disable_irq();
    if(inputs_1 & BIT_MASK_07)
        {
            inputs_1 &= ~BIT_MASK_07;
            if(mb_data.counter_1_l == 0xffff)
                mb_data.counter_1_h++;
            mb_data.counter_1_l++;
        }

        if(inputs_1 & BIT_MASK_06)
        {
            inputs_1 &= ~BIT_MASK_06;
            if(mb_data.counter_2_l == 0xffff)
                mb_data.counter_2_h++;
            mb_data.counter_2_l++;
        }

        if(inputs_1 & BIT_MASK_03)
        {
            inputs_1 &= ~BIT_MASK_03;
            if(mb_data.counter_3_l == 0xffff)
                mb_data.counter_3_h++;
            mb_data.counter_3_l++;
        }
        __enable_irq();
}[/I]
0 Kudos
Reply

1,398 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_Europe on Sat Feb 18 05:57:09 MST 2012
Hello forrest,

without diving into the problem into detail yet, but did you try to check the inputs piece by piece. So not putting them in parallel?

Connect one input to your square 5 Hz and connect the other inputs on pull up resistors to Vdd. Do the testing and so on for the other two inputs.

How do you know that an interrupt is missing?

Please compare your code to the [B]'extint'[/B] -code written in the example in e.g. the 'NXP' file on your PC c:-directory. Start simple with only one channel.
0 Kudos
Reply

1,398 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by stalisman on Fri Feb 17 09:24:05 MST 2012
He could write his own code but it looks a tad like the 'codebase for the LPC1114' code in which case the documentation exists to explain what the parameters mean etc.

I am having enough trouble of my own with this stuff as although I know the intention something whacky on my own board is going on ... but that's my problem.  Essentially I have zillions of interrupts of which maybe 1% are missed .. either that or the registers are telling porkies .. but what the heck it's probably the hardware at fault anyway.

Regarding the above code I'd like to know how the pins are configured via the IOCON registers ... then when someone comes up with a brilliant analysis it'll probably solve my problems too :-)
0 Kudos
Reply

1,398 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Fri Feb 17 07:15:58 MST 2012
Start by declaring inputs variable as volatile. Get rid of tens of library function calls and replace them with 4..5 simple statements operating on GPIO control registers - this way you will know what your code is doing.
0 Kudos
Reply