S100 Computers

HomeS-100 Boards HistoryNew BoardsSoftwareBoards For Sale
ForumOther Web SitesNewsIndex   
A PS2 Keyboard Input FPGA Code Example.
This circuit example adds a very basic PS2 Keyboard input port to the FPGA Prototype board.  It assumes the user is familiar with the very common "PS2 keyboard Interface", most commonly found in IBM PC's and clones. See here for more details.

The actual hardware on the board consist of a 2X5 pin connector to a PS2 keyboard socket (via a ribbon cable) at the back of your S100 bus box. Please note the pinout of this connector is exactly the same pinout as the PS2 connector on our V3 MSDOS Support Board.    BTW, this pinout is different from the PS2 pinout on our Console IO Board. Of course it can be easily changed.
    keyboard Live      Sockets_PS2
In 1987 IBM introduced its PS2 line of PCs. This was an effort to stem the flow of "IBM PC clones" that were swamping the market.  Major changes included the introduction replacing the ISA bus completely with a "Micro Channel Bus". This MCA bus was not well received by the PC customer base, since it was proprietary to IBM and was not commonly implemented by any of the other PC-compatible makers. Eventually IBM abandoned the architecture and return to the standard ISA bus.  The one and only item  PS2 computers offered that remained , was the keyboard and mouse interface.  It went on to dominate world wide all desktop and laptop interfaces.  Today,  its almost impossible to find a new keyboard that does not utilize a PS2 interface (or its USB adaptor equivalent).

Unlike earlier keyboard interfaces that returned simple parallel 8 bit ASCII codes from the keyboard, PS2 keyboards return a sophisticated serial code over two wires (CLK & DATA).  Please read here to understand the PS2 keyboard protocol if you are not familiar with it.

We will utilize our FPGA Prototype board to examine this PS2 data stream and display the pressed key ASCII code on the 8 LEDs of our FPGA board.

Again there are many ways this can be done with a Cyclone IV FPGA and the are numerous examples available on the web. 
I found this simple one from DigiKey to be excellent. PS/2 Keyboard to ASCII Converter (VHDL)

Since we are working with .bdf files we need to convert this .
VHD file to a .bsf file. We do this from the Quartus File Menu.

Load the 
ps2_keyboard_to_ascii.vhd file.
The click File dropdown menu and select "
Then select,
Create Symbol Files from the Current File.

You must have the support files,
ps2_keyboard.vhl and debounce.vhd files in the current folder as well.  (See the bottom of this page for everything that is needed).

Hooking up the PS2 keyboard on our FPGA board is dirt simple.
Here is the core of the
PS2_key.bdf file
We connect pins P17 4 & 5 to the PS2 connector at the top of the board.

Load the compiled code into the FPGA. When you press a PS2 keyboard character the appropriate 8 bit ASCII code should appear on LEDs 0-7.  For example pressing the "1" key should display 31H.
Upon each key press the WaveShare LED2 should flash.

As an FPGA coding exercise you can combine this circuit with
PortIN_Test.bdf so that you can read the keyboard on say port 68H and the keyboard status on port 69H.

Note this is a very simple example of using our Cyclone IV to for a PS2 keyboard. More elaborate interfaces have a bidirectional interface with the keyboard.  Please study the files below to understand completely what is going on before going on to more complicated examples.

PS2_KEY.ZIP  (V1.0 10/18/2018)

This page was last modified on 10/18/2018