Simple PC Keyboard to BS2 interface
TechnoRobbo
Posts: 323
Simple and cheap.· Based on 4 inexpensive readily available chips LM339 (Quad Comporator),two·74HC595 Shift Register and the 74HC165 Shift Register.
The principle is simple clear the buffer (74HC595) release the clock for the keyboard so it starts sending data. Invert the incoming bits so the start bit can be used via the comparator to pull the clock low and force the keyboard to stop and store keystroke data. Then read the data (inverted) via the 74HC165.
Ok it "sounds" complex but it's not. heres the snippet of code that reads the keyboard.
getkey:
··· PULSOUT clear,20· 'clear buffer
··· PULSOUT start,250 'start cycle
··· DO
··· LOOP UNTIL stopbit=1 'Wait for cycle TO finish
··· PULSOUT load, 5 ' grab the switch inputs
··· SHIFTIN datain, clock, MSBPRE, [noparse][[/noparse]scancode]
· RETURN
Yes, that's all!
The program then converts the scan codes into ascii and outputs them out the serial port. If you choose not to use ascii you can work with the scan codes and turn the keyboard into a 144 button pad.
Here's a link to the document I used as a reference to the scan codes: http://www.beyondlogic.org/keyboard/keybrd.htm
Schematics and code for BS2 are attached. I scavanged the keyboard plug from an old pc motherboard.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Post Edited (TechnoRobbo) : 2/4/2007 7:44:32 PM GMT
The principle is simple clear the buffer (74HC595) release the clock for the keyboard so it starts sending data. Invert the incoming bits so the start bit can be used via the comparator to pull the clock low and force the keyboard to stop and store keystroke data. Then read the data (inverted) via the 74HC165.
Ok it "sounds" complex but it's not. heres the snippet of code that reads the keyboard.
getkey:
··· PULSOUT clear,20· 'clear buffer
··· PULSOUT start,250 'start cycle
··· DO
··· LOOP UNTIL stopbit=1 'Wait for cycle TO finish
··· PULSOUT load, 5 ' grab the switch inputs
··· SHIFTIN datain, clock, MSBPRE, [noparse][[/noparse]scancode]
· RETURN
Yes, that's all!
The program then converts the scan codes into ascii and outputs them out the serial port. If you choose not to use ascii you can work with the scan codes and turn the keyboard into a 144 button pad.
Here's a link to the document I used as a reference to the scan codes: http://www.beyondlogic.org/keyboard/keybrd.htm
Schematics and code for BS2 are attached. I scavanged the keyboard plug from an old pc motherboard.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Post Edited (TechnoRobbo) : 2/4/2007 7:44:32 PM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Post Edited (TechnoRobbo) : 2/6/2007 1:33:30 AM GMT
Are you going to make an board for this project
or are you just bread board it
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
As many need it...
Well done!!!!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Rule your Destiny-
--Be Good. Be Bad. Be Provas--
The hellinic (Greek) robots portal: Greekbotics
Many Projects and Schematics by the users·and also robotic news
(Translate using babelfish)
I'm·not quite sure what your question is.· I'm not looking to sell boards. I am making a board for myself.· I'm· releasing the design into the public domain and hoping people expand on it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Post Edited (TechnoRobbo) : 2/4/2007 4:09:49 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Enter characters:
a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9
Output characters: (Note: blank space means nothing was displayed)
`····· d·· f z h i o2j
Note: a 'g' gave multiple 'z' sometimes followed by a 'g'
A further test revealed that if you were to keep pressing and releasing a key it would eventually come up. Sometimes nothing would get displayed first and sometimes like the case of the 'g' it would have 'zzzzz' in front of the g.
Some characters such as f, h, m and others always came up correctly.
I also tried it on a BS2px and similar results happened. I got different characters - which almost sounds like a timing issue since the BS2px is faster. I don't really know for sure.
Any ideas how to solve this?
Post Edited (T&E Engineer) : 2/4/2007 10:54:40 PM GMT
COMMENTS PLEASE...
Thanks,
In my earlier schematic I negelected to put in the power for the LM339.· Make sure you have the current schematic. I also did not include the BS2 ground - taking it for granted. It's now in the schmatic. I also clarified the·PS2·pin numbers since the reference article differs from the standard mindin p6 connector numeration.
The LED's
All· PS2 keyboards default to Scan Set2. The LEDs are not a keyboard function. They are turned on and off by the host. The keyboard only transmits scan codes (press and release).
The buffer is one directional (input) requiring twice as many chips to merely·turn on LED's.
The Problem & The BS2px
It's more than likely a timing issue since they are critical to the buffer operation.
The following routine is·based on the BS2 2 µs timing. The Bs2px is based on .8µs
··· PULSOUT clear,20· 'clear buffer
··· PULSOUT start,250 'start cycle
··· DO
··· LOOP UNTIL stopbit=1 'Wait for cycle TO finish
··· PULSOUT load, 5 ' grab the switch inputs
··· SHIFTIN datain, clock, MSBPRE, [noparse][[/noparse]scancode]
· RETURN
Try increasiing the timing as follows for the Bs2px:
··· PULSOUT clear,50 'clear buffer
··· PULSOUT start,625 'start cycle
··· DO
··· LOOP UNTIL stopbit=1 'Wait for cycle TO finish
··· PULSOUT load, 13' grab the switch inputs
··· SHIFTIN datain, clock, MSBPRE, [noparse][[/noparse]scancode]
· RETURN
To clarify: the pulsout start,625 command has to stay on long enough for the keyboard clock to shift the register 1 time. This forces the register to latch a zero at the stopbit pin from the reset command.· If you send too fast a signal it will retain the "one" bit from the last byte. ·The fact that your getting gibberish is a good sign as long as the gibberish is consistent.
Once you have the timing adjusted the buffer will work flawlessly. My wife types 80 WPM and she can't get it to give an error.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Post Edited (TechnoRobbo) : 2/6/2007 12:25:14 AM GMT
The attached DEBUG screenshot shows what happens when I enter all lowercase alphabet characters and then all uppercase alphabet characters.
(e.g. abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ)
As you can see many times when a character was entered nothing came out and other times strange characters came out. Since it is fairly reproducible it is not noise or randomness but simply the wrong scancode coming out.
Any other ideas? I will also attempt to rebuild the circuit and see if this helps on a different breadboard with wires from the BS2 P0-P5 and power (+5v and GND) from the Professional Development Board to the external soderless breadboard.
Since I have completely issolated the problem out then it has to be one of two items:
1. Bad IC chips
2. Code that is customized for your setup.
I will try replacing all of the IC chips 1 by 1 and report back.
This line:
...could be the key try increasing it to 800 - this is the only line that is dependent on the speed of the keyboards clock (hence specific to the keyboard) and requires at least 1 cycle to be transmitted by the clock.
One method of trouble shooting would be to connect the 8 data lines direct to the stamp pins 8 thru 15. set them as inputs·(·DIRH=0)· and read them as a byte (·scancode=INH ).
·and rem out"
··· 'PULSOUT load, 5 ' grab the switch inputs
··· 'SHIFTIN datain, clock, MSBPRE, [noparse][[/noparse]scancode]
view the input as HEX scancodes·to make sure your wires are in order.
If F9 is pressed it should produce the codes :·· 01 F0 01
If F5 is pressed it should produce the codes :·· 03 F0 03
and so on.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Post Edited (TechnoRobbo) : 2/6/2007 12:07:24 PM GMT
I·replaced the first 595 and it fixed itself. I got the·all the right codes:
abcdefghABCDEFGH
I did notice a couple of·times I got a0b0c0d0e0.
However, when I swapped them out and pressed down·to get a·good connection, it is ok now. weird.
All is working. This is really nice!!
I would like to interface it to a SX Video module from Bean to make it sort of like the TV typewritter that you see on the Propeller chip (very limited though). However, neat idea all the same. I will also at some point rewrite the code for an SX-28 to bring the cost factor down (as I have many SX-28's but only 1 BS2 and 1 BS2px (more·cost too)).
Great Job!
BTW: Your timing specifications were correct for the BS2px too. If you left the original numbers (20, 250, 5) in the subroutine, it would not always send a character to the screen. However, if you used the (50,625 and 13) numbers - it worked correctly.
Post Edited (T&E Engineer) : 2/6/2007 2:25:57 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Parts:
B1·········· 9 Volt
PIC OUT·· DB9 Custom
R1········· 1Meg
R2········· 1Meg
R3··········10K
R4········· 10K
R5········· 10K
R6········· 10K
u1········· 74HC595
u2··········74HC595
u3········· 74HC165
U4········· LM339
U5········· PS2 Socket·scavanged
U6········· LM7805
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Post Edited (TechnoRobbo) : 3/12/2007 3:57:38 AM GMT
Congrats on the PCB!
I included the software as an example on how to read it.· And like most projects on a forum, it's intended to educate people on different possibilities, techniques·and present unconventional solutions to those that are learning.
The circuit is the message - not the board. Recently i·heard that with the lapse of the Apollo program,·NASA had to re-learn how to launch rockets into space. Let's not forget how to invent.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Post Edited (TechnoRobbo) : 3/11/2007 5:53:07 PM GMT