Monday, February 24, 2020

The magic MC-10 keyboard trick

On the last episode of the CoCoTalk podcast (talk show?) the news section brought up the following video, where a BASIC program reads garbage from the keyboard when you wave your hand over it.


https://youtu.be/o6zssRDSjuE

I gave a brief explanation of why this happens on the show, but here is a little more detail about what is going on.


The Motorola 6803 is a microcontroller. It differs a bit from most 8 bit microprocessors because it has some built in hardware.  Parallel I/O ports, serial port, timer, etc...  To keep things somewhat simple, the MC-10 keyboard is wired to one of the built in parallel I/O ports.  The program shown above sets that port to input mode, and then it just polls the input port, and prints whatever comes in on the screen.

The way the keyboard is wired to the 6803, it forms it's own buss of sorts on the system.  The wires and circuit board traces form little antennas which pick up noise.  It's been a while, but if I remember right, the human body can induce a current of up to 1.8 volts.  I don't have a scope to hook up to it for verification, but that's probably what we'd see.  While the port on the 6803 was designed to work with 5 volt parts, it seems just sensitive enough to pick up that voltage as high signals.  Since the voltage isn't continuous on all the lines, the numbers change somewhat randomly.

If the keyboard had used a 2 layer board with a ground plane on the top side, and just passed the key connections through from/to the other side, this probably wouldn't happen.  Also, if the keyboard buss had resistors tying the keyboard lines to ground on the read side of the circuit, that weak noise would have been dropped to a level that the 6803 wouldn't read.  I don't think this was a matter of money, the engineer probably just didn't see it as a buss, so he didn't expect it, and this didn't show up in testing.

So why doesn't it cause a problem for BASIC?  The BASIC interpreter outputs data to the keyboard to choose which row of keys to check, it performs debounce which dumps inconsistent data, etc...
I don't think the debounce is helping.  More likely, the 6803's I/O port design can't read that low of a voltage under those circumstances, and that only happens when it's set just as input and you poll it, but that's a bit of a guess.

2 comments:

  1. It's not a problem for Basic because Basic doesn't use that port for input. Basic configures the port pins as outputs which are used to strobe the keyboard columns. Input comes from reading the keyboard rows which do have pull-up resistors.

    ReplyDelete
  2. Thanks!
    Yeah, I had forgotten that the keyboard was read from a memory mapped address. I did run into that while working on AGDx.

    ReplyDelete