On Tue, Jun 11, 2013 at 7:55 PM, Patrick Moody w= rote: > On 11 June 2013 13:26, Manu Abraham wrote: >> Hi, >> >> Rewrote the Rotary encoder for use with an 18F4550 in C18. >> >> I can't really make out what is wrong in there. It looks as though >> everything makes sense, but the result doesn't make sense, >> ie the increments/decrements, I cannot see (at least 0-9) >> Change is quite random. >> >> The code is here: >> >> http://goo.gl/Qm0Re >> >> If someone could lend another pair of eyes, would be very helpful. >> > > On line 66, your comment suggests that you expect enc_s to potentially > be something other than 0 (zero) at this point. > It won't because on line 58 it is re-initialised to 0 (zero) on every > call of the interrupt. > > To make it behave the way you expect, on line 58 declare it as "static > u8 enc_s =3D 0;". You can leave out the declaration of "read" since > you're not using it any more. If you did decide to use the "read" > variable for debouncing, it could (and should in order not to waste > resources) be declared separately since it doesn't need to be static. > The effect of the static keyword is that your initialisation to 0 will > only happen on the first call, and to ensure that the variable is > saved in between subsequent calls to the interrupt handler. > > Someone previously posted a link to the wikipedia page which probably > explains this better than I just did Ugh, somehow I did miss the static initializer. :-( Did make the change and try again, but increments/decrements seems to be the order of 4. ie 0, 4, 8 ... decrement also seems t work rotating in the other direction. The problem that I see us that the increments are still in the order of 4. Any thoughts ? Updated code here. http://goo.gl/xti8N 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 .