Keyboard decoder

Topics related to the SBC- series of printed circuit boards, designed by Daryl Rictor and popular with many 6502.org visitors.
Post Reply
User avatar
8BIT
Posts: 1787
Joined: 30 Aug 2002
Location: Sacramento, CA
Contact:

Keyboard decoder

Post by 8BIT »

I have created a PC keyboard decoder using an Atmel ATTiny26 controller. (20 pin DIP package).

Here are the preliminary specs:

This chip does all of the scancode decoding of a standard keyboard and provides an 8 bit output containing the standard ASCII codes in addition to special codes for the extra keys (Alt, windows, pause, scroll lock, etc).
Data ready and data acknowlege signals are used for handshaking.

This takes the workload off of the 6502 and can be easily connected using an 8 bit port on a 6522. I have a working prototype connected to Port B of a 6522 on my SBC. Port A has my Text Video Display connected, allowing complete stand alone operation of my SBC. (No Serial port terminal required!)

I hope to have a working PCB designed soon that will integrate the keyboard decoder, text video, and the necessary logic to allow connection thru the expansion port, keeping the SBC's 6522s available for general I/O.

I'll update my website soon with all the details.

Thanks!

Daryl
User avatar
GARTHWILSON
Forum Moderator
Posts: 8774
Joined: 30 Aug 2002
Location: Southern California
Contact:

Post by GARTHWILSON »

In your diagram at http://sbc.rictor.org/io/pckbavr.html (diagram shown below), you show a pull-up resistor on both the clock line and the data line. Is there any need to have one on the clock line? It is only fed from the controller end isn't it, so it could be connected to a totem-pole output with no resistors? You show the other keyboard interface at http://sbc.rictor.org/io/pckb6522.html with the 6522 with no pull-ups at all, but I figured that was because the older ones really did have LSTTL-type inputs instead of high-impedance like WDC's CMOS ones, so they were naturally pulled up internally.

Image
User avatar
8BIT
Posts: 1787
Joined: 30 Aug 2002
Location: Sacramento, CA
Contact:

Post by 8BIT »

Garth,

Both resistors are optional. I think I threw them in because some of the reference material I was using showed the pull-up resistors in their interfaces. I made them 10k in value so they were providing a weak pull-up. Just above the schematic on the web page, I included this text:
Quote:
This keyboard decoder takes all of the overhead associated with scancode to ASCII conversion and places it in the interface. This frees the 6502 to handle more important operations. The simple circuit consists of an 6-pin PS2 keyboard socket, an Atmel ATTiny26 microcontroller, a 14 pin header, and two optional resistors!
Hope that answers your question?

Daryl
Last edited by 8BIT on Sat Feb 21, 2009 4:14 pm, edited 1 time in total.
User avatar
GARTHWILSON
Forum Moderator
Posts: 8774
Joined: 30 Aug 2002
Location: Southern California
Contact:

Post by GARTHWILSON »

Obviously I haven't looked into it enough to do it myself but it is my understanding that the data line has to be a wire-OR open-drain-type arrangement so data can be sent both directions on an interface that is much like I²C; so it would require the pull-up. I²C needs it on the clock line too if you have a multi-master situation (which is not common).
User avatar
BitWise
In Memoriam
Posts: 996
Joined: 02 Mar 2004
Location: Berkshire, UK
Contact:

Post by BitWise »

The I2C standard allows slave devices to perform 'clock-stretching' if they need more time to process a request. If a slave holds the clock line low then the master should wait for line to return to the high state before continuing with the next byte transfer. So both clock and data can be bi-directional even in a single master configuration.
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs
gnb10
Posts: 5
Joined: 06 Mar 2007

Post by gnb10 »

The PS/2 clock can be driven from either end too, so if the data line needs a
pull-up odds are the clock will too. The reason for this is that if the host wants
to send commands to the keyboard it signals this by pulling the clock low for
(at least) 100 microseconds, then releasing it and waiting for the keyboard to
start clocking in the bits.
smilingphoenix
Posts: 43
Joined: 20 May 2006
Location: Brighton, England

Post by smilingphoenix »

Both the clock and data lines need a pull-up of some sort. The keyboard specification requires the lines be driven with open-collector style outputs at both ends, so both ends can pull the lines low at the same time but neither end can pull it high and create a short-circuit when the other end pulls it low.

If your microcontroller chip has built-in pullups you can use these, keeping the pin as an input except when you want to pull it low. I prefer adding external 10k pullup resistors - they help to improve the noise immunity.
Shift to the left, shift to the right,
mask in, mask out,
BYTE! BYTE! BYTE!
leeeeee
In Memoriam
Posts: 347
Joined: 30 Aug 2002
Location: UK
Contact:

Post by leeeeee »

The spec requires the attached device, keyboard or mouse, to have the pullups.

Lee.
smilingphoenix
Posts: 43
Joined: 20 May 2006
Location: Brighton, England

Post by smilingphoenix »

Thanks for that snippit - in all the pages of stuff I've read on the keyboard & mouse interface, that fact was notable by its absence. Darn - all those resistors I could have saved... :roll:
Shift to the left, shift to the right,
mask in, mask out,
BYTE! BYTE! BYTE!
User avatar
ptorric
Posts: 85
Joined: 13 Feb 2005
Contact:

Post by ptorric »

hi Daryl, i'm investigatin on ps2 keyboard.
a question: why did you choose to use an external controller and not use a 6522 direct interface?
do you think is it a problem to put under irq an interfacing routine?
i asking to myself why didnt we (forum) already make some "standard" interface routines for general purpose use ps2 keyboard.
thanks!
User avatar
8BIT
Posts: 1787
Joined: 30 Aug 2002
Location: Sacramento, CA
Contact:

Post by 8BIT »

Why not use the 6522?

Personal preference on my part. Depending upon your application, the 6522 is a great choice. It requires no additional parts or address decoding. If you want to reduce the chores of decoding the serial data from the 6502, then a microcontroller is a good choice. It adds extra hardware and decoding.

In the case of the SBC-3, I wanted to leave as much of the 6522's resources open as possible for user applications. Also, since I didn't want the 65816 to be bogged down servicing numerous I/O tasks, I chose the microcontroller. The added benefit was an RS-232 port for no extra hardware!

I have written a PC keyboard decoding routine for the 6522. The code is on my website. It does not require interrupts as it disables the keyboard from clocking until the 6502 is ready to read it. It could be modified for intterupts if desired.

http://sbc.rictor.org/io/pckb6522.html

Hope that helps!

Daryl
Post Reply