Stupid keyboard, stupid shift; a proposal for better key sensing


On my Apple keyboard (the white wired one, circa 2003, with an ergonomic curve to it) if I press both Shift keys down then it disables most of the QWERTY row. I guess this is some sort of ghosting or masking. Is it useful to be able to separately detect the two Shift keys? Why aren’t they wired on the same row/column intersection? That would eliminate this sort of masking. This makes me think far too hard about keyboard wiring designs and microcontroller pin minimisation. Observation: pin minimisation is the root of all keyboard misdesigns (well except for problems with the actual shape, action, and layout of the keys).

The Matrix

Electrically, keyboards are arranged in a matrix of rows and columns with a switch (corresponding to an actual key) at the intersection of each row/column pair. Depressing a key closes the switches and forms an electrical connexion between the row and the column. A microcontroller uses a scanning algorithm to detect key presses: it regularly scans the rows and columns by driving each row bus in turn and sensing each column bus to detect which keys are depressed. Warning: this description is made up by me based on my ancient knowledge of the ZX81 hardware design. I have no idea how modern keyboards work, but it’s probably something very similar. Probably you can get a single chip for USD 1 that does all this driving and sensing of the matrix, has a register and some LED drivers for the Caps Lock light, and a USB interface all in one. I suspect Apple have very little choice in how the electrical wiring of their keyboard is made.

The number of microcontroller pins I need for a keyboard of N keys is p+q where p×q ≥ N. If we assume that the cost of a microcontroller is proportional to the number of pins it has, then we would do well to minimise the number of pins we require for the keyboard matrix. For a 40 key keyboard (the ZX81) an arrangement of 8 rows and 5 columns is optimal. This comes about because we can only place one key at the intersection of each row and column. If we try and place two or more keys at the same intersection then the scan algorithm can’t differentiate between them.

However if we can somehow differentiate between two or more keys at the same intersection then we could put more keys per intersection and thereby reduce the number of pins we require.

Capacitance is Key

Suppose we put a capacitor inline with each switch. Now when a key is depressed instead of a closed circuit between a row and a column we get a resonant CR circuit. We can still use the scanning algorithm, but instead of driving the row bus with a constant voltage we drive it with a periodic signal. Obviously we should choose the period so that the CR circuit passes it. A 1.5 MHz square wave might be a good choice for a keyboard because we can get this from the clock used for the USB interface (12 MHz divided by 8). If we put different value capacitors on different key switches and drive the row with two different frequencies (1.5 MHz and 0.75 MHz say) then we can now detect two different keys at the same row/column intersection. We scan once at 1.5 MHz to detect one set of keys and scan again at 0.75 MHz to detect another set of keys.

For our ZX81 example with 40 keys we would need only 20 intersections which we can do with 4 rows and 5 columns, reducing our pin requirements from 13 to 9 pins. Awesome!

In general we save about 30% going from 1 key per intersection to 2 keys per intersection: we go from about 2×sqrt(N) pins to about 2×sqrt(N÷2) or sqrt(2)×sqrt(N). sqrt(2)÷2 is of course about 0.7.

More keys per intersection means greater savings, but also requires more frequencies, slower scanning (because each frequency requires an extra pass), and more stringent rejection requirements in the CR circuits.

For a really cheap and nasty keyboard, instead of having an open/closed switch inline with a capacitor simply make the keybaard so that two metal plates are brought close together when the key is depressed. The two metal plates form a capacitor whose value can be controlled by changing the area of the metal plates. (In fact, don’t really cheap and nasty keyboards use this principal already?) The challenge would be to reliably detect keys with different capacitance.

2 Responses to “Stupid keyboard, stupid shift; a proposal for better key sensing”

  1. Clive Says:

    I’m not sure you can depend on the capacitance of a key to be sufficiently repeatable, let alone sufficiently stable over the switch’s lifetime for this to work, sadly. Using the keyswitch itself as a variable capacitor would be tricky: firstly, it would involve wiring a conductor to the moving part of the keyswitch where in current designs the moving section joins two fixed pads (i.e. it’s really two switches in series) and secondly the one of the switches half-closed would be indistinguishable from the other fully-closed.

    The simple way to avoid masking and phantom problems is to place a diode in series with each switch, but people would often rather not pay the price.

    Thinking about this more, for simple circuits the pin count and package count are the expensive things, not component counts within ICs: adding 40 ICs and 80 pins for the capacitors to save four pins on the microcontroller is probably a false economy.

    Maybe it would be cheap to scatter a few parts around the board each of which handled, say, eight keys? If you were truly desperate to preserve pincount, they could use a two-wire powered bus – for forty keys that would mean five ten-pin devices plus two pins on the microcontroller for a total of 52 pins compared with 89.

    The fact this hasn’t happened implies that the cost of microcontroller pins is small compared with plastics, mechanics and the sea journey from China.

  2. drj11 Says:

    on making a cheap and nasty version: you could avoid wiring a conductor to the moving part by treating it as two capacitors in series (much like the original switch is two switches in series). The problem of the half-open switch could perhaps be solved mechanically. Most keyboard switches have the feature that a minimum closing force is required thereby ensuring that the switch stays is an “almost-closed” state for as little time as possible. Software could eliminate the momentary aliases where you were unlucky enough to scan a key just as it was in the position where it looked like it was the other sort of key. These are all the sorts of reasons why I said “challenge”. On the whole I agree, not a go-er.

    Capacitors come in packages right? So I’m not adding 40 components for 40 capacitors, more like 4 (packages of 10). That doesn’t change the number of pads of course.

    We could throw away all the capacitors and use LR circuits by making little inductors out of spiral shaped circuit board tracks.

    As you say, it’s all currently swamped by other factors.

Leave a Reply to drj11 Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: