Kerry, mechanical or optical encoders output exact same data regardless of having = detent or no detent. Andre=A0 ________________________________ From: "jim@jpes.com" To: Microcontroller discussion list - Public. Sent: Wednesday, October 12, 2011 6:51 AM Subject: RE: [EE] Rotary Encoder Implementation ok.=A0 but how does that equate to counting rapidly?=A0 just curious. Regards, Jim > -------- Original Message -------- > Subject: Re: [EE] Rotary Encoder Implementation > From: Kerry Wentworth > Date: Tue, October 11, 2011 10:45 pm > To: "Microcontroller discussion list - Public." >=20 >=20 > Correct me if I'm wrong, but this encoder is mechanical, not optical,=20 > and it has detents, and moving from 1 detent to the next equals 360=20 > degrees of electrical travel.=A0 I have tried to use my normal optical=20 > encoder software with such encoders with poor results. >=20 > Using 4X or even 2X algorithms would have no advantage with such=20 > encoders.=A0 Also, they will never sit on the edge of=A0 A or B changing= =20 > with small vibrations. They will sit in a detent halfway between A=20 > change and B change. >=20 > Kerry >=20 >=20 >=20 > jim wrote: > > No it won't "count rapidly".=A0 Because I wait for the outputs to go to= =20 > > the normal resting state before I exit the routine where it adds to the > > count variable.=A0 I have been playing with the encoder to get it to me= ss=20 > > up, but I haven't been able to so far.=A0 It works for me as it is. YMM= V. > > I don't claim it to be bulletproof.=A0 All I claim is that I wrote it u= sing > > Information gleaned from observation of the encoder at work using a DMM= , > > And from others code posted on the internet. > > > > Regards, > > > > Jim > > > > -----Original Message----- > > From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behal= f Of Christopher Head > > Sent: Tuesday, October 11, 2011 5:48 PM > > To: piclist@mit.edu > > Subject: Re: [EE] Rotary Encoder Implementation > > > >=A0=20 > >> jim@jpes.com wrote: > >>=A0 =A0=20 > >>>=A0 All, > >>> > >>>=A0 I have been working with a rotary encoder that I am planning to > >>> use as a control for a piece of test=20 > >>>=A0 equipment at work.=A0 I have looked on the web for algorithms to > >>> decode the outputs of said encoder,=20 > >>>=A0 and have found several.=A0 Most of them work as advertised in my > >>> application, but I have come up with a=20 > >>>=A0 version that works very well in my opinion. > >>> > >>>=A0 I don't know whether it is new or novel, but all I have done is > >>> watch for the "A" output to go high. > >>>=A0 When it does, I then read the port that the encoder is attached > >>> to.=A0 I mask of the bits I am interested=20 > >>>=A0 in, and use this as an index into a table.=A0 If the value is "01"= I > >>> add "1" to my variable.=A0 If the value=20 > >>>=A0 is "10", I subtract "1" by adding 255.=A0 Any other combination "0= 0" > >>> or "11" adds a zero for no change. > >>> > >>>=A0 I have tried this out spinning the knob on the encoder as fast as = I > >>> can, and I can't see any missed=20 > >>>=A0 counts.=A0 I am using a delay of 2.5 mS in my routine for > >>> debouncing.=A0=20 > >>>=A0 =A0 =A0=20 > > > > I assume we're talking about a quadrature-output rotational encoder > > here; ignore if not. > > > > This will probably work fine when spinning the knob, but it could fail > > if the input is mostly still but jittering slightly. The outputs of a > > rotary encoder are in quadrature, so across a full output cycle, A will > > rise, then B will rise, then A will fall, then B will fall. Imagine if > > the knob is sitting right by the position where A rises, and is > > jittering slightly. You'll see the A output oscillating while B remains > > stable. Your example algorithm will count rapidly. A full > > quadrature-decode will simply add and subtract one repeatedly in this > > situation, accurately reflecting the physical reality. Also, doing > > proper quadrature decoding eliminates the need to do debouncing > > altogether, since any possible jitter occurs on only one output at a > > time and hence can only change the counter value by =B11. And it gives > > you 4=D7 the resolution. > > > > Chris > >=A0=20 >=20 > --=20 > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .