LPC1768 QEI Interupt

Hello All,

First off I am new to Mbed and C++ for that matter so my question may be obvious. Using an LPC1768 and the QEI interface. I have encoder counting properly on QEIPOS and have setup QEI_COMPPOS_CH_0 to trigger at position 0. Then enabled QEI_INTFLAG_POS0_Int, when I read the status of QEI_INTFLAG_POS0_Int it changes state and can be reset. My question is how do I make this trigger an interrupt to run a function? I have tried googling and found info pointing toward syntax like this:

void __attribute__((QEI_INTFLAG_POS0_Int)) do_interrupt() 

    // Do things

But alas this will not compile. Any help is appreciated.


Hello Dan,

Unfortunately, I have no deep knowledge of the LPC1768 hardware details (e.g. QEI). However, maybe you can use this Mbed QEI library which is based on the InterruptIn mbed API rather than on a specific QEI hardware built into the LPC1768.

Best regards, Zoltan

Thanks for the reply. I have used this library to implement a software encoder and it works very well, but I do not believe it will work in this case as I am using the builtin QEI of the 1768. If I am wrong please correct me. I have successfully used the InteruptIn from discrete pins.

mbed::InterruptIn  some_pin ;

some_pin.rise(this,  &on_pin_rise);

This will run function on_pin_rise every time the pin goes high. When I try QEI_INTFLAG_POS0_Int.rise(this, &on_flag_rise); I get an error that QEI_INTFLAG_POS0_Int does not have member rise(); . I believe the interrupt is already being called because this is the interrupt flag for position zero compare , I just don’t know how to access it.


Too late for me to check now, but
Find the startup code in targets/nxp/…
There should be the ISR , declared as weak, which your code will override (remember to use extern „C“ in cpp).
If it’s not declared, you can set the interrupt vector with global NVIC_SetVector().

Thanks for the reply. I will look into extern C for the time being. Anybody point me toward some example useage would be helpful, googling yields very little.


Got it! Anybody who is interested.


Setup function

extern "C" void QEI_IRQHandler (void)  
    if(QEI_GetIntStatus(LPC_QEI, QEI_INTFLAG_POS0_Int)) 
       //do things


Thanks for the info. I have tried to compile it but unfortunately the compiler (and me) was not able to find QEI_GetIntStatus and QEI_INTFLAG_POS0_Int. Could you please let us know where these items are declared/defined?

Thank you.

I am not using barebones mbed it is part of a larger system but so far everything seems to line up. Yours may vary a little as I think the version I am on is about 5 years old.

In the header file:
#include "mbed.h" 
#include "path_to/lpc17xx_qei.h"  //This is what you are missing

a quick google and:


FYI- These commands are only checking if the POS0 interrupt flag is set, it has to be cleared with this command :


In the header file is good information on other statuses that can be checked and parameters can be set.

Hope that helps.

That was the missing piece.

Thank you.