piclist 2001\03\06\130204a >
Thread: Mouse encoders
face BY : mikespam@spam_OUTwhitewing.co.uk

On Tue, 6 Mar 2001 14:30:34 -0000, you wrote:

{Quote hidden}

These encoders usually have a roughly 90 degree phase shift between
the 2 outputs.
The simplest way is to wait for (or have an interrupt on) a falling
edge on one of the inputs, and when received, sample the other input.
The state of the second input represents direction, so you either add
or subtract one from the position depending on the state, e.g.
<wait for falling edge on input 1>
movlw -1
btfsc <input 2>
movlw 1
addwf position

There are other ways which give more resolution but you probably won't
need to for your application.
One alternative, which gives the best resolution, is to use a state
lookup table, where on every change(rising or falling) in either input
(e.g. using RB4-7 int on change), you create a 4 bit value consisting
of the new and old states of the 2 inputs, and look up the increment
value (-1, +1 or 0 for illegal states) in a table.  
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email @spam@listservspamspammitvma.mit.edu with SET PICList DIGEST in the body

<o64aats7s9vebiofbq2qglsh9ac45bfcjn@4ax.com> quoted-printable

In reply to: <AF211C95CF03D4119F7C00A024AB2375026C99@PLATINUM>
See also: www.piclist.com/techref/microchip/ios.htm?key=encoder
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) Mouse encoders

month overview.

new search...