PS/2 to Master keyboard interface?

for bbc micro/electron hardware, peripherals & programming issues (NOT emulators!)
crj
Posts: 323
Joined: Thu May 02, 2013 4:58 pm

PS/2 to Master keyboard interface?

Postby crj » Sat Sep 30, 2017 2:59 am

My BBC Master is just under 19" wide. Currently it takes up quite a bit of space.

I have an equipment rack, and a KVM switch.

Are you thinking what I'm thinking?

What if I could put the Beeb out of the way and access it through my KVM switch?

Now, I'm aware of this user port hack, but (a) I want the user port for other purposes and (b) it requires software support. I'd much rather fake it at the hardware level.

Google isn't finding any such project; have I missed anything? Otherwise, I reckon an ATmega324PB PIC has enough GPIO and could easily bit-bang fast enough. As a stretch goal, it ought to be feasible to leave the real keyboard working simultaneously with the computer accepting keystrokes from either/both.

Is this worth doing? Am I the only person who wants one?

(The BBC B/B+'s keyboard looks more fiddly to emulate, because of that pesky 74LS163 running at 1MHz. It'd probably need one of the vanishing breed of 5V FPGAs/CPLDs.)

User avatar
myelin
Posts: 203
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

Re: PS/2 to Master keyboard interface?

Postby myelin » Sat Sep 30, 2017 3:41 am

Funny how things always seem to happen at the right time here... I just started working on this exact project.

Assuming you're talking about a Master 128, it's highly unlikely that you'll be able to bit bang this one fast enough unless you're running a *really* fast MCU. It uses a keyboard encoder chip that contains all the logic that's in the chips on the BBC B/B+ keyboard. The Master 128's keyboard connector is 30 pins wide (PL11 + PL24) and connects directly to the rows and columns on the keyboard. The keyboard encoder chip cycles the column lines low, and reads the row lines to see if any of them go low. Chances are, it does this pretty quickly, although I haven't verified this by attaching a scope to the column lines.

So there's two ways to do this. Prime got it working back in 2009 with a crosspoint switch, which is a chip which has a programmable matrix of connections (used for some analog operations, but happens to perfectly emulate a keyboard).

That's probably the most safe/reliable way to do things, but the MT8816 crosspoint switch chip is $11 and I have a bunch of CPLDs on hand, so I'm trying a different approach, with a microcontroller pushing key state into the CPLD, and the CPLD outputting the correct row values when the relevant column is strobed. I have some VHDL code for it, but I haven't tested anything yet. The PS/2 keyboard arrives Monday, so I'll probably have some results next week :)
SW/EE from New Zealand, now in San Francisco: http://myelin.nz/
Having fun making hardware projects for the Electron!
So far: 32k flash cart, USB cart interface, 3-cart expansion, Elk PiTubeDirect. Later: Dual ported ram cart.

crj
Posts: 323
Joined: Thu May 02, 2013 4:58 pm

Re: PS/2 to Master keyboard interface?

Postby crj » Sat Sep 30, 2017 6:02 am

Yes, your hacking at a BBC Master that had no keyboard reminded me of the project I'd been thinking about for a while. I should have mentioned/acknowledged that - sorry.

The chip is fed 1MHz, but there's no earthly reason why it needs to scan the key matrix anything like that fast. Even 10kHz would be ample for any conceivable purpose!

Conversely, a 20MHz CPU does actually have time to do load-from-GPIO, table-lookup, save-to-GPIO within one phase of a 1MHz clock. Admittedly, speaking PS/2 at the same time is a little less plausible if it really is scanning at 1MHz.

Crosspoint switches seem to have more than doubled in price since you looked, unless you know some online retailer which has them in a bargain bucket. But there's absolutely no need. You could fake it with a bunch of octal tristate latches. And as you say it's easily within the capabilities of a large CPLD or tiny FPGA.

You might have some spare CPLDs kicking around, but I don't, and I'm reluctant to buy remaindered stock. If you know any of 5V programmable logic bigger than the Lattice ispMACH4000 that's not end-of-life I'd very much like to hear about it!

User avatar
myelin
Posts: 203
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

Re: PS/2 to Master keyboard interface?

Postby myelin » Sat Sep 30, 2017 7:07 am

(quick response here b/c I'm on my phone right now)

Conveniently, the Xilinx XC9500XL CPLD series is in active production and interfaces very nicely with TTL logic levels. The inputs can handle up to 5.5V, and it's 3.3V outputs drive TTL (or TTL compatible, like the Master) logic just fine. So no need to buy remaindered stock. It's pretty solderable too, in the tqfp 44 pin package. My logic for the keyboard emulator fits in a $3.50 xc9572xl-10vq44.
SW/EE from New Zealand, now in San Francisco: http://myelin.nz/
Having fun making hardware projects for the Electron!
So far: 32k flash cart, USB cart interface, 3-cart expansion, Elk PiTubeDirect. Later: Dual ported ram cart.

User avatar
myelin
Posts: 203
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

Re: PS/2 to Master keyboard interface?

Postby myelin » Sat Sep 30, 2017 7:08 am

If you have a scope handy it would be awesome if you could take a look and see if the cols strobe at 1Mhz or if the scan freq is lower in the Master! I'll give this a try next week (next time I have some project time) otherwise.
SW/EE from New Zealand, now in San Francisco: http://myelin.nz/
Having fun making hardware projects for the Electron!
So far: 32k flash cart, USB cart interface, 3-cart expansion, Elk PiTubeDirect. Later: Dual ported ram cart.

crj
Posts: 323
Joined: Thu May 02, 2013 4:58 pm

Re: PS/2 to Master keyboard interface?

Postby crj » Sat Sep 30, 2017 10:54 am

myelin wrote:the Xilinx XC9500XL CPLD series is in active production


I accept that some seem to be for sale. However this suggests they were discontinued in at the start of 2013. Did Xilinx, have a change of heart? Have I misunderstood that notice? Are there just piles of the things still sitting in warehouses?

User avatar
hoglet
Posts: 6623
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol

Re: PS/2 to Master keyboard interface?

Postby hoglet » Sat Sep 30, 2017 12:16 pm

crj wrote:I accept that some seem to be for sale. However this suggests they were discontinued in at the start of 2013. Did Xilinx, have a change of heart? Have I misunderstood that notice? Are there just piles of the things still sitting in warehouses?

That notice refers to the original XC9500 series (5V VCC).

The XC9500XL series (3.3V VCC, 5V tolerant I/O) is still I believe a current product.

Dave

crj
Posts: 323
Joined: Thu May 02, 2013 4:58 pm

Re: PS/2 to Master keyboard interface?

Postby crj » Sat Sep 30, 2017 12:41 pm

Hmm. So an XC9500XL isn't a kind of XC9500? Clear as mud!

I've just found another discontinuation notice, from 2016, for some of the XC9500 package options. That was via a blog entry which referred to the XC9500XL line as "mature".

But yes, it does appear the devices continue to be manufactured in some shape or form. This is relevant to my interests, thanks. (-8

crj
Posts: 323
Joined: Thu May 02, 2013 4:58 pm

Re: PS/2 to Master keyboard interface?

Postby crj » Sat Sep 30, 2017 1:13 pm

Hmm. I'd forgotten how expensive and tiny CPLDs are by today's standards, though. It looks like you'd need at least the XC95144XL for the job, the limiting factor being the need for at least one register per key.

So that's £5.60 or so. Whereas thirteen MM74HCT373 octal 5V tri-state latches cost 13*40p = £5.20.

I guess the CPLD could present a tidier interface to the uC, though, so there's that.

crj
Posts: 323
Joined: Thu May 02, 2013 4:58 pm

Re: PS/2 to Master keyboard interface?

Postby crj » Sat Sep 30, 2017 1:16 pm

Incidentally, do you know that it drives columns and reads rows, rather than driving rows and reading columns? The schematic is unforthcoming.

User avatar
myelin
Posts: 203
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

Re: PS/2 to Master keyboard interface?

Postby myelin » Sat Sep 30, 2017 3:52 pm

I plead exhaustion... I missed your comment about using 13 octal latches. I love that idea... still prefer the CPLD approach for my own project, but the sea of latches is very much in keeping with the "retro hardware" theme here and will actually let you store enough bits to fully emulate the keyboard, rather than what I'm doing in my CPLD, which is to emulate max two keys at once (plus shift/ctrl/break, which are outside the matrix). (That's how I can fit it in a 9572.)

I'm pretty sure it's the cols and not the rows that are driven, but check the Master service manual in case I misread it. Putting a scope on the keyboard lines will also work.

I'll post my VHDL in a few days; it compiles but is untested so far.
SW/EE from New Zealand, now in San Francisco: http://myelin.nz/
Having fun making hardware projects for the Electron!
So far: 32k flash cart, USB cart interface, 3-cart expansion, Elk PiTubeDirect. Later: Dual ported ram cart.

crj
Posts: 323
Joined: Thu May 02, 2013 4:58 pm

Re: PS/2 to Master keyboard interface?

Postby crj » Sat Sep 30, 2017 6:42 pm

Hmm. Two keys at once isn't enough for Elite. Six would be, but not two. :-p

crj
Posts: 323
Joined: Thu May 02, 2013 4:58 pm

Re: PS/2 to Master keyboard interface?

Postby crj » Sat Sep 30, 2017 7:15 pm

I'd never read the service manual before. If it wasn't in the New Advanced User Guide or the schematic, it was a mystery to me. I've now read:
R0 to R7:- The keyboard row input connections[...]
C0 to C14:- These open collector column driving outputs[...]

So yes, it drives columns and reads rows.

It also says the column lines "are sequentially taken active low in auto scan mode at a rate of 1MHz". That's when it's robotically looking for any pressed key; once it's discovered that a key has been pressed the CPU takes over and performs a slow scan looking for a specific key. I've not looked at the actual code, but it's likely as simple as "STX sys6522a:LDA sys6522a", giving only three 2MHz cycles and a 1MHz cycle in which to react. 2.5µs isn't actually much more slack a constraint than 1µs. )-8

User avatar
jgharston
Posts: 2759
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield

Re: PS/2 to Master keyboard interface?

Postby jgharston » Sat Sep 30, 2017 7:47 pm

crj wrote:Incidentally, do you know that it drives columns and reads rows, rather than driving rows and reading columns? The schematic is unforthcoming.

On the BBC it's clear that during autoscan the columns are driven, counting upwards, as it's driven by a 74LS163 running free with its outputs wired to the keyboard columns, and the rows are wired to the inputs of a 74LS251.

When a key is pressed the currently selected column is connected to the IRQ line. When an IRQ is received the MOS stops the free running and selects each column counting downwards and samples the KBDIRQ line in the VIA until it finds the column that generated the IRQ. The MOS then goes through selecting which row of this column to read from, counting upwards, sampling the KBDWR line in the VIA until it finds the row in that column with a key pressed.

So, columns are driven and rows are read.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

User avatar
jgharston
Posts: 2759
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield

Re: PS/2 to Master keyboard interface?

Postby jgharston » Sat Sep 30, 2017 7:57 pm

crj wrote:once it's discovered that a key has been pressed the CPU takes over and performs a slow scan looking for a specific key. I've not looked at the actual code, but it's likely as simple as "STX sys6522a:LDA sys6522a", giving only three 2MHz cycles and a 1MHz cycle in which to react. 2.5µs isn't actually much more slack a constraint than 1µs. )-8

CJR managed to post while I was typing up mine. :)

What the MOS does is essentially:
?&FE40=&0B ; stop autoscan
?&FE43=&7F ; %01111111 b7=input b6-b0=output
keynum=15 ; start with column 15 (or 9 on BBC)
REPEAT
.... ?&FE4F=keynum ; write to PortA to select this column
.... pressed=(?&FE4D AND 1) ; read KBDIRQ
.... IF NOT pressed THEN keynum=keynum-1
UNTIL column<0 OR pressed
IF NOT pressed THEN exit
REPEAT
.... ?&FE4F=keynum ; write to PortA to select column in b0-b3, row in b4-b6
.... pressed=(?&FE4F AND 128) ; check KBDWR in b7
.... IF NOT pressed THEN keynum=keynum+16 ; select next row in b4-b6
UNTIL pressed OR keynum>127
IF NOT pressed THEN exit

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

User avatar
myelin
Posts: 203
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

Re: PS/2 to Master keyboard interface?

Postby myelin » Thu Oct 05, 2017 4:07 am

crj wrote:So yes, it drives columns and reads rows.


Note also that the column outputs are *open collector* and need pullups if you're reading them from a CPLD or MCU. I just discovered this after spending ages wiring a CPLD board (XC9572XL, which doesn't have programmable pullups) to my Master 128 motherboard, and finding that nothing worked :/

13 pullup resistors (or connections to MCU pins configured as pullups) is more than I want to try to wire up by hand right now, so now I'm deciding whether to make a PCB for this whole thing, or to try something else.

Are you having any luck so far with the MCU approach? I have an STM32F4 DISCOVERY board here that might be fast enough to emulate the keyboard in software; someone managed to make a Gameboy cartridge emulator using one a while back, so that might be worth a try.

(Update: I can't for the life of me seem to be able to find the Discovery board, so that may be a dead end for now...)
SW/EE from New Zealand, now in San Francisco: http://myelin.nz/
Having fun making hardware projects for the Electron!
So far: 32k flash cart, USB cart interface, 3-cart expansion, Elk PiTubeDirect. Later: Dual ported ram cart.

crj
Posts: 323
Joined: Thu May 02, 2013 4:58 pm

Re: PS/2 to Master keyboard interface?

Postby crj » Thu Oct 05, 2017 4:32 am

myelin wrote:Are you having any luck so far with the MCU approach?

I've not considered it further, to be honest. I've been focusing on other retrocomputing things for the time being. (On the plus side, those other things could turn out to be awesome. (-8 )

User avatar
myelin
Posts: 203
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

Re: PS/2 to Master keyboard interface?

Postby myelin » Thu Oct 05, 2017 6:54 am

crj wrote:(On the plus side, those other things could turn out to be awesome. (-8 )


Looking forward to hearing more :)

I realized that I do actually have access to the column signals -- they're on PL7. I soldered a header there and hooked NKBEN and SA0-3 up to my CPLD, and hardcoded it to simulate a press on 'R'. This successfully caused my Master 128 to go into the "CMOS RAM reset" screen on startup, so it looks like it's working! Time to wire this up to an MCU so I can use my laptop keyboard (and eventually a PS/2 keyboard once I've got one).

master_with_cpld_keyboard_sm.jpeg
SW/EE from New Zealand, now in San Francisco: http://myelin.nz/
Having fun making hardware projects for the Electron!
So far: 32k flash cart, USB cart interface, 3-cart expansion, Elk PiTubeDirect. Later: Dual ported ram cart.

Prime
Posts: 2346
Joined: Sun May 31, 2009 11:52 pm

Re: PS/2 to Master keyboard interface?

Postby Prime » Thu Oct 05, 2017 3:48 pm

myelin wrote:So there's two ways to do this. Prime got it working back in 2009 with a crosspoint switch, which is a chip which has a programmable matrix of connections (used for some analog operations, but happens to perfectly emulate a keyboard).

That's probably the most safe/reliable way to do things, but the MT8816 crosspoint switch chip is $11 and I have a bunch of CPLDs on hand, so I'm trying a different approach, with a microcontroller pushing key state into the CPLD, and the CPLD outputting the correct row values when the relevant column is strobed. I have some VHDL code for it, but I haven't tested anything yet. The PS/2 keyboard arrives Monday, so I'll probably have some results next week :)


Nope MT8816's available here : http://www.futurlec.com/ICSFZarlink.shtml For $4.50 US, so gonna be just under £4. I did originally considder using a bunch of LS chips when I was doing this for the Dragon, but ended up with the crosspoint as it was cheaper and less hassle. You may be able to do it with a CPLD however but it would end up essentially emulating a crosspoint anyways :) I believe some of the Sinclair folks managed to do this for the ZX8x / Spectrum.

Cheers.

Phill.

crj
Posts: 323
Joined: Thu May 02, 2013 4:58 pm

Re: PS/2 to Master keyboard interface?

Postby crj » Thu Oct 05, 2017 5:48 pm

I note the crosspoint isn't RoHS-compliant, though. That could be an issue.

For the mystery other project, I'm coming to the conclusion that the best bet nowadays is an Altera Max 10 FPGA and a handful of appropriate TI LVCH-family chips as 5V-tolerant glue (especially SN74LVCH245A - octal tristate transceiver).

The Max 10 range self-boots in milliseconds from internal flash. The LVCH family has bus-hold as well as 5V tolerance, so there's no need to worry about flapping inputs. There's a bit more silicon to glue down, but much more clout.

User avatar
1024MAK
Posts: 6791
Joined: Mon Apr 18, 2011 4:46 pm
Location: Looking forward to summer in Somerset, UK...

Re: PS/2 to Master keyboard interface?

Postby 1024MAK » Thu Oct 05, 2017 6:52 pm

crj wrote:I note the crosspoint isn't RoHS-compliant, though. That could be an issue.
In what way is it an issue? Lead based solder is not RoHS-compliant, but it's still permitted to be sold and used for hobby use.

Or do you mean that the chips are only available "while stock lasts" and that there may not be any currently being fabricated?

Mark
For a "Complete BBC Games Archive" visit www.bbcmicro.co.uk NOW!
BeebWiki‬ - for answers to many questions...

crj
Posts: 323
Joined: Thu May 02, 2013 4:58 pm

Re: PS/2 to Master keyboard interface?

Postby crj » Thu Oct 05, 2017 8:01 pm

If it's only going to be a one-off, or a thing everyone who wants builds from components then yes, it's fine.

However, it wouldn't be legal to make them and sell them. Unless one is certain that's off the cards, it seems worth at least considering RoHS when choosing how to implement something.

User avatar
myelin
Posts: 203
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

Re: PS/2 to Master keyboard interface?

Postby myelin » Fri Oct 06, 2017 6:15 am

I tried and failed to get this working with a PS/2 keyboard -- not sure if the keyboard I just bought was DOA, or I broke something along the way, but it's super temperamental and nothing shows up on my Saleae scope when I type on it, so that seems like a dead end for now.

However, I have the whole system working nicely from my laptop to the Master 128 -- I can type into a pygame window on the laptop, have the scancodes sent to a USB-attached MCU, which sends them to the CPLD that's attached to the Master motherboard. Very much enjoying that right now :)

Details over in the "standalone Master board" thread.
SW/EE from New Zealand, now in San Francisco: http://myelin.nz/
Having fun making hardware projects for the Electron!
So far: 32k flash cart, USB cart interface, 3-cart expansion, Elk PiTubeDirect. Later: Dual ported ram cart.


Return to “hardware”

Who is online

Users browsing this forum: No registered users and 11 guests