ECAD & Architecture Workshop Three
Mouse Interface
workshop home |
workshops: 1 |
2 |
3 |
4 |
5 |
6
Introduction
You may have noticed a few of the more interesting features on the
Altera board. These include a VGA connector, and a PS/2 mouse or
keyboard connector. We are not going to play with the VGA port in this
workshop - it's definitely one of the more amusing ways of blowing up
a monitor. However, the mouse port looks sufficiently fun, and
relatively safe.
The objective of this practical is to interface correctly with a
PS/2 serial mouse connected to the PS/2 connector on the Altera
board. You should be able to output to the LEDs the current x position
of the mouse pointer, and also the first two mouse buttons should be
represented on the decimal point LEDs.
Modules
There are several useful modules that you can use for this practical. These are:
- HexToLEDs.v, which you should be
familiar with.
- ps2_mouse.v,
which acts as a simple clocked serial input. It also contains some
code which sends a byte out to the mouse when you download your
program.This stream of pulses is required to initialise the mouse and
tell it to send data normally. The signature is:
module ps2_mouse(clock, mdata, mclock, data, receive_key);
- input clock should be provided
with the normal 25.175MHz clock
- inout mdata should be connected to
the mouse data line
- inout mclock should be connected
to the mouse clock data line
- output [7:0] data contains the
latest byte to be read from the serial line
- output receive_key changes state
when a new byte is received on the serial line
Please note that the inout statement above
are not input statements! If you get this
wrong it frequently crashes the MAX+plus II (sigh!).
Mouse data format
The mouse sends data to the "computer" in three bytes along the serial port.
- Byte 1 is the status byte, and has the structure:
MSB 7 | 6 | 5 | 4 | 3 | 2 | 1 | LSB 0 |
Y Overflow | X Overflow | Y Sign | X Sign | 1 | Middle Button | Right Button | Left Button |
- The sign and overflow bits in Byte 1 may be ignored for the
purpose of this practical - but you'll need the button bits, and the 1
bit will be necessary to help make sure that your state machine is
synchronised with the mouse.
- Byte 2 is the X change value. This is a signed eight-bit value
representing the distance the mouse has moved since the last data
packet.
- Byte 3 is the Y change value. This is a signed eight-bit value
representing the distance the mouse has moved since the last data
packet.
The project code
The core of your program should be a state machine with three
states - one state for each byte input. The state machine should
change state each time a new byte is received. Each state will deal
with decoding the corresponding input byte. Note that the first byte
has a valid bit and you should remain in the same state until this
valid bit is set.
You will need to create your own .acf
file. To last week's you will need to add mclk on pin 30, and mdata
on pin 31.
Test your mouse hardware
To test your mouse hardware download mousetest.zip which contains mousetest.sof. This is the file normally produced by a successful compilation which the Programmer downloads to the board. To tell the Programmer to download mousetest.sof rather than the project you are working on, follow these steps:
- Open the Programmer, by choosing
, or by clicking
on the shortcut button, which looks like this:
- Switch on
. Turning it on may open a dialogue box, otherwise open it yourself using .
- The white box in the centre of this dialogue box should be empty;
if not, click on Delete All.
- Now click on Select Programming File and find
mousetest.sof.
- Back in the
Multi-Device JTAG chain setup
dialogue box, click on Add to add the programming file to the
list.
- Click on Detect JTAG chain info. If the
Altera board is plugged in, and you have set up the dialogue box
correctly, you will get a message telling you so.
- Close the dialogue box with OK, and click on
Configure. This should download the data to the board, and
the test will run. This test code indicates the direction that
the mouse is traveling in on the LEDs. The decimal points on the LEDs
indicate left and right mouse button presses. If your mouse doesn't appear to work then make sure that the mouse
connector is firmly inserted and then download the test code again to
reboot the mouse. If that doesn't fix it then please report the
problem.
- Once you have successfully run a test don't forget to switch off before continuing work on your project.
Tip of the day
You may find that the old compilations from previous workshops have
consumed a lot of disk space with temporary files. It is safe to
delete the files which you have not created (remember to keep your
.v and .acf
files!).
Questions
- What is the resolution of the mouse?
- Are the overflow flags ever set?
- (Optional) Alter your code so that you can measure how frequently
the mouse sends its 3-byte packets.
Ticking Criteria
- Your verilog code needs to be cleanly formatted and commented.
- You must give a live demonstration of your solution.
- The verilog code must be strictly synchronous with all clocks
coming from one of the two clock distribution networks. Derived
clocks which are distributed over programmable wiring are dangerous
because clock skew can vary widly.
- You must make good use of modular decomposition to ensure that
each module is not too complex.
- Answers to the questions for the lab must be added to the end of
your code. You will need to add some verilog code in order to answer
the second question (i.e. to detect if the overflow flags are ever set).
- The following header must be added to all code
submitted:
//////////////////////////////////////////////////////////////////////////////
// ECAD+Arch Workshop 3
//
// Your name
// Your college
// date
//////////////////////////////////////////////////////////////////////////////