How to transfer keyboard characters from a FPGA to a computer via a PS2 port
Sometimes it may be convenient to output data to a text file on a computer. That way one is more flexible on the way he/she can display certain outputs. Most people tend to use the little HEX display on the UP1 board to display characters of the alphabet. However with the option of using a PS2 driver, one can display the characters onto a computer instead, using any text editor. This option also allows one to save the data output in any text editor file. The UP1 board has a PS2 port, which allows one to hook up the board to any standard PS2 port on a PC. My goal was to develop a method where by a user can input a simple binary code, and press an enable button to transmit letters of the alphabet to any computer via a PS2 port. For example, if the user wants to send the character "A" to the computer, then he/she will input the binary code "11110" and assert the enable signal which is active low. The PS2 driver will then output the character "A" on the computer through any text editor.
Unfortunately, I was not able to get the system working completely, and there are glitches with some of the code. At present, only a few characters can be output to the computer, such as "A", "B", "D", and a few others. Therefore, if you ever get the chance to venture into my code, perhaps you could fix the bug, and use the PS2 driver, for your purposes.
Here are some excellent links that explain how the PS2 protocol works. I tried to develop my code using the information provided in these links:
AT Keyboard Interfacing:
http://panda.cs.ndsu.nodak.edu/~achapwes/PICmicro/keyboard/atkeyboard.html
Scan Codes used in a keyboard:
http://panda.cs.ndsu.nodak.edu/~achapwes/PICmicro/keyboard/scancodes2.html
The PS2 Protocol:
http://panda.cs.ndsu.nodak.edu/~achapwes/PICmicro/PS2/ps2.htm
The Spatial Mouse project of April 2001, also provides some useful insight on how to transfer data serially to a computer via the PS2 port on the UP1 board. In fact, I ended up using some of the code developed by the members of the Spatial Mouse project. Here is a short description of the code used in my PS2 driver. Again, I would advise you that the code does not work perfectly, and you probably will want to fix any bugs you may come across.
1) clock_ticked.vhd: Slower clock derived from tick counting of incoming clock to generate a 25 KHz clock.
2) d_flipflop_falling.vhd : falling edge triggered d flip flop with asynchronous clear.
3) d_flipflop_rising.vhd : rising edge triggered d flip flop with asynchronous clear.
4) dual_phase_clock.vhd : dual phase clock generator generates two clocks 1/4 out of phase from each other
-- the output clocks are 1/2 the frequency of the input clock
5) dual_phase_clock_pkg.vhd : Package of the components used by the dual phase clock.
6) KB_PS2_decode.vhd : This decorder decodes five bit data from the keyboard into 11 bits of data. These 11 bits are required for the PS2 interface, and include the start, stop and odd parity bit used in the PS2 protocol.
7) oneshot.vhd : This program generates an enable signal that is 50 clock cycles wide when the enable signal is received. This ensures correct operation of the system, and allows a character to be repeated at a rate of 2 seconds approximately.
8) scan_code.vhd : This controller generates the make and break
codes required for a PS2 interface. The make code is simply the bit stream from the decoder.
The break code is generated by sending the bit-stream FO Hex, followed by the make code again.
9) shift_out_register.vhd : Output shift register with parallel loading input.
Assertion of load signal asynchronously loads register. Rising edge triggered shift only if shift is enabled.
Outputs a high by default.
Code used from Spatial Mouse project April 2001
10) transmit_controller.vhd : synchronizes data transmission with clock bus between Keyboard and PC
and assertion of data at appropriate clock pulses
Code used from Spatial Mouse Project April 2001
11) transmitter_pkg.vhd : This package is used for the PS2 interface
12) transmitter.vhd Transmits a
keyboard command byte to host. PS/2 timing requirements are enforced.
Code modified from spatial mouse project April 2001.
I hope you find the information I have provided useful. If you have any
questions please email me at: azdhanji@ee.ualberta.ca
Submitted by: Aly Dhanji - DATAD Binary Keyboard group December 2001