28

Foreach axis on a mechanical (ball) mouse there is an IR transmitter and receiver pair with a wheel that looks like having only simple slits.

How is the direction calculated?

zaf
  • 453
  • 6
  • 10

1 Answers1

36

There's not just an IR transmitter/receiver pair, there are two of them. Between transmitters and receivers there's a slotted wheel, which, when rotating, causes a pulse train in the receiver. (The light from the transmitter is blocked, can pass, blocked again, and so on.)

enter image description here

The trick is how the two receivers are placed, namely in quadrature.

enter image description here

This means that the pulses of one receiver precede the pulses of the other by a number of degrees (ideally 90°). If the wheel turn the other way the same pulses now lag the others.

enter image description here

Notice that on a rising edge of channel A the B channel is at a high level when turning one way, and low when turning the other way.

edit (about absolute encoders)
I wasn't completely satisfied with my reply to JGord's comment (some inaccuracies), hence this reprise
The system described above is known as an incremental encoder because it detects relative changes, from one position to the next. Over a full rotation the codes are repeated a number of times, so you can't know your absolute position just by looking at the code.
To overcome this there exist absolute encoders. Instead of two channels in quadrature they have a lot more channels creating a unique pattern for each rotation position. A 10 channel encoder can tell \$2^{10}\$ or 1024 different positions apart. Shaft encoders in robots are even more accurate.

enter image description here

The specific pattern is typical of Gray coding.

about Gray coding
Ordinary binary has the disadvantage that code transitions may create erroneous codes during the transition. Take for instance the change from 0111 (7) to 1000 (8). If the leftmost bit is a bit faster than the others you will see for a moment 1111 (15), which is totally off.
Gray code overcomes this by rearranging the codes so that there's only 1 bit changing at a time.

Absolute encoders won't help you to find the absolute mouse position, however, because the wheel rotates several times while you're moving the mouse. The "unique" pattern will repeat every few mm and isn't so unique after all. Besides, it's always possible to move the mouse when the computer is off, or you can lift the mouse and put it down again a bit further. Both actions will go undetected.


Further reading
"Control Shaft Encoders" \$-\$ Circuit Cellar issue 250, May 2011, p.28 ff

stevenvh
  • 145,145
  • 21
  • 455
  • 667
  • The image in the answer is broken. – zaf Jun 15 '11 at 16:10
  • Question: This dual channel optical encoder works for position and velocity, but what if you needed to know total distance? So for example, what if you spun it a bunch of times, turned off your device, turned it back on later, and spun it a bunch more times. Sure you could record the distance to non-volatile memory each time, but is there a mechanical way of solving this problem? I'm thinking in the direction of a cleverly placed third channel... but I can't come up with anything. – NickHalden Jun 15 '11 at 16:46
  • @stevenvh - [They're working on it](http://meta.stackexchange.com/questions/94989/my-stack-overflow-imgur-images-are-disappearing/94991#94991), the URLs are being changed from the standard `i.imgur.com` to `stack.imgur.com`. – Kevin Vermeer Jun 15 '11 at 17:27
  • @stevenvh Hm, I wonder if anyone has thought to try using DeBruijn Sequences rather than gray code... – NickHalden Jun 15 '11 at 17:41
  • 1
    @stevenvh alright, basically there are two receivers housed in one unit. Thanks. – zaf Jun 16 '11 at 06:57
  • @JGord - I replaced my answer to your comment by an addendum to my answer to the OP. – stevenvh Jun 16 '11 at 08:21
  • @stevenvh Wow, thats really neat looking. I'm not exactly sure how they're related, but based on what you're saying Gray Codes seem extremely similar to DeBruijn sequences. Going to do some exploring. – NickHalden Jun 16 '11 at 16:18
  • @stevenvh Ok, I understand the difference now. So if you were to use a DeBruijn sequence, you would only need one ring of printed pattern, but 10 IR emitter/detector pairs. This would come in handy if for some reason you needed an encoder which had to fit certain physical limitations. BTW, anyone know if Gray Code relates to the Walsh basis set through some fancy Lin Alg? – NickHalden Jun 16 '11 at 16:27
  • @JGord: Yes, [single-track Gray code STGC](http://en.wikipedia.org/wiki/Gray_code#Single-track_Gray_code). – davidcary Jun 19 '11 at 01:56
  • @JGord the device you are looking for is called an odometer – joeforker Sep 29 '11 at 12:33
  • Regarding the Gray coding image: I am now hypnotised. – kinokijuf Feb 07 '12 at 18:14
  • @JGord, they use 'homing' in the CNC world to get around power cycles, and other situations. – Michael Pruitt Feb 08 '12 at 06:46