Pretty sure our keyboard was broken so we scrapped this idea and used buttons instead. Feel free to read it anyways, who knows you might learn something.

PS/2 Connection
A PS/2 connection is an older way of communicating between computers and keyboards. Today most keyboards use USB but the PS/2 connection can still be found. It consists of 6 lines/wires, one for Data, one for Ground, one for power, and one for a clock, the other two are not used. Clock and data lines are bi-directional, both the keyboard and host can use them.

Basic Overview
Using a keyboard with a PS/2 connection along with the PS/2 P-Mod, we are able to control the turret's movement. When a key is hit on a keyboard a "message" is sent to the computer or other host (in our case the FPGA). This "message" is known as a Scancode and consists of two letters or numbers, for instance, the letter "A" sends a scancode of "1C" to the computer. The scancode of "1C" is sent by a signal of 1's and 0's; 1 is considered "high" and a 0 is considered "low". The alternating high and low signal is read by the computer and translated into letters and numbers. Upon recieving the "1C" scancode from the keyboard, the computer will take that scancode and will print it to the screen or use it for whatever function is needed, in our case the letter "A" will move the turret down. This is all done extremely fast, and therefore timing will be extremely important.

PS/2 connections are bi-directional, meaning the keyboard can communicate to the host and the host can communicate with the keyboard. So when does the host device know when to recieve data or send data? This is done by the combination of a clock and an "initiation" bit. Because both need to communicate with each other, both need to be running off a clock that is going at the same speed (more on this later). The keyboard can only send data when the clock signal is "high". So if the host wants to send information it will pull the clock to a "low" position, inhibiting the ability of the keyboard to send data. The keyboard will write to the Data line when the clock signal is high and the host will read this data when the clock is low.

The host and keyboard must also be on the same page when it comes to receiving and transmitting information. The keyboard sends a total of 11 bits, 8 of those bits makes up the scancode. The first is the "initiation" bit, basically the keyboard sends a "low" signal to initiate the transfer of data, this is followed by the 8 bit scancode and 1 parity bit. The parity bit is a way to catch mistakes. What it does is makes the amount of 1's odd, so if there are an even amount of 1's in the scancode the parity bit will be a 1 to make an odd number of 1's. If the number in the scancode is odd, the parrity bit will be a 0, keeping the amount of 1's odd. As odd as this seems, the role of the parity bit is very important. If the host recieves an even number of 1's it will know that the code was a mistake, so the host will request for the scancode to be resent, this will ensure that no errors occur resulting in the loss of data. It will fix mistakes and make the communication run much smoother. The 11th bit that is sent to the host is the "end" bit, this is always a 1 and tells the host that it is done sending data. The host will then send one bit back to the keyboard acknowledging that it recieved the information.

For a more in depth look at the procedure take a look at this site:

This code is not mine, it is the code that comes from Digilent Inc. It serves as a great example of how the interfacing of a keyboard appears in VHDL. I suggest reading both the website and the VHDL to better understand this topic.