Extremely weird Interrupt behavior

01 Jun 2011

Hello everyone,

I'm using pinchange interrupts on the MBED lpc1768 for the first time and something is going seriously wrong. I would like to get an interrupt on the rising edge of an input signal, and so far the code works fine. But sometimes I get some random interrupt between two pulses of the input signal. In the picture the readout of the scope is shown. The yellow signal is the input signal on the interrupt pin and the Blue signal is the toggling signal (toggled each interrupt). I really can't see a reason why the interrupt should be triggered at te point it is triggered now. The rise time of the yellow signal is 250ns and it comes from a voltagecomparator with hysteresis so I thought it would be 'nice' enough.

Thank you in advance for your help! Kind regards Geert

/media/uploads/Geertje/foto0139.jpg

#include "mbed.h"

Serial pc(USBTX, USBRX);
DigitalOut myled(p20);
DigitalOut Ledj(LED1);

void pinchange(void)
{
    myled=!myled;
}

int main() {
    
    InterruptIn _pin(p16); 
    _pin.mode(PullUp);
    _pin.rise(&pinchange);
    while(1)
    {
        wait(1);
        Ledj=!Ledj;
        wait(1);                 
    }
}
07 Jun 2011

Hello all,

Just for the record I would like to tell you I think i've found the problem. This interrupt routine has to keep track of edges created by a rotary encoder, which is coupled to a motor. The motor creates emi and i think that is the reason for the failing interrupts (although the supplies are not connected and thoroughly buffered with capacitors). The distortions somehow can not be seen on the oscilloscope (checked the supply and the datalines) but perhaps it directly affects the mbed board/core. When I connect a function generator to simulate the rotary encoder-pulses, everything is fine. So nothing is wrong with the mbed at all. Now i'll start with some shielding in order to solve the problem completely.

kind regards, Geert

08 Jun 2011

This could also be contact bounce, if you are using a mechanical encoder.

You might look at Andy's PinDetect library, as it has debouncing ability. Or try my QEI_hw driver that supports hardware debouncing via digital filtering.

08 Jun 2011

It has to be a contact bounce issue. Add some debounce code and everything should work fine :)