Mouse Optical Encoders / Wheels - diyAudio
Go Back   Home > Forums > General Interest > Everything Else

Everything Else Anything related to audio / video / electronics etc) BUT remember- we have many new forums where your thread may now fit! .... Parts, Equipment & Tools, Construction Tips, Software Tools......

Please consider donating to help us continue to serve you.

Ads on/off / Custom Title / More PMs / More album space / Advanced printing & mass image saving
Reply
 
Thread Tools Search this Thread
Old 24th November 2006, 12:26 AM   #1
diyAudio Member
 
Join Date: Feb 2003
Location: USA
Send a message via ICQ to discman1028 Send a message via AIM to discman1028
Question Mouse Optical Encoders / Wheels

Anyone ever open up a standard PS/2 mouse? They all have two LEDs with two spinning optical encoder wheels (one horizontal, one vertical -- duh).

I am wondering if anybody has ANY idea about the circuitry that is used to translate the patterns? I can't find any info on the chip that is on the board, so I'm not even sure if it's a microcontroller, or some specific IC meant for the job. (Or, if the logic is handled on a PC motherboard!)

Any ideas? I can't seem to find good info anywhere.

The reason being is I want to use that physical mechanism that is in place, intercept those signals on a microcontroler, interleave some other custom data, THEN send a custom message along to the PC.

Thanks.


Anyone ever open up a standard PS/2 mouse? They all have two LEDs with two spinning optical encoder wheels (one horizontal, one vertical -- duh).

I am wondering if anybody has ANY idea about the circuitry that is used to translate the patterns? I can't find any info on the chip that is on the board, so I'm not even sure if it's a microcontroller, or some specific IC meant for the job. (Or, if the logic is handled on a PC motherboard!)

Any ideas? I can't seem to find good info anywhere.

The reason being is I want to use that physical mechanism that is in place, intercept those signals on a microcontroler, interleave some other custom data, THEN send a custom message along to the PC.

EDIT: May have asked too soon, the last sentence of this page explains the protocol a bit. But I'm still unsure what chip is in there.
  Reply With Quote
Old 24th November 2006, 02:14 AM   #2
dangus is offline dangus  Canada
diyAudio Member
 
Join Date: May 2004
Location: Vancouver Island
It could be a microcontroller; there's an app note at Microchip that explains how to make a serial mouse with a PIC16C54, complete with source code.
http://ww1.microchip.com/downloads/e...tes/00519c.pdf

About the PS/2 mouse protocol:
http://www.computer-engineering.org/ps2mouse/

PIC16F84 PS/2 mouse design:
http://web.archive.org/web/200511040.../ps2mouse.html
  Reply With Quote
Old 24th November 2006, 03:03 AM   #3
diyAudio Member
 
Join Date: Feb 2003
Location: USA
Send a message via ICQ to discman1028 Send a message via AIM to discman1028
Thanks, these are good! Any other comments/links are welcome.
  Reply With Quote
Old 24th November 2006, 03:17 AM   #4
SY is offline SY  United States
diyAudio Moderator
 
SY's Avatar
 
Join Date: Oct 2002
Location: Chicagoland
Blog Entries: 1
It's definitely a microcontroller. The interesting part is that the wheels usually contain two sources/sensors in quadrature. This enables the controller to tell the difference between motion in opposite directions (e.g., up versus down).
__________________
You might be screaming "No, no, no" and all they hear is "Who wants cake?" Let me tell you something: They all do. They all want cake.- Wilford Brimley
  Reply With Quote
Old 13th December 2006, 08:39 PM   #5
diyAudio Member
 
Join Date: Jan 2006
Location: Fairmount, GA
SY,

Very interesting. I always wondered about that!
__________________
Poor stereo mix? Switch to mono! Perfect.
  Reply With Quote
Old 13th December 2006, 09:20 PM   #6
diyAudio Member
 
I_Forgot's Avatar
 
Join Date: Jan 2005
Location: Phoenix, Az.
The encoder has two lights and detectors that work in quadrature. The output is a 2 bit gray code. Gray code means only one bit changes from one state to the next. There are 4 possible output states, in clockwise rotation order they are
00, 01, 11, 10 ..... repeating forever as you turn clockwise.

When you turn counterclockwise, the order is reversed:
00, 10, 11, 01 ..... repeating forever as you turn counterclockwise.

A microcontroller can determine the direction by comparing the "new" state of the encoder to the previous state. For example, if the new state is 11 and the previous state was 10, the encoder has been rotated CCW. Look at the CW - there is never a condition where CW rotation gives a 10 -> 11 sequence.

In something like a PIC microcontroller, a subroutine containing a lookup table is typically used to quickly and easily determine the direction of rotation. You fill the lower nibble of a word with the previous and new states of the encoder and add that value to the program counter. When the program counter changes to the new address, it encounters a RETLW instruction ("return with literal in W"). A typical example would be that you would want to increment a counter if the encoder is rotating CW and decrement it if the encoder is rotating CCW. The table will be filled with +1 and -1 values in the retlw statements that make up the table and correspond to the different states changes the encoder makes as it rotates.

Note that there are never any state changes in which both bits of the encoder output are changed. For example, the encoder never switches from 00 to 11. The table entries for this condition will be retlw 0x00. A value of zero will be returned so the counter value will not be affected. In theory these states can never occur, but noise or switch contact bouncing can make strange things happen so these states must be accounted for in the look-up table.

Here is a table I use in project of mine:

;*******************************************
; This table returns +1 or -1 to indicate the direction of encoder
; rotation. Encoder state is stored in lower nibble of ENC_TEMP
; Table valid for 7 6 5 4 3 2 1 0
; 0 0 0 0 old B old A new B new A
;where A, B are encoder pins

ENC_TABLE CODE 0x005

enc_table
movf ENC_TMP,W
addwf PCL,F ; Indirect jump
retlw H'00' ; 00 -> 00 do nothing
retlw H'01' ; 01 -> 00 increment
retlw H'FF' ; 10 -> 00 decrement
retlw H'00' ; 11 -> 00 do nothing
retlw H'FF' ; 00 -> 01 decrement
retlw H'00' ; 01 -> 01 do nothing
retlw H'00' ; 10 -> 01 do nothing
retlw H'01' ; 11 -> 01 increment
retlw H'01' ; 00 -> 10 increment
retlw H'00' ; 01 -> 10 do nothing
retlw H'00' ; 10 -> 10 do nothing
retlw H'FF' ; 11 -> 10 decrement
retlw H'00' ; 00 -> 11 do nothing
retlw H'FF' ; 01 -> 11 decrement
retlw H'01' ; 10 -> 11 increment
retlw H'00' ; 11 -> 11 do nothing

After returning from the table you set the old state of the encoder equal to the new state and it is ready for the next encoder turn.

I_F
  Reply With Quote

Reply


Hide this!Advertise here!
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Murray the K's Disco on Wheels diamondzzzz Introductions 3 25th June 2012 12:33 AM
AKAI Digital audio parts- pcm61P/encoders/boards imix500 Swap Meet 10 31st December 2011 10:58 PM
some sort of turntable-device, with wheels... Rodeodave Instruments and Amps 3 5th February 2010 12:17 AM
Boombox on wheels needs an experts trouble shooting skills! jestah Class D 12 17th July 2009 12:53 AM
Pots n' Encoders meta Parts 3 13th December 2002 02:39 PM


New To Site? Need Help?

All times are GMT. The time now is 05:27 AM.


vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2014 DragonByte Technologies Ltd.
Copyright 1999-2014 diyAudio

Content Relevant URLs by vBSEO 3.3.2