"Best" is a matter of opinion and what you're trying to achieve. Easiest is usually to only use one of the interrupts and either increment or decrement based on the state of the non-interrupt pin. (interrupt when A channel goes high and increment if B is high, decrement if B is low) Personally I'm fond of a different technique which results in higher resolution. But it does require storing the previous state of the encoder and interrupting on both rising and falling edges of both A and B channels. After an interrupt, XOR previous B value with the current A value. Increment or decrement based on the result. Don't forget to save the value for the next interrupt. A third technique is to concatenate the encoder bits and use it as the index into a lookup table. Where the results of the lookup are +1, -1 or 0 that are then added to your counter variable. Good luck, -Denny On Sun, Jun 9, 2013 at 3:43 PM, Manu Abraham wrote= : > Hi, > > What's the best way to decode a rotary encoder (gray code) output, > when the outputs of the encoder are connected to edge detectors > both of which result in an IRQ each ? > (in a microcontroller, of course) > > (I have connected the decoder pins A&B to CCP1&2 of a PIC which > result in 2 IRQ's (ie; CCP1 and CCP2) on each state change) > > > Thanks, > > Manu > -- > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .