Mice are often overlooked as motion or position encoders. Mechanical mice can be connected directly to a shaft and relay data to a uC via serial communication without requiring any processing of encoder data. Optical mice can sense motion without mechanical conneciton and can do so at a distance given an optical refit, allowing them to focus past their bottom surface.
The old PS2 mice are valuable because they don't require a complex USB stack to work. They send (after being activated) a simple series of data bytes over standard logic level, bidirectional (open collector) wires. Power is 4.5 to 5.5 volts at up to 275mA. Don't hot plug.
note: much of this shamlessly copied from
The pinouts for each connector are shown below:
|5-pin DIN (AT/XT):
1 - Clock
2 - Data
3 - Not Implemented
4 - Ground
5 - Vcc (+5V)
|6-pin Mini-DIN (PS/2):
1 - Data
2 - Not Implemented
3 - Ground
4 - Vcc (+5V)
5 - Clock
6 - Not Implemented
A - Not Implemented
B - Data
C - Ground
D - Clock
E - Vcc (+5V)
F - Not Implemented
Summary: Bus States
Data = high, Clock = high: Idle state.
Data = high, Clock = low: Communication Inhibited.
Clock = low for 100mS, Data = low, Clock = high: Host Request-to-Send
All data is transmitted one byte at a time and each byte is sent in a frame consisting of 11-12 bits. These bits are:
PS2 -> Host. PS2 generates 10 - 16.7 kHz clock, host reads data on the falling edge.
Host -> PS2, after Host Request-to-Send, PS2 generates Clock signals and clocks in eight data bits and one stop bit. The host changes the Data line only when the Clock is low, and data is read by the device when Clock rises. After the stop bit is received, the device will acknowledge the received byte by bringing the Data line low and generating one last clock pulse. If the host does not release the Data line after the 11th clock pulse, the device will continue to generate clock pulses until the the Data line is released (the device will then generate an error.) The host may abort transmission at time before the 11th clock pulse (acknowledge bit) by holding Clock low for at least 100 microseconds.
The standard PS/2 mouse sends movement/button information to the host using the following 3-byte packet:
|Bit 7||Bit 6||Bit 5||Bit 4||Bit 3||Bit 2||Bit 1||Bit 0|
|Byte 1||Y overflow||X overflow||Y sign bit||X sign bit||Always 1||Middle Btn||Right Btn||Left Btn|
|Byte 2||X movement|
|Byte 3||Y movement|
The movement values are 9-bit 2's complement integers, where the most significant bit appears as a "sign" bit in byte 1 of the movement data packet. Their value represents the mouse's offset relative to its position when the previous packet was sent, in units determined by the current resolution. The range of values that can be expressed is -255 to +255. If this range is exceeded, the appropriate overflow bit is set.
Following is the set of commands accepted by the standard PS/2 mouse. If the mouse is in stream mode, the host should disable data reporting (command 0xF5) before sending any other commands.
|Bit 7||Bit 6||Bit 5||Bit 4||Bit 3||Bit 2||Bit 1||Bit 0|
|Byte 1||Always 0||Mode||Enable||Scaling||Always 0||Left Btn||Middle Btn||Right Btn|
|Byte 3||Sample Rate|
Right, Middle, Left Btn = 1 if button pressed; 0 if button is not pressed.
Scaling = 1 if scaling is 2:1; 0 if scaling is 1:1 (see commands 0xE7 and 0xE6).
Enable = 1 if data reporting is enabled; 0 if data reporting is disabled (see commands 0xF5 and 0xF4).
Mode = 1 if remote mode is enabled; 0 if stream mode is enabled (see commands 0xF0 and 0xEA).
|Byte Read from Host||Resolution|
The only commands the standard PS/2 mouse will send to the host are "Resend" (FEh) and "Error" (FCh).
The PS/2 mouse is normally detected/initialized only when the computer is booting up. That is, the mouse is not hot-pluggable and you must restart your computer whenever you add/remove a PS/2 mouse. Adding/removing the PS/2 mouse while the computer is running may physically damage some motherboards.
The initial detection of the PS/2 mouse occurrs during POST. If a mouse is detected, the BIOS will allow the operating system to configure/enable the mouse. Otherwise, it will inhibit communication on the mouse's bus. If you boot the computer with a mouse attached, then detach/reattach the mouse while in Windows, the OS may be able to detect the mouse was reattached. Testing this on Win98 SE, it seems to work about 50% of the time.
The following is the communication between my computer (running Win98 SE) and a standard PS/2 mouse during the boot process. It is fairly typical of how a PS/2 mouse is initialized and if you want to emulate a PS/2 mouse it must (at minimum) be able to support the following sequence of commands...
from J.E. Davis posted by Peter Tiang
Serial UART: 1200 baud, data=8,start=1,parity=none Mouse Protocol of Transmission bit: 7 6 5 4 3 2 1 0 byte 1 (sync) 1 0 0 0 0 L M R (0=depressed button) byte 2 (dX) x7 x6 x5 x4 x3 x2 x1 x0 (bit 7 -> 0=pos,1=neg) byte 3 (dY) y7 y6 y5 y4 y3 y2 y1 y0 byte 4 (dX') x7 x6 x5 x4 x3 x2 x1 x0 byte 5 (dY') y7 y6 y5 y4 y3 y2 y1 y0 Notes: - all bytes are two's complement binary - dX, dY = relative moves after last transmission - dX',dY' = relative moves since dX, dY were transmitted
Serial UART: 1200 baud, data=7,stop=1,parity=none Mouse Protocol of Transmission (normal mode) bit: 7 6 5 4 3 2 1 0 byte 1 (sync) 0 1 L R y7 y6 x7 x6 (1=depressed button) byte 2 (dX) 0 0 x5 x4 x3 x2 x1 x0 (MSB-> 0=pos,1=neg) byte 3 (dY) 0 0 y5 y4 y3 y2 y1 y0 Notes: - all moves bytes are two's complement binary (you must collect all bits together)
Mechanical mice use a Quadrature Encoder position sensor attached to a shaft that rubs against the ball.
Jinxs' 16F84 4 button directional controller pluges in place of an MS Mouse
|file: /Techref/io/mouses.htm, 17KB, , updated: 2015/12/20 16:00, local time: 2022/5/27 14:55,
|©2022 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?|
<A HREF="http://www.piclist.com/Techref/io/mouses.htm"> Mouses</A>
|Did you find what you needed?|
PICList 2022 contributors:
o List host: MIT, Site host massmind.org, Top posters @20220527
* Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.
Welcome to www.piclist.com!