Labs

Lab 5

Lab 5: Mouse-based Dexterity Measurement Game


Starts: Week 11(Oct 29 - Nov 2)
Demo Due: EXTENDED Week 15 (Nov 26- Nov 30)
Code and Report Due: EXTENDED Nov 30, 11:59 PM
Points: 150

Announcements

Nov 15: There were some errors in the supplied code for the LCD interface and PS2 mouse interface that will lead to challenges in successfully implementing your design on the FPGA board. In addition, the lab write had a few errors regarding which clock was used as the input to the HLSM. A new set of files has been posted to the lab writeup. All provided files start with "Lab5_". Please ensure you are using the correct files. Please note that you will need to use your ps2_FSM implementation from Lab 3.

The lab description has been revised to note two important changes:

  1. The clock used for the HLSM is a 200kHz clock, not the 50 MHz clock.
  2. The top module incorrectly omitted a a separate reset signal for the clock divider. This caused the reset to not function correctly. This has been corrected in the update files, and a UCF file has been provided.

Thus, Lab 5 has been extended to the week of Nov 26 (Nov 26 - Nov 30) and will replace the originally scheduled lab practical. The lab practical grading will be based upon synthesizing your design to the FPGA board. Partial credit will be assigned based upon the components of your design that are working. A rubric will be posted in the near future.

Pre-Lab Assignment

Create a high-level state machine (HLSM) diagram for the Mouse-based Dexterity Game design described below. Be sure to use the same inputs and outputs as specified in the following description.(10 points)

Code-Check Requirement

An initial implementation for all Verilog modules and testbenches required for this lab assignment must be shown to your TA at the beginning of your scheduled lab section in Week 12 (Nov 5 - Nov 9). (10 points)

Lab Report

A lab report is required for this lab assignment using format of the provided template, ECE 274 Lab Report Template. Only one lab report is required for each group. In addition to following the specified lab report template, your lab report should include figures for your final high-level state machine diagram and simulation waveforms demonstrating correct functionality of the Mouse-based Dexterity Game component. The lab report should be written as a technical document thoroughly describing your design (and NOT as a report describing the steps you followed to implement the design). The lab report must be submitted via D2L as a Word or PDF file along with your code submission. (10 points)

Files

http://www2.engr.arizona.edu/~ece274/uploads/Labs/Lab5_Mousebased_Dexterity_Game.v http://www2.engr.arizona.edu/~ece274/uploads/Labs/Lab5_Absolute_Calc.v http://www2.engr.arizona.edu/~ece274/uploads/Labs/Lab5_Bin2BCD.v http://www2.engr.arizona.edu/~ece274/uploads/Labs/Lab5_Button_Pulse.v http://www2.engr.arizona.edu/~ece274/uploads/Labs/Lab5_ClkDiv200KHz.v http://www2.engr.arizona.edu/~ece274/uploads/Labs/Lab5_Iterator.v http://www2.engr.arizona.edu/~ece274/uploads/Labs/Lab5_LCD_Interface.v http://www2.engr.arizona.edu/~ece274/uploads/Labs/Lab5_Mouse_Game_Top.v http://www2.engr.arizona.edu/~ece274/uploads/Labs/Lab5_ps2_FSM.v http://www2.engr.arizona.edu/~ece274/uploads/Labs/Lab5_ps2_Interface.v http://www2.engr.arizona.edu/~ece274/uploads/Labs/Lab5_ps2_Output.v http://www2.engr.arizona.edu/~ece274/uploads/Labs/Lab5_ps2_Shifter.v http://www2.engr.arizona.edu/~ece274/uploads/Labs/Lab5_ps2_Timer.v http://www2.engr.arizona.edu/~ece274/uploads/Labs/Lab5_ps2_Writer.v http://www2.engr.arizona.edu/~ece274/uploads/Labs/Lab5.ucf

Note: You will need to use all of the modules provided. You should not change the interfaces of any of the components provided (nor should you add any extra components).

Lab Overview

In this lab, you will be designing a mouse-based dexterity game that determines a user’s dexterity by measuring how accurately a user can return the mouse to its original position after initially displacing it in any general direction. On reset, the dexterity game will initially display an introduction message “Welcome!” on the LCD of the Spartan-3E FPGA board. When the left mouse button is pressed, the dexterity game will display a “Click to Start!” message before initiating the game. Upon pressing the left mouse button once again, a “Move Mouse!” message will be displayed on the LCD prompting the user to move the mouse from its initial location – let’s call it location A – to any other location – location B – and indicating his/her selection by pressing the left mouse button. If location B is within 200 MRUs (mouse resolution units) of the original location, the dexterity game will display a “Not far enough!” message on the LCD indicating that the user should move the mouse a longer distance. Otherwise, the dexterity game will display a “Return Mouse!” message on the LCD and the user will have 2 seconds to return the mouse to its original position – location A – as accurately as possible and select that location with another press of the left mouse button. If the user successfully returns the mouse to within 200 MRUs of the original location, the dexterity game will display the distance between the original location, A, and the user’s guess. The distance in MRUs is calculated as the Manhattan distance that is equal to the sum of the distance in the X and Y directions. In other words D = X + Y.

If the user returns the mouse to a location further than 200 MRUs of the original location, then the game is lost and the message “Too far!” will be displayed. Alternatively, if the user takes longer than 2 seconds to return the mouse to its original location and press the left mouse button, then the dexterity game will display a “Too slow!” message. The dexterity game will continue displaying the “Not far enough!” message, the successful distance measurement message, the “Too far!” message, or the “Too slow!” message until the user pushes either the reset or right mouse buttons to restart the game.

The following figures provide a top level view of the various components of the Mouse-based Dexterity Game you will be designing and provide an overview of the connections that will be used to implement your design on the Spartan-3E FPGA board. You will be responsible for designed the shaded components; the others have been provided for you.

Note: The following figure shows an incorrect connection for the clock signals and is missing the DivRst input. Please consult the provided top module for the correct connections.

Mouse-based Dexterity Game

The Mouse-based Dexterity Game component provides the main functionality of the overall design and will interface with the PS2 mouse and LCD components. In this lab, you will create an RTL design of the above specified dexterity game as a high-level sate machine (HLSM). The Mouse-based Dexterity Game component has 7 inputs – Clk, Rst, X_Value, Y_Value, Left_Button, Right_Button, and XY_Value_Update – and 8 outputs – LCD_Update, LCD_Msg_Slow, LCD_Msg_Short, LCD_Msg_Far, LCD_Msg_Move, LCD_Msg_Ret, LCD_Msg_Strt, and Distance.

The PS2_Clk_Div signal is 200 kHz signal should be used to measure elapsed time. The Rst input is used as the global reset signal for you HLSM.

As the mouse is moved, it periodically updates the board with information regarding its position. When the XY_Value_Update input becomes 1, an update has been received and the mouse’s new location information is available via the 9-bit inputs X_Value and Y_Value. Note, however, that the X_Value and Y_Value inputs represent the distance moved – in MRUs – since the last update in the x and y directions respectively. Additionally, the X_Value and Y_Value inputs are signed numbers using a two’s complement' representation.

The outputs Distance, LCD_Update, LCD_Msg_Slow, LCD_Msg_Short, LCD_Msg_Far, LCD_Msg_Move, LCD_Msg_Ret, and LCD_Msg_Strt are used to interface with the provided LCD Interface component. The Distance output is a 14-bit output that corresponds to the distance in MRUs between the original location, A, and the user’s final guess. The LCD_Msg_Strt output is a 1-bit output used to display the “Click to Start!” message on the LCD. The LCD_Msg_Move output is a 1-bit output used to display the “Move Mouse!” message on the LCD. The LCD_Msg_Short output is a 1-bit output indicating the user did not move the mouse far enough (at least 200 MRUs) when starting the game. The LCD_Msg_Ret output is a 1-bit output used to display the “Return Mouse!” message on the LCD in order prompt the user to return the mouse to its original position. The LCD_Msg_Far output is a 1-bit output used to display the “Too far!” message on the LCD when the user exceeds the mouse’s original location by more than 200 MRUs. Finally, the LCD_Update output and LCD_Ack input are used for communicating with the LCD component to specify when and how the LCD display should be updated.

Because the LCDDisplay and Mouse-based Dexterity Game components operate using two different clock signals, in order to communicate between the two components, your design will have to implement a simple handshaking scheme. As illustrated in the following timing diagram, to update the LCD, the Mouse-based Dexterity Game must first assert the LCD_Update output and continue to assert this output until the LCD_Ack input is asserted by the LCDDisplay component. Upon detecting that the LCD_Ack input is high, the Mouse-based Dexterity Game must de-assert the LCD_Update signal and wait for the LCD_Ack input to be de-asserted as well. This handshaking sequence is required for all updates to the LCDDisplay. For example, to display a measured distance on the LCD, the Mouse-based Dexterity Game should assign the measured distance to the Distance output, assign 0 to LCD_Msg_Slow, LCD_Msg_Short, LCD_Msg_Far, LCD_Msg_Move, LCD_Msg_Ret, and LCD_Msg_Strt, assert the LCD_Update output, and complete the handshaking as described above. Note that the values assigned to Distance, LCD_Msg_Slow, LCD_Msg_Short, LCD_Msg_Far, LCD_Msg_Move, LCD_Msg_Ret, and LCD_Msg_Strt must remain constant as long as LCD_Update is asserted. As another example, to display the slow message on the LCD, the Mouse-based Dexterity Game should assign 1 to the LCD_Msg_Slow output, assign 0 to the other outputs, assert the LCD_Update output, and complete the handshaking as described above.

Lab Procedure

  1. Behaviorally design the Mouse-based Dexterity Game component (90 points):
    • Behaviorally design the Mouse-based Dexterity Game as a high-level state machine using either a one-procedure or two-procedure implementation. Note: If you choose to utilize a two-procedure implementation for your high-level state machine, be sure to model all registers within your design using separate current and next reg variables. The following is the breakdown in points awarded for various elements of the design. (75 points)
      • Measuring distance between the initial mouse location and the final guess. (25 points)
      • Interfacing with LCD to display messages. (20 points)
      • Detecting not far enough condition. (10 points)
      • Detecting slow condition. (10 points)
      • Detecting far condition. (10 points)
    • Create a testbench that tests your Mouse-based Dexterity Game design for correct functionality. Your testbench should check for correct distance measurement, correct slow detection, correct detection of the too far condition, and correct detection of the not far enough condition. Note: As you are not yet interfacing with the LCDDisplay component, you will need to control the LCD_Ack signal from within your testbench to provide and acknowledge in response to the LCD_Update signal. (15 points)
  2. Using the provided modules synthesize, download, and test your overall Mouse-based Dexterity Game design on the Spartan-3E FPGA board. Note: As most information is provided through the LCD for this assignment, you must minimally be able to interface with the LCD and display a message other than introduction message “Welcome” on the LCD. (30 points)

\\