2
\$\begingroup\$

I'm pretty rusty with electronics, so please forgive me this question. I've built a keyboard matrix with 15 columns and 5 rows.

The 5 rows are connected to GPIO pins on an Atmega 32u4 MCU. The 15 columns are connected to GPIO pins on an MCP23017 I/O expander.

The matrix is wired as 15x5 (well, a couple of over-size keys means that there are a couple of spots where the matrix is one row shorter, or skips a key in a given column).

The matrix is scanned in the usual fashion: row by row, set the row to Output/Low, then read the columns (this is done over i2c, reading back 16 bits for all of the pins "at once"), then reset the row to Input/High and continue.

For the most part this works fine, but there are some keys that don't register; these are in the final column and bottom row.

When I attach nScope to a key in row1 and press it, I can see the transition from logic-high to logic-low. When I repeat the same for lower rows I can see that the logic-low level gets higher (the trough gets shallower) as we get closer to the bottom.

I've attached a screenshot from nScope; the green trace is attached to the node labelled row5 in the schematic fragment included here. The orange trace is the other side of the diode, where the arrow points and says "floating". The square wave is due to the matrix scan selects/de-selects rows. The trace is without any keys being pressed.

SW3 in this schematic doesn't register when pressed, but SW5 (in the column above) does register.

My hunch is that the pull-up resistors for the columns are not right. I have tried with and without pull-resistors on the column GPIO pins; external 4k7 and then swapped those for the internal 100k pull-ups; the symptoms remain the same. Disabling the pull-ups just results in garbage as you might expect.

How do I debug this? What's the likely cause of this and what should I try to do to mitigate it?

schematic

simulate this circuit – Schematic created using CircuitLab

scope readings from row 5

\$\endgroup\$
  • 1
    \$\begingroup\$ Is that how you actually wired up the diodes? Looks wrong to me. \$\endgroup\$ – jonk Nov 23 '16 at 10:35
  • 1
    \$\begingroup\$ It looks like your adding the forward drops of the diodes. Closing SW3 would mean a drop of D3 and D1 before you get row5 signal. \$\endgroup\$ – JIm Dearden Nov 23 '16 at 10:49
  • \$\begingroup\$ deskthority.net/workshop-f7/brownfox-step-by-step-t6050.html is what I followed to physically wire things up. I may have transcribed that incorrectly to the schematic :-/ \$\endgroup\$ – Wez Furlong Nov 23 '16 at 10:56
  • 1
    \$\begingroup\$ There's no schematic there, but I can see that the diodes are wired okay. Did you notice that all of the black lines on one end of each diode are connected to the same long conductive rail in their picture? That's correct. Your schematic does it differently. So now I think we need to see pictures of what you actually DID DO. \$\endgroup\$ – jonk Nov 23 '16 at 11:00
2
\$\begingroup\$

Some keypads don't even use diodes. But you get ghosting then. So diodes are added. But the reason they are added is to isolate one switch from another. You've got the diodes chained in series.

Let me illustrate with an example similar to what you presented, using four switches, but done correctly:

schematic

simulate this circuit – Schematic created using CircuitLab

It should look more like that. Note that the diodes don't form a conductive path that proceeds through more than one of them at a time.

\$\endgroup\$
  • \$\begingroup\$ ah, I think the problem is that my oversize switches are wired wrongly, but the rest look like this. I'll verify and come back to this; thanks! \$\endgroup\$ – Wez Furlong Nov 23 '16 at 10:59
  • \$\begingroup\$ @WezFurlong Okay. That could be the problem. \$\endgroup\$ – jonk Nov 23 '16 at 11:02
  • 1
    \$\begingroup\$ Yep, that was it; the bottom row had a number of oversize keys and they were all hooked up badly; all fixed now, thanks! \$\endgroup\$ – Wez Furlong Nov 23 '16 at 12:14
0
\$\begingroup\$

The wiring of the diodes is not correct for a matrix keyboard. The kathodes of the diodes of every row must be connected toghether to obtain a diode "or" logic function, not to the anode of the subsequent diode. If you connect the diodes as in your schematics, you will add the diodes forward drop voltages, and after some columns you will not be able to have a high level.

\$\endgroup\$

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.