PS/2 keyboard interface to a uC - Page 1
Forum section: electronics / general

author: ZeroResistance
author_rank: Frequent Contributor
timestamp: October 25, 2016, 04:13:48 pm
content: Is it a possibility to handle a PS/2 keyboard entirely in hardware... I mean by wiring it to a SPI / I2C or say a UART.I have read forum posts especially on microchip forums where the users say that they did it in software because of the wierd nature of the PS/2 protocol.Has anyone over here has success in doing so?I'm trying to figure out the protocol from Adam Chapweske's site over herehttp://www.computer-engineering.org/ps2protocol/

author: ZeroResistance
author_rank: Frequent Contributor
timestamp: October 25, 2016, 04:37:59 pm
content: Quoteso says that article.If so can the clock pin be wired to an external interrupt pin, interrupt latency might come into play here but I want to service the keyboard as quickly I can and free up the cpu to do other tasks.

author: C
author_rank: Super Contributor
timestamp: October 25, 2016, 05:12:44 pm
content: From memory, I think you will find that the end creating the clock used can have it stretched by other end.Note that a ps2 keyboard sends and receives data. You might think of leds but older keyboards had many modes of operation set from pc.

author: ZeroResistance
author_rank: Frequent Contributor
timestamp: October 25, 2016, 05:23:38 pm
content: Quote from: C on October 25, 2016, 05:12:44 pmAs per what I read it says that the device always generates the clock but the host controls the whole game, I mean that the host can interrupt a device sending by pulling the clock low, and it can then start sending data.

author: westfw
author_rank: Super Contributor
timestamp: October 25, 2016, 09:26:38 pm
content: QuoteYes. This seems to be a popular implementation; there's an Arduino implementation that does this here:http://playground.arduino.cc/Main/PS2Keyboard(they seem to have a bunch of other links too.)

author: ZeroResistance
author_rank: Frequent Contributor
timestamp: October 26, 2016, 05:59:19 am
content: Quote from: westfw on October 25, 2016, 09:26:38 pmThanks for the info westfw, I have to handle a mouse and a keyboard on a single chip and along with that the chip would also be doing other tasks my concern is interrupt latency given that the clock frequency of PS/2 is around 10 - 16.7 kHz it shouldn't cause much problems.I would be doing this on a PIC32.If I remember correctly one of the posters had wired up the clock to the input capture pin instead of the INTX pins.

author: ZeroResistance
author_rank: Frequent Contributor
timestamp: November 01, 2016, 06:28:24 am
content: Are there any chips that can handle the PS/2 interface?

author: timb
author_rank: Super Contributor
timestamp: November 01, 2016, 10:27:38 am
content: Quote from: ZeroResistance on November 01, 2016, 06:28:24 amA PSoC 3 or 5LP could do it in hardware. You could whip up a UDB implementation pretty easily in Verilog. If you don't know how to do that, you might be able to simply creat a state machine with some LUT blocks, plus a timer and a few other things. (That might use slightly more resources than going pure Verilog.)

author: CJay
author_rank: Super Contributor
timestamp: November 01, 2016, 03:52:27 pm
content: It's do-able, but if you can still find a keyboard that's PC/XT compatible (not as hard as you may think) it's even easier.

author: rstofer
author_rank: Super Contributor
timestamp: November 01, 2016, 04:51:43 pm
content: Even if the keyboard has a USB cable, there are adapters that convert it to PS/2https://www.amazon.com/StarTech-com-Replacement-Keyboard-Adapter-Mini-DIN/dp/B000A0K2JO/ref=sr_1_2Once you have the signals in PS/2 form, there are a number of projects around including:http://playground.arduino.cc/Main/PS2KeyboardPS/2 is an ugly thing to deal with. Here are the details:http://www.computer-engineering.org/ps2protocol/The last time I did this, I used the keyboard as part of an FPGA CPU project. I'm pretty sure I started with something from Opencores and modified it for my needs.