Ghosting and Masking

Note:  If you are seeing this note, then you are looking at an incomplete draft.  Keep checking back as I complete these series of blog posts over the next week or two.

A straightforward implementation of a scanning matrix works well enough when keys are pressed one at a time.  Pressing multiple keys at once can lead to ghosting and masking.

Ghosting makes it appear a switch has been pressed when in reality it hasn’t.  How does this happen?  Let’s examine the following scenario where the keys at (1,1), (1,3) and (3,3) are pressed simultaneously.

The controller starts by bringing column 1 low and since the switch at (1,1) is pressed, it brings row 1 low as expected.  Great so far!

Uh oh.  Looks like the switch at (1,3) is providing an alternate pathway to column 3, also bringing it low.  If you play a lot of Khet, all that follows should be painfully obvious.

Since the switch at (3,3) is also pressed, it brings row 3 low ahead of schedule; it shouldn’t be low until column 3 is actually selected.  The controller reads row 1 and row 3 as active and thus thinks a switch at (1,1) AND (3,1) have been pressed.

The switch at (3,1) has not been pressed, it’s just a ghost!  Hopefully that wasn’t the button for launching the nukes.

Masking happens in a symmetric fashion.  Imagine if you actually pressed the switch at (3,1) while still holding down the others.  If you were to release the switch at (1,3) it would still register as being pressed because pressing the one at (3,1) created a new ghost right at that spot.  This is the sort of thing that causes so many preventable deaths in the PC gaming world.

Fortunately there is an easy fix by incorporating diodes into the matrix so that current goes where it is intended.

Now let’s revisit the same scenario, only with the diodes inserted as previously shown. The diode at (1,3) becomes reverse biased, eliminating the alternate path along with any masking or ghost effects.

So now you know where babies come from… And why you see so many diodes in those joysticks you have been taking apart.

If diodes can fix this issue, why is the problem still present on keyboards?  Mostly because omitting the diodes saves on cost and the matrix is organized such that the problem doesn’t surface under typical usage.

Leave a Reply

Your email address will not be published. Required fields are marked *