{"id":101,"date":"2020-12-15T20:56:56","date_gmt":"2020-12-16T02:56:56","guid":{"rendered":"https:\/\/torensmith.com\/?p=101"},"modified":"2021-01-03T21:47:52","modified_gmt":"2021-01-04T03:47:52","slug":"keyboard-tinkering-part-5","status":"publish","type":"post","link":"https:\/\/torensmith.com\/?p=101","title":{"rendered":"Keyboard Tinkering, part 5"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">After discovering that the MCP23017 I2C-based GPIO expander was not going to be reliable, my first thought was to try out its SPI-based equivalent, the MCP23S17. In theory the same bug affecting the MCP23017 doesn&#8217;t affect the MCP23S17, and the communication overhead would be much lower because SPI is so much faster. I ordered some of these but haven&#8217;t experimented with them yet, because my other idea showed up first: the 74HC154, a 4-to-16 decoder IC, often used for memory address bus decoding. It has 4 input pins and 16 output pins; you set a 4-bit number (0-15) on the input pins, and it grounds the corresponding output pin while the rest remain high. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I really liked the idea of this chip not needing any communication protocol beyond 4 GPIO pins; it would eliminate the kind of problem I was having with the I2C-based expander, and should speed up the keyboard scanning loop. When I started working with it, I had two problems. The first was just an annoyance: the previous version of the adapter was cycling through the rows (via native GPIO), grounding one at a time (and leaving the rest floating), while reading in the 16 columns. This new method would be outputting the columns and reading in the rows, so I had to rework the somewhat-optimized code to all work in the opposite direction.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The other bump I encountered was more problematic. In the previous version, every time I switched which row was being scanned, I set the selected row to output low, and set all other rows to be floating inputs. Then the columns were set to input with pullups, so they&#8217;d register as low if they were connected to the selected row, and high otherwise. The reason the non-selected rows were set to floating inputs was because if you pressed two keys at once, it might connect two rows on the same column, and I didn&#8217;t want to short out a low and high output on the row pins. But the new decoder IC doesn&#8217;t leave non-selected outputs floating; they&#8217;re set as high. After testing, I confirmed what I feared, which was that the chip really did not like having those output pins shorted out.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The solution in this case was kind of brute-force: 16 diodes, one per output pin of the decoder, making sure no current could ever flow out of them. It could still flow in, so I could still detect when one of the rows was connected to the selected column. The breadboard prototype for this was messy with diodes, but it worked. (Side note: fancy new mechanical keyboard with NKRO (n-key rollover) have diodes at each keyswitch to prevent ghosting of keys, but these vintage keyboards do not. Ghost avoidance will be problem for future updates.)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Anyway, here&#8217;s what the PCB design for that looks like. Now I wait for the updated boards (and surface-mount diodes) to arrive.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a href=\"https:\/\/torensmith.com\/wp-content\/uploads\/2020\/12\/5aff43ecf86fdbeb1fefb8a74d3c4524.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/torensmith.com\/wp-content\/uploads\/2020\/12\/5aff43ecf86fdbeb1fefb8a74d3c4524.png\" alt=\"\" class=\"wp-image-102\" width=\"501\" height=\"226\" srcset=\"https:\/\/torensmith.com\/wp-content\/uploads\/2020\/12\/5aff43ecf86fdbeb1fefb8a74d3c4524.png 1001w, https:\/\/torensmith.com\/wp-content\/uploads\/2020\/12\/5aff43ecf86fdbeb1fefb8a74d3c4524-300x135.png 300w, https:\/\/torensmith.com\/wp-content\/uploads\/2020\/12\/5aff43ecf86fdbeb1fefb8a74d3c4524-768x346.png 768w\" sizes=\"auto, (max-width: 501px) 100vw, 501px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">(I have yet to spend the time to figure out how to make my silkscreen layer not be a mess in EAGLE, but the design should work.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After discovering that the MCP23017 I2C-based GPIO expander was not going to be reliable, my first thought was to try out its SPI-based equivalent, the MCP23S17. In theory the same bug affecting the MCP23017 doesn&#8217;t affect the MCP23S17, and the communication overhead would be much lower because SPI is so much faster. I ordered some [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[1],"tags":[9,6,7],"class_list":["post-101","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-keyboard","tag-nmb","tag-space-invaders"],"_links":{"self":[{"href":"https:\/\/torensmith.com\/index.php?rest_route=\/wp\/v2\/posts\/101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/torensmith.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/torensmith.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/torensmith.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/torensmith.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=101"}],"version-history":[{"count":2,"href":"https:\/\/torensmith.com\/index.php?rest_route=\/wp\/v2\/posts\/101\/revisions"}],"predecessor-version":[{"id":104,"href":"https:\/\/torensmith.com\/index.php?rest_route=\/wp\/v2\/posts\/101\/revisions\/104"}],"wp:attachment":[{"href":"https:\/\/torensmith.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/torensmith.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/torensmith.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}