0
\$\begingroup\$

I'm trying to add an USB keyboard to an old 8-bit Amstrad CPC 464 home computer, like is done here.

To make a brief summary:

The keyboard is designed as a matrix with 10 lines and 8 bits per line, where each bit indicates the state of a key.

enter image description here

The scan of the keys must be done in sw by polling. The process, described here in detail, consists on the the CPU configuring the PPI (Programmable Peripheral Interface), first to output the keyboard line to scan on lanes C0-C7 and, second, to read the results from the A0-A7 lanes, which are connected to the PSG (Programmable Sound Generator) which also acts as a keyboard interface.

Here is an excerpt of the schematic with the involved parts: enter image description here

The problem I'm facing is with the 74LS145 decoder. The original keyboard works well, so there's nothing broken. I'd expect to see the polling on the decoder input lines and the outputs changing accordingly, one output activating at a time indicating the selected keyboard line. All of that regardless of any key been pressed on the actual keyboard. But, although I see that the polling is done and the ABCD input lines change, the output ones are always L as long as I do not press any key. It's like the decoder would only be enabled if a key is pressed, but I don't see any enable pin on the decoder.

How can it be? The behavior of the decoder is simple, it just reacts to its inputs selecting one of the outputs. I don't see how output can depend on anything more than that...

\$\endgroup\$
3
\$\begingroup\$

From your data sheet link:

These devices feature high-performance, n-p-n output transistors designed for use as indicator/relay drivers or as open-collector logic-circuit drivers.

In other words, they are open-collector devices which can only sink current by driving low; a high output state would only be achieved by something else sourcing current.

In your keyboard case, that "something else" would probably be pull-up resistors on the input side of the matrix, which only get connected through when as keyswitch is closed. If you look at the row drivers when no keys are closed, you see a confusingly identical situation where the outputs change between being "off" and "low" - which doesn't look any different.

To detect which output is being driven when the switches are all open, you could add your own weak pullups to source current. But it's probably better that you just monitor the smaller number of address lines.

Presumably, what you are doing here overall is hosting the USB keyboard with an MCU having a USB host port, then monitoring the scanning of the target system, and planning to inject an appropriate keypress by driving an input line low at the right time. Depending on how consistent the behavior of the target system is, it's possibly you might get away with only monitoring one select line and predicting the timing of the others from that; but if it is software scanned or otherwise inconsistent you probably need to monitor all four - or else change the keyboard handling software to accept input by some other means, like a serial port.

\$\endgroup\$
1
\$\begingroup\$

Since the 74LS145 is open collector a key must be pressed to rise the output to high (current comes from the sound generator chip).

\$\endgroup\$
  • \$\begingroup\$ Open collector would pull a high signal low, and at any one time only a single output of the '145 is low. Presumably the sound generator chip must have built in pull-ups on its inputs, since I dont see any pull-up resistors in the schematic connected to these lines. \$\endgroup\$ – Tom S May 11 at 22:04
  • \$\begingroup\$ Either that, or those lines are outputs. \$\endgroup\$ – Warooze May 11 at 22:30
  • 2
    \$\begingroup\$ Yes, the AY-3-8912 has internal pullups. \$\endgroup\$ – Bruce Abbott May 12 at 1:46
  • \$\begingroup\$ The schematic has arrows which seem to be indicating signal flow direction. They are pointing out of the '145 and in to the sound generator chip, so I dont think they are outputs. If the keys of the keyboard are normally closed, and thus always causing the inputs of the sound generator to be pulled low by the '145, and pressing a key makes them normally open thus allowing the sound generator to see a high, then I think you have a point. But the keyboard schematic in the service manual seems to be suggesting they are normally open. \$\endgroup\$ – Tom S May 12 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.