On Mon, Jun 10, 2013 at 6:38 AM, Denny Esterline wro= te: > "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 decreme= nt > based on the state of the non-interrupt pin. (interrupt when A channel go= es > 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 channel= s. > 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 valu= e > 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. I freed up some associated pins on the microcontroller. http://farm4.staticflickr.com/3763/9005870401_b52fc6b8fd_o.jpg Using PORTB change interrupt to detect the Encoder event, RB4 connected to Encoder B RB5 connected to Encoder A RB6, RB7 connected to ICSP You can see the OLED displaying the count in the picture. http://hifiduino.wordpress.com/2010/10/20/rotaryencoder-hw-sw-no-debounce/ Bourns has an application note on debouncing: http://www.bourns.com/data/global/pdfs/Bourns_enc_sgnl_cond_technote.pdf Seemed like the lookup way was quite reliable and fast too, hence. One thing that I don't understand is, why he does this: " static uint8_t old_AB =3D 0;" that would loose the previous state altogether, wouldn't it ? So, I put up some code which does the following on a PIC18F4550 const s8 rom enc_states[] =3D { 0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0 }; u8 c_state =3D 0; #pragma interrupt hi_interrupt void hi_interrupt(void) { if (INTCONbits.RBIF) { INTCONbits.RBIF =3D 0; LATD =3D disp_bits[1]; LATE =3D 1; /* on display:1 */ // c_state =3D 0; c_state <<=3D 2; /* previous state */ c_state |=3D (PORTB >> 4) & 0x03; /* add current state */ count +=3D enc_states[(c_state & 0x0f)]; } } and I am simply displaying the count: buf[0] =3D count; ssd1308_wr_str(buf, 8); Running it, the count doesn't seem to be correct, sometimes jumps by increment of 4 sometimes 1 etc. Any other thoughts how to better debounce the input ? Or is it a bug, rather than a debounce issue ? Thanks, Manu --=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 .