On Tue, Jun 11, 2013 at 11:11 PM, Joe Wronski wrote: > On 6/11/2013 1:16 PM, Manu Abraham wrote: >> On Tue, Jun 11, 2013 at 10:27 PM, Manu Abraham = wrote: >>> On Tue, Jun 11, 2013 at 9:09 PM, Joe Wronski wrote: >>>> Since the enc_tab[] only contains -1,0,+1, the only explanation I can >>>> think of would be that you are actually getting 4x the number of >>>> interrupts that you think you are. Have you tried setting breakpoints >>>> in the interrupt or print_error_code() func to step through the code? >>>> Also, what happens when the count goes over 9 or less than 0? You onl= y >>>> have 10 digits to print 16 possible values, and count is unsigned. >>> Right, array returns 1, -1 or 0 only. Interrupt is fired 4 times for RB= IF, >>> PORTB change Interrupt. >>> >>> The display can show 0-9, so after a reset/powerup, it starts with 0. := -) >>> >>> I guess, I understand what's happening. >> Ditched the array, looking directly at the mechanical states. >> Retained the small debouncing counter, It feels better turning the knob = with >> this debouncing in there. >> >> Simplified the code to look thus: http://goo.gl/sjrlF >> >> Thanks to all the people, who helped to helped to shoot this bug down. := -) >> Hope the code snippet will be useful to someone, trodding this path agai= n. >> >> >> Thanks, >> >> Manu > I don't know why I started following this, maybe because I had done some > rotary encoder code before (and promptly forgot how it worked). > The new way better, because you're only using 1of the 2 encoder bits. > I think you're throwing away either resolution or state information by > ignoring the value of ENC_B. > But, I suppose ENC_B contributes an interrupt, so it's not as thought > it's not there at all. Resolution looks fine. Spinning it as fast as I can (connected the OLED display), Can see the charset on the display for each count increment/decrement, as expected even when rotating the encoder really really fast. No glitches = and or lost counts, or reverse counts. Works just as expected. There are 4 interrupts, due to 4 changes, due to 4 logic states. All the lo= gic states are handled. In any case, you cannot change the counter for all the = 4 states, but only for the 2 states. So, I guess things look okay for now. Regards, 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 .