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:

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.

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:

  1. Open the Programmer, by choosing MAX+plus II | Programmer, or by clicking on the shortcut button, which looks like this:
     
  2. Switch on JTAG | Multi-Device JTAG chain. Turning it on may open a dialogue box, otherwise open it yourself using JTAG | Multi-Device JTAG chain setup.
     
  3. The white box in the centre of this dialogue box should be empty; if not, click on Delete All.
     
  4. Now click on Select Programming File and find mousetest.sof.
     
  5. Back in the Multi-Device JTAG chain setup dialogue box, click on Add to add the programming file to the list.
     
  6. 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.
     
  7. 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.
     
  8. Once you have successfully run a test don't forget to switch off JTAG | Multi-Device JTAG chain 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

  1. What is the resolution of the mouse?
  2. Are the overflow flags ever set?
  3. (Optional) Alter your code so that you can measure how frequently the mouse sends its 3-byte packets.

Ticking Criteria

  1. Your verilog code needs to be cleanly formatted and commented.
  2. You must give a live demonstration of your solution.
  3. 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.
  4. You must make good use of modular decomposition to ensure that each module is not too complex.
  5. 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).
  6. The following header must be added to all code submitted:
    //////////////////////////////////////////////////////////////////////////////
    // ECAD+Arch Workshop 3
    //
    // Your name
    // Your college
    // date
    //////////////////////////////////////////////////////////////////////////////