Hall Effect Keyboard Sensing and Wiring Explained

User avatar
dorkvader

28 Jan 2018, 20:56

Cross post from Geekhack https://geekhack.org/index.php?topic=93775.0
Hi all, I've been getting some questions about hooking up hall effect keyboards so we can actually use them. Here is an explanation of two ways of doing sensing. Method #1 is 2KRO and #2 is NKRO. Both have their advantages. Vintage keyboards (usually) use the 2KRO method, and I am currently wiring my keypad prototype as NKRO. First some properties of the switches.

Hall effect switches were manufactured by microswitch (honeywell) from 1968 and were used in normal keyboards until the mid-1980's and for industrial automation until at least 2005. They are usually operated by 5V in keyboards and output a signal that's close to that from 2 output pins when pressed (note: some hall effect switches only have 1 output pin. They are not covered here. Some switches, especially for those in keypunches only output a pulse and not a continuous signal. these are also not covered here). Note that there are two main versions of the switch, an older "rail mounted" style, and a newer "sealed" style. These techniques should apply to both (but I think the older style requires more current)

Edit: here's a topic where I go over the electrical considerations of the switches https://geekhack.org/index.php?topic=87453.0

OK First method: 2KRO.
Pros:
  • Use the circuit in place (no major PCB modification required)
    Much quicker and easier
Cons:
  • Only 2KRO (possibly only 1KRO on some keyboards but these are likely rare)
    Requires custom controller code (need to wire for sense/sense operation)
Circuit description: Every switch has the 5V and Ground connections connected all in parallel, so they are all powered all the time. Switches have one output all connected to eachother and the other output all connected. While it doesn't "look" like this on the PCB, logically we can consider these as your traditional "Rows and Columns" style keyboard matrix. When a switch is pressed, you see +5V on both the outputs, so you can sense 5V on one of the rows and 5V on one of the columns. This is why its sense/sense configuration. A standard keyboard is sense/strobe, where it sends a 5V strobe through one of the columns, and senses what you get back on the rows. Almost all keyboard operate in this type of model (contact switches, capacitor, I think some inductive keyboards, but not others, etc).

Edit: many hall effect keyboards are wired with one output of switches connected to rows and the other to columns but not all of them are.

Here's some pictures I made to help explain
Image
This is how they are wired. It's a little hard to see, depending on how well you can read schematics. I created a custom hall effect sensor component and laid out everything in LTSpice. Here you see all the 5V and the ground pins of the switches connected together, and all output 1 collected in columns and output 2 connected in rows. Next we will see what happens when a switch is pressed.



Image
Here we see what happens when Switch at R2 C2 is pressed. You can see voltage going out on one row (red line) and one column (green line). The controller would detect this and recognize the switch is pressed, sending the proper keycode to the computer. The power and ground lines are all active, but I didn't highlight them for the sake of simplicity, All the other rows and columns have 0V on them because no other switches are pressed.



Image
Here we see two switches at R2C2 and R2C3 pressed. Since they are the same row, the red line at row 2 has 5V coming out of it, and the green lines at Rows 2 and 3 have 5v coming out of them. The controller would detect this and output both keycodes to the computer. Again All the other rows and columns have 0V on them because no other switches are pressed.




Image
Here we see two switches at R2C2 and R1C2 pressed. Since they are the same Column, the green line at column 2 has 5V coming out of it, and the red lines at Rows 1 and 2 have 5v coming out of them. The controller would detect this and output both keycodes to the computer. Again All the other rows and columns have 0V on them because no other switches are pressed.



Image
Here we see an example of blocking, If three switches at R1C2 and R2C2 and R2C3 are all pressed, we have two rows with 5V coming out of them and two columns with 5V coming out of them. The controller cannot distinguish if the switch at R1C3 is pressed or not if the other 3 are pressed, so in this case we see that the keyboard's physical matrix only supports 2KRO. You can also see that this 2KRO sense/sense technique is much the same as a standard sense/strobe 2KRO technique, with the exception that the columns have 5V coming out of them, instead of having 5V coming in.

Note that you can just hook this up to a standard keyboard controller and it won't damage the switches, but since the controller is outputting 5V on the columns and the keyswitches are also outputting 5v on the columns (when pressed) the controller will not be able to detect which keyswitches on the columns are pressed, it has to sense both rows and columns for keypress events.

How to modify a keyboard that is wired this way to a modern controller? you would first wire the 5V up to power/ground (USB power should be sufficient, but I recommend an external USB charger for testing) the map out the matrix and wire up one pin output to columns and the other output to rows. Note that in some keyboards, they will have pin 1 of most switches connected to all rows, and then have pin 2 of like 2-3 switches connected to rows, the other pin output is on columns. So be careful when wiring the matrix. Then cut the power to the on-board microcontroller and cut the wires to the keyboard sense circuitry (usually a bunch of pull-up resistors) so all that is isolated form the keyswitch matrix. Then you would program the matrix into your microcontroller firmware and then change the input detection from strobe.sense to sense/sense. In this configuration a scanrate has no meaning, because it is sensing all the time. Since hall sensors settle much faster than traditional switches you would have much higher performance.

*note* if anyone would like to help me modify a firmware like Kiibohd or TMK in this way I would greatly appreciate it. PM me for details but be aware I'm not on GH that much, and working fulltime while taking classes, so I won't have a lot of free time.

---------------------------------------------
Method 2 NKRO.
This method takes advantage of the fact that when switches are off, they have no output. It's like a switch behind a diode for a standard NKRO keyboard. So what we do now is to power only a single column of switches at a time, read what's coming on the rows, then power it off and repeat. This is pretty much exactly the same as how a standard keyboard works, it sends a voltage output to the columns and then senses the rows for voltage back, which it will get for any switch pressed in the row. For this reason we can theoretically use unmodified keyboard controllers and firmware for this However it requires some hardware mods. First a circuit description.

Edit: here's a topic where I have started modifying a keyboard to this version https://geekhack.org/index.php?topic=89262.0

Here we have the ground pins all connected to eachother, and the power pins are connected together to columns. The switch output pins are connected to rows. You can connect both outputs together for added reliability if you want (some keyboards do this, some have one output floating. more on this later.) Note you nly need one of the two outputs for this method. The power pins are all connected to the controller, which turns on one column with a voltage strobe, and reads back what it gets on the rows to see if any key in that column is pressed. Then it turns on another column and reads again. *note* you can't just connect the columns to a controller and expect it to work. More on this later. Here's a circuit diagram


Image
Here we see all the switch grounds connected, the power pins are connected to columns, and both switch outputs are on the rows. Let's go through a sense cycle to see how this works.



Image
Here we have switch at R1C3 is pressed, and C3 is currently being strobed by the controller. You can see R1 is active (5V out) and R2 is not (0V out). The controller senses this as Switch R1C3 is pressed and sends the appropriate scancode. In this example you could also be pressing any switch in C1 or C2 and no output would occur since the switch is off (unpowered). I have drawn little arrows on the power line because it is taking voltage IN from the controller.



Image
Let's assume, we are still pressing R1C3 and the controller moves over to the next column.
Here R1C3 is pressed, and column 2 is currently being strobed by the controller. Again I have lit up the red line from the controller with arrows pointing in because power is coming out of the controller and in to the switches here. Nothing is pressed in C2 so none of the lines have output. Even though R1C3 is pressed, there is no output because the switch is off. I hope you can see now how NKRO occurrs. You can just wire the switches up on rows without diodes and it'll work this way because an unpowered switch has no output.


Now unfortunately you can't just wire up a matrix of switches this way very easily. Let's look at electrical considerations. The reason this is the case is because each switch is an active component and consumes power when it's unpressed and even more power when it is pressed. Whatever is strobing the columns here has to be able to power a full column of (usually 5-6 depending on what sort of matrix you are using) switches, which each consume power (see my other thread about how much, and in what circumstances) and most microcontrollers can only output enough current to power about 2 switches reliably. So if you try to wire up a whole column of switches, the controller cant power them all and you risk damaging the controller or (more likely) they just won't work, The switches will probably be undamaged / unaffected, since they are quite hardy. So how to get NKRO to work? You will need some way to amplify the current coming out of the microcontrolelr pins, and you can do this with transistors! Here's an example circuit diagram with NPN transistors on the high side of the switch.

Image
Here we have the same NKRO example as above, but with transistors on each of the power rows. Here the microcontroller columns are connected to the vertical lines and turn the transistors "on" thus sending power to that line of switches and making them work. Other details such as biasing resistors for the transistors are left as an exercise to the reader (in practice I found out they can be omitted, with the only resistors needed are pullup resistors on the outputs more on this later). Now the basic idea is the microcontroller turns the resistor on which sends power from the 5V rail to the column in question. I haven't had transistor theory in classes yet so I might have wired it wrong or picked the wrong kind of resistor. The operation is the same as the above.

Wiring considerations. This is much more difficult than the above. This is because the switches have to be PCB mounted. You could in theory wire up the sealed type without the PCB, but the sensors can slide out of the switches, so you are just relying on some friction to hold it together. The rail mounted type has no contact between the sensor and the magnets whatsoever, so a PCB is fully required here. So you have to keep the PCB, but since the wiring is different, you have to cut (or drill) every connection from the switch's power pin to the power rail, then get some wire and solder it to every switch thereby creating columns for your controller to strobe (through transistors). Then you have to wire up the rows to form a matrix. In practice this usually means you have to cut (or drill) those traces too so that you can make a matrix of your choosing. Here you can either connect both outputs together, leave one of them "floating" or connect the unused output to ground through a resistor. Best practice would probably be #3, and #1 takes a bit more effort, but you see many examples of keyboards wired up as #2, so its up to you to leave it like that if you want. If you're getting weird errors in testing, then you can try to ground unused outputs or connect them to used ones to fix issues. Then you have to wire up all the columns to transistors, then to the microcontroller. I was thinking of making a PCB with transistors on it that you could use as a strip, but that takes time and I havent done it yet, but this would make it a lot easier for people to wire it up for the various myriad of keyboards out there.

Note that the BUD Honeywell Hall effect keypad was successfully wired up to a teensy and working without any of this. I believe it is wiring the switches up in a 1*16 matrix, which is perfectly suitable for a small keyboard like that but of little use to larger keyboards.

--------------------------------------------
OK SO I have gone over two methods of wiring. There is one other thing that is important, and that's what to do with the output. In practice the output of these switches is quite poor, if you just try and measure it outright, so you need to connect them up with a pull-up resistor to the input of your controller. I am told that the teensy has internal pull-ups, but I have not tested this yet. Most of the keyboards you see have pull-up resistors, and I have soldered mine in for testing purposes on my prototype.

Note, that with pull-up resistors the output is inverted, so it's High (5V) when the switch is unpressed, and low (0V) when it's pressed. You could run this through an inverter before the controller, or program the controller to accept inverted input.

Controller selection. I have been asked about wiring these keyboards up to an xwhatsit controller. Since the xwhatsit operates as a sense/strobe style, you would have to do method 2, drill and re-wire the PCB, and solder transistors on the strobe outputs to power the columns. You would also have to make sure the xwhatsit can read the voltage coming out, or you may also need pull-up resistors on the outputs, and then you would have to invert it. You could just enable the internal pull-ups in the controller and program it to invert the signals, and it would work, but if you are OK with 2KRO this can be achieved much more easily with method 1 (and a standard teensy controller running firmware with a customizeable sense/strobe section that you could reprogram to sense/sense operation.)

Another thing to consider for using a standard controller is that it takes some "time" to power the column on before it will output. it also takes some "time" (dure to capacitance) for the output to turn "off" after the column is depowered. I don't know how the controller works, but you would want to have a bit of "time" in between when a column is depowered and when a column is powered, otherwise you will get one erroneous keypress every time a column is switched. This might be unnecessary, since it takes a bit of time to power on the new column, but it would definitely require some testing.

Other considerations: You can operate a hall effect keyswitch at least 2 orders of magnitude faster than a standard contact-based one because there is no "ringing" or debouncing to do, and the output ramps up and settles extremely quickly. So you could operate it with a 60KHz scanrate instead of a 1KHz one common in contact based keybaords today. The "hall effect sensing and application" article by Honeywell indicates that you can operate them at a 100-KHz scanrate, but I have not been able to get more than about 60 KHz in practice. I'm hoping to learn more about High speed circuits to see why this is the case). This is because the hall effect switches are schmitt triggered, so they have a little built in hysteresis. Theoretically you can do the same with other inherently linear switches like capacitance based ones. SO even if you are using method 2 and have to wait for a bit between pressing columns, you can still operate it 10 times faster than a contact-based keyboard and have some comfortable amount of headroom. They also have no contact so they are rated for 30 Billion keypresses. I have tested them underwater, and they can take voltage inputs of up to 30V and still work fine. Overall they are excellent switches, which are sadly only linear. I hope to include a solenoid in my keyboards in the future to add some of the delightful clickety-clack.

That's all for now!
Last edited by dorkvader on 28 Jan 2018, 21:38, edited 1 time in total.

User avatar
Techno Trousers
100,000,000 actuations

28 Jan 2018, 21:12

Wow, nice detailed write-up. I haven't gotten involved in the "under-the-hood" stuff like this, but I'd like to someday when I have the time to devote to it.

I think you have a typo here, or I really need some further explanation ;D :
The reason this is the case is because each switch is an active component and consumes power when it's pressed and even more power when it is pressed.

DMA

28 Jan 2018, 21:25

Wouldn't you kill the switches quickly turning them on and off all the time? They're probably not rated for 30 billion power cycles..

User avatar
dorkvader

28 Jan 2018, 21:37

Techno Trousers wrote: Wow, nice detailed write-up. I haven't gotten involved in the "under-the-hood" stuff like this, but I'd like to someday when I have the time to devote to it.

I think you have a typo here, or I really need some further explanation ;D :
The reason this is the case is because each switch is an active component and consumes power when it's pressed and even more power when it is pressed.
From here:
https://geekhack.org/index.php?topic=87 ... msg2356487
When they are not pressed, they were measured to consume 1.3 mA, and when the switch was pressed, they were measured to consume 4 mA.

SO the first bit should say "unpressed" I will update!
DMA wrote: Wouldn't you kill the switches quickly turning them on and off all the time? They're probably not rated for 30 billion power cycles..
Most likely not. I am not 100% sure, but I believe this system is already used for some hall effect keyboards with only 1 output pin. Even if i does degrade the switch, the effect will be more pronounced at the higher operating voltage of 25V or the absolute maximum rating of 30V than the low 5V range we are using here.

It would be easy to test. I can hook up a switch to the signal generator, and run a 60 KHz square wave through it, which would get to 30 billion after only 6 days. I'll start that now.

edit: putting a 5V 1.9 MHz signal (the limit my generator can do) through it now. I can't detect keypress events faster than about 40 KHz but it's definitely rapid cycling the switch electronics. I have some tape holding it on the "pressed" state (which consumes more power). I'll check on it later.
Last edited by dorkvader on 28 Jan 2018, 22:45, edited 1 time in total.

DMA

28 Jan 2018, 21:50

Another option would be to connect switches to demultiplexor or PISO shift register.
Or just dedicate it's own GPIO pin to every key :)
https://www.mouser.com/ds/2/308/NLHV4051-D-1107585.pdf - 8-channel demux, 25 cents @100

User avatar
dorkvader

28 Jan 2018, 22:57

DMA wrote: Another option would be to connect switches to demultiplexor or PISO shift register.
Or just dedicate it's own GPIO pin to every key :)
https://www.mouser.com/ds/2/308/NLHV4051-D-1107585.pdf - 8-channel demux, 25 cents @100
That would work, but has a delay of 600 nS max (at 5V)! The gamers are going to miss their FPS at this rate :lol:

The real issue here is that the keypress event has a short "spike" before it goes high. See here:
Image So you would have to add a resistor to get that peak under the threshold voltage for the demux, or... Actually you could take care of it with a standard debounce algorithm. It already operates much faster than the debounce algorithm is supposed to, so it would totally work. It's also very repeatable, so you could easily just program the controller to ignore the first peak, which is only about 0.25 us wide (divisions are 0.5 us apart in that scope shot)

One of the good design points of these switches is that they output logic directly.

Unfortunately I don't know how to program a controller for that!

Slom

28 Jan 2018, 23:06

Awesome write up, will take a closer look at it on my next free weekend :)

For now I just wanted to note that some micro switch SD switches offer a third option: these have one of the inner pins as input and the other as output. Specifically I'm talking of the switches with a S in the last place of the part number (S is for "logical scan"). And even more specifically the keyboards of TI silent 700 line have these inner pins wired as a matrix.

TLDR: please don't modify TI Silent 700 pcbs with 1A3S/1A8S switches just to get NKRO, it's just not needed

post397958.html

User avatar
Daniel Beardsmore

28 Jan 2018, 23:45

I'm surprised though how many keyboards did use the 3-pin SD series switches. Originally I thought it was some cheap option that came along later, but it seems even the Space-cadet keyboard is 3-pin, based on the part numbers. That's assuming that we are understanding the part numbers correctly, as the 'E' type (3-pin) isn't covered in the official documentation that we have.

User avatar
dorkvader

29 Jan 2018, 00:07

Daniel Beardsmore wrote: I'm surprised though how many keyboards did use the 3-pin SD series switches. Originally I thought it was some cheap option that came along later, but it seems even the Space-cadet keyboard is 3-pin, based on the part numbers. That's assuming that we are understanding the part numbers correctly, as the 'E' type (3-pin) isn't covered in the official documentation that we have.
That's the second KB I know of that has the 3-pin. The first is some KB HaaTa had in his apartment. You can see pictures of the Symbolics KB PCB here: http://www.asl.dsl.pipex.com/symbolics/ ... nside.html
This was before webwit got his.

Slom

29 Jan 2018, 00:17

According to the Micro_Switch_SD16_Keyswitch_Modules.pdf the three-terminal modules also explicitly support a scanned mode.

DMA

29 Jan 2018, 00:42

dorkvader wrote: The real issue here is that the keypress event has a short "spike" before it goes high. See here:
Image So you would have to add a resistor to get that peak under the threshold voltage for the demux, or... Actually you could take care of it with a standard debounce algorithm.
That demux is fully analog. It doesn't care about your logic levels. It will just forward the signal to your GPIOs, where you'll read it.
But yes, you'll need a debouncing algorithm. Or a series resistor between demux and MCU with capacitor on the MCU end of it, to eat that peak. Will slow down the scanning though - after selection you'll need to wait for the capacitor to charge before you read.
-=-
Slom, good catch! So just a bunch of transistors on a low side is needed.

User avatar
XMIT
[ XMIT ]

04 Apr 2019, 17:12

You can do this. The other simple solution is to just have each Hall sensor drive a FET and then scan it like a plain old matrix.

Post Reply

Return to “Workshop”