LPC1114 and Rotary necoder

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by vladimirro on Fri Jun 12 16:09:01 MST 2015
Hello all

I have a problem which is literally driving me crazy and I can't solve it.
I want to control a variable "number" with my rotary encoder

Here's the code for initialisation

void controlsinit()
//PIO2_5 <-- A
//PIO0_6 <-- B
LPC_GPIO2->DIR &= ~(1<<5);//PIO2_5 as input
LPC_GPIO0->DIR &= ~(1<<6);//PIO0_6 as input

LPC_GPIO2->IS &= ~(1<<5);//edge sensitive
LPC_GPIO2->IBE &= ~(1<<5);//no both edges
LPC_GPIO2->IEV &= ~(1<<5);//falling edge
LPC_GPIO2->IE |= (1<<5);//falling edge


And here's the interrupt code
void PIOINT2_IRQHandler(void)
if (LPC_GPIO0->DATA & (1<<6)) number--;
else number++;
LPC_GPIO2->IC = LPC_GPIO2->RIS;//clear edge interrupt

So I basically want to increment/decrement the variable number by rotating the knob.
The result is very random. Sometimes it is incrementing/decrementing by one, sometimes by 2 or even 50... sometimes it doesn't change the variable at all. Completely random.

Is there anything wrong with my code?