CMOS Gate Array Design Exercise 2001

Design Specification


Shaft Encoder Interface


Introduction

This year's exercise is to design a circuit to interpret the signals from one axis of a mouse shaft encoder. The circuit will be implemented on a CMOS gate array chip fabricated in the department's own clean room facilities. Two such circuits (along with some glue logic) will be used to construct a complete PS/2 interface for an old style "Atari mouse". The exercise is completed with a demonstration of the "Atari mouse" controlling a Windows 2000 PC via the constructed interface.

Mice and Shaft Encoders

Most mouse computer peripherals use a rolling ball which drives two orthogonally mounted shaft encoders, one for each axis X and Y. The figure below shows this configuration:

Construction of a Mouse

Construction of a Mouse

Looking in greater detail at a single shaft encoder, we find a rotating disc with holes in it, separating a pair of LEDs from a pair of phototransistors. The LEDs are always on, resulting in pulses of light to the phototransistors as the disc rotates. The figure below shows the mounting position for the phototransistors just above the axis of the disk. In this configuration the signals from the two phototransistors are out of phase such that the signal from A leads the signal from B by 90° as the ball rolls forward and the signal from B leads the signal from A by 90° as the ball rolls backwards.

mouse 1D

Note that we have a 2 bit Gray code which avoids problems associated with A and B changing at the same time.

In a modern mouse, the signals from the shaft encoder are interpreted causing a counter to increment or decrement as the ball rolls. Whenever possible the count value is transferred to the computer over a serial link (RS232, PS/2 or USB).

Although it is possible to modify the count value every time an edge is detected on either the A or B signal, a much simpler implementation is reached if the count value is only changed when an edge is detected on the A signal. The rest of this document assumes that you employ this strategy.

PS/2 Mouse Protocol

All PS/2 mice and keyboards use the same underlying protocol for device to host communication; data is encoded in 11 bit frames:

The device also provides a clock signal for the duration of the transmission, this is used to synchronize the data transfer. The pattern of clock and data bits is shown below:

PS/2 protocol

For a simple two or three button mouse, three bytes will be sent to the host to code movement and button positions.

Bit 7Bit 6Bit 5Bit 4 Bit 3Bit 2Bit 1Bit 0
Byte 1Y overflowX overflow Y sign bitX sign bit Always 1 Middle BtnRight BtnLeft Btn
Byte 2X Movement
Byte 3Y Movement

notes

PS/2 Mouse Interface

The Atari mouse at the centre of this exercise contains amplifiers to give CMOS compatible 0v and 5v outputs from the phototransistors but doesn't perform any further signal processing, leaving it up to the computer to interpret the signals from the two shaft encoders.

Your task is to build a complete PS/2 mouse interface such that the PC believes it has a standard PS/2 mouse attached to it. A block diagram for the PS/2 Mouse Interface is shown below:

mouse block

A more detailed system diagram is shown below.

mouse system

note that various of the shift register inputs are hard-wired

Shaft Encoder Interface

The shaft encoder interface has two inputs, A and B, from the shaft encoder and produces a multibit COUNT value indicating the number of pulses counted in a particular direction.

Since the mouse has two buttons it is convenient for each shaft encoder interface to process the signals from one of the buttons as well as from one of the shaft encoders. The unprocessed button signal is nBUTTin while the processed signal is BUTTout.

In communication with the Control unit the interface has two request outputs. MOVEreq indicates that there have been one or more changes on the A input giving a non-zero COUNT value which is waiting for transfer to the Shift Register while BUTTreq indicates that there has been a change on the BUTTout value which is waiting for transfer to the Shift Register.

An acknowledge signal, ACK, from the Control unit, indicates that transfer to the Shift Register is taking place and should cause the COUNT value to be set to zero and the request outputs to go inactive unless it coincides with further changes on the A and nBUTTin inputs.

Testability

In light of the complexity of this year's design it has been decided to make a suggestion on the initial splitting of your circuit into separately testable blocks. All submitted designs should exhibit more testability than described here (more circuit breaks to improve observability and controllability and more test outputs to improve observability only).

The suggested split is into three blocks. With the exception of common CLOCK and nRESET inputs, the blocks are independent.

During the testing stage, the separate blocks will be reconnected to give the originally specified functionality. Due to the careful choice of signal names, this split circuit will simulate as if it was reconnected thereby assisting with design verification.

Detailed Specification

Your design for the shaft encoder interface must satisfy the following specification:

Sample Waveform Diagram

In order to clarify the specification, the following diagram illustrates the behaviour of all of signals within the circuit, given a specific set of stimuli from the Atari mouse and the Control unit:

wave

In order for your circuit to meet the specification it is not necessary for it to follow exactly the timing diagram above, this diagram is for a specific implementation.

Nor is it sufficient that your circuit can exactly match the timing diagram, your design must function correctly for all sets of input stimuli.


Iain McNally

24-9-2001