ECE351 Digital Systems Design, Spring 2016 Lab 4

advertisement
ECE351 Digital Systems Design, Spring 2016
Lab 4
PS/2 Mouse Interface for the Basys2 Board
PS/2 refers to a standard way of connecting devices like keyboard and mouse to a host. In
addition to lines for data and clk, a PS/2 port has gnd and power +V supplied by the host – about
+5V and 100mA to power the mouse’s on-board logic. Figure 1(a) shows the generic PS/2
connector and the hardwired pins on the Basys2 board.
(a)
(b)
Figure 1: (a) PS/2 connections, Basys2 hardwired pins. (b) PS/2 signal timing specs.
PS/2 is a serial interface. The host must be running an interface program for a mouse connected to
a PS/2 port. A PS/2 interface is actually bidirectional because the host must transmit to the mouse
at least to initialize at power-up – that’s why the ps2_clock on pin B1 and ps2_data on pin C3 are
shown as two-way in Figure 1(a) and must be declared as inout ports in VHDL.
Many designers of host PS/2 interfaces organize the implementation as one or more FSMs, for
example, the initialization sequence of Digilent’s Mouse Reference Component steps through
states of a FSM.
The mouse has 4 operational modes controlled by its host:
1. Reset, to reset mouse’s on-board logic and always the start-up state for power-on
initialization.
2. Stream, the default operating state in which the mouse sends a movement data packet
whenever there is movement or button activity.
3. Remote, in which the mouse sends a movement packet only when polled by the host.
4. Wrap, a diagnostic mode in which the mouse simply echoes back each packet the host
sends it.
In stream mode, an enabled mouse activated by button-press or motion sends a packet of data
words to the host. Each packet consists of three 11-bit words or frames sent sequentially – serial
transmission of bits to the host. We will refer to these bits as 0-32 left to right from first to last
transmitted:
•
•
•
Bits 0, 11, 22 are the 0 start bits for frames
Bits 10, 21, 32 are the 1 stop bits for frames
Bits 9, 20, 31 are the odd parity bits for frames
The first frame is mouse status info, the second frame is X-axis movement, and the third frame is
Y-axis movement. Note that the numerical value of sign-and-byte sent by the mouse is in the
range of +/-25510. The number is the delta or change relative to the previous value, that is, the
offset relative to the position when the previous packet was sent, in units of the resolution. For
instance, the X-value at resolution 8 denotes 80mm UP and -63 denotes 504mm DOWN.
Figure 1(b) shows some technical timing constraints for a PS/2 mouse including setup and
holding times. The clk sent by the mouse is at logic 1 until a transmission starts. The first 1-to-0
(negative- or falling-edge) clock transition gets the host’s attention at the start of transmission.
The mouse sends clock edges until all three data frames have been transmitted, then it holds the
clock at 1 until the next transmission. The host uses the negative edges of clk for timing.
Lab tasks: Do a multi-phase implementation with these modifications of the Digilent Mouse
Reference Component 1 - or if you wish, of course, you can write the complete code from scratch.
Document your changes, new signals, etc, carefully in the Digilent VHDL code – there are
already numerous inter- and intra-component signals and FSM states.
Phase 1 (40%):
•
•
•
•
•
The position vectors xpos, ypos, zpos are multi-bit outputs from the structural
MouseRefComp not actually sent elsewhere in this lab because you will use the on-board
7-segment displays. You can suppress these vectors as outputs in the MouseRefComp
port list.
One of the tasks of the resolution_mouse_informer is to set maximum values for xpos,
ypos, zpos as upper limits in the mouse_controller. Be sure that the controller does not
get these upper limits set to 0; otherwise, the position vectors won’t change in response to
a movement packet from the mouse.
Use debounced BTN0 for reset. Use SW0 for RESOLUTION and BTN1 for SWITCH.
For the first phase info about a movement packet from the mouse in stream mode postinitialization, use LD2-LD1-LD0 respectively to show when LEFT-MIDDLE-RIGHT
mouse button is pressed and use LD4-LD3 respectively for the sign of X-Y movement in
the movement packet.
Also verify that RST, SWITCH, and RESOLUTION work as required.
Phase 2: When your phase 1 is complete with no VHDL syntax errors or XST synthesis
complaints, add more X-movement info (30%):
•
The current X position is a 10-bit vector xpos. Use the 7-segment displays to show the
current X position in HEX. This vector from the controlled changes on reset or on mouse
movement in X direction.
Phase 3: Get to know the details of the 33-bit movement packets. Select some interesting info in
a packet other than Y-movement, devise an LED or 7-segment display for that info, and
implement (30%).
1
https://reference.digilentinc.com/_media/basys2:mouserefcomp.zip
Download