Skip to content

Ghosting on some keys when using keypad.KeyMatrix. #7621

@SeanCline

Description

@SeanCline

CircuitPython version

Adafruit CircuitPython 8.0.0 Beta 6.

Code/REPL

https://github.com/SeanCline/RabidKeyboard/blob/main/firmware/code.py

Behavior

I designed and built a keyboard using the KMK firmware. After using it for a few months, I noticed some weird ghosting on two key combinations.

  • When pressing LeftGui and LeftShift, LeftControl sees a phantom press.
  • When pressing A and Tab, CapsLock sees a phantom press.

Description

Looking at the matrix schematic, you can see a pattern here. Enabling KMK's logging, this phantom keypress seems to happen on every other scan of the matrix. Very strange!

Normally, when ghosting is involved, you'd suspect the diodes. But, since only two keys are required to trigger the phantom press, I cannot think of any way a diode could be to blame.

Additional information

So, I started reviewing the KeyMatrix scan logic and I noticed that it scans as fast as possible. At the end of each scan, it asserts the resting state of the row and switches to a pulled input before moving onto the next row. This logic was added by @dhalbert a couple years ago.

I suspect this final bit of logic important, but is happening too fast to discharge any stray capacitance and/or trace inductance of a bigger key matrix. When the next row is scanned, the column input still briefly sees the previous row's value. This makes some sense because the two ghosted keys are on the furthest column from the microcontroller.

I have a solution for my keyboard. After scanning each row, I check the columns a few times to make sure they've settled to their resting value. See this diff: main...SeanCline:circuitpython:main
Perhaps somebody might have a better solution, but I think stray capacitance/trace inductance is to blame, and hopefully it's possible to make the matrix scanner more resilient to it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions