1
\$\begingroup\$

I'm designing a keyboard. I found some information online about how to make the keyboard be able to detect multiple key presses at the same time (N-key-rollover).

I found this schematic, from this website.

schem

The website says that A and B are the two inputs, and 1 and 2 are the two outputs. I'd select A, then read the values at 1 and 2, and hence know which keys are currently pressed, then do the same with B.

The diodes are to prevent false-positive keypresses. The website explains this in more detail.

What I don't understand, is how 1 or 2 would ever be high? Let's assume A is high, and the bottom left switch is closed, surely its diode is still opposing the current flow, right? How would any current flow to 2?

Is this a matter of conventional vs. electron current flow? Because that always confuses me, but I just can't figure this out.

EDIT, this is active low.

\$\endgroup\$
  • 2
    \$\begingroup\$ Is this for active-high or active-low logic? \$\endgroup\$ – Hearth Oct 11 '18 at 21:36
  • \$\begingroup\$ @Felthry whoops - post edited, sorry for leaving that out. \$\endgroup\$ – Jacob Garby Oct 11 '18 at 21:38
  • \$\begingroup\$ (and where I said "let's assume A is high", I mean when it is selected, or active) \$\endgroup\$ – Jacob Garby Oct 11 '18 at 21:38
1
\$\begingroup\$

A pull-up resistor is required on both pins 1 and 2. These will weakly pull the output pins high. Additionally A and B are either driven high or low depending on which column you are wanting to scan - driving low enables a column, driving high disabled a column.

If input A say is driven low, and outputs 1 and 2 are pulled weakly high by a resistor, then you basically have a circuit that is nothing more than two push buttons. You can read the values of 1 and 2 to see if the button is pressed or not.

If input B is driven low, you again have two push buttons which can be checked by reading 1 and 2. Again the outputs are weakly driven high by resistors.

By constantly swapping between B and A being driven low, you can read all four buttons using two pins.

The diodes prevent the buttons in column B from being registered if you were to push multiple buttons simultaneously (e.g. pressing all of A1, B1, A2 simultaneously would otherwise pull B2 low).

The reason the pull-up resistors are not shown is that these are typically present internally in the microcontroller used to read the array.

\$\endgroup\$
  • \$\begingroup\$ That makes sense. Thanks for the quick answer! I'll accept it as soon as I can. \$\endgroup\$ – Jacob Garby Oct 11 '18 at 21:43
  • \$\begingroup\$ @Jacob: Tom won't mind me saying this but wait a day or two to see what other answers come in. You will get other points of view and maybe some other insights. When you accept too quickly it discourages others from answering. You can usually upvote as well. \$\endgroup\$ – Transistor Oct 11 '18 at 22:01
  • \$\begingroup\$ @TomCarpenter I'm sorry for bringing this up again, but I can't get my head around why the diodes appear to be the wrong way around, to me? \$\endgroup\$ – Jacob Garby Oct 14 '18 at 12:52
  • \$\begingroup\$ Or in other words, how would any current at all flow from the columns to the rows? \$\endgroup\$ – Jacob Garby Oct 14 '18 at 13:09
  • 1
    \$\begingroup\$ The diodes are the way round they are because you are driving A or B low. 1 and 2 are pulled high, so current needs to flow from number to letter. \$\endgroup\$ – Tom Carpenter Oct 14 '18 at 13:42

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.