Selecting a MCU for Keyboard - Page 1
Forum section: electronics / general

author: ajo518
author_rank: Contributor
timestamp: June 04, 2019, 12:54:50 am
content: Hi guys!I'm trying to decide on what brand / architecture of chips I should be using. I plan on making a custom pcb for both of these projects, but it is always nice if there is a dev kit that I can use to start out with, but it is not necessary.I'm working on two related keyboard projects.1) A keyboard based off of a Lenovo T420 keyboard with usb and or Bluetooth interface2) full custom mechanical keyboard with bluetooth or usbplan on making a custom pcb for both of these projects, but it is always nice if there is a dev kit that I can use to start out with, but it is not necessary.I have worked with pic for school and have a pic kit 3. I liked it ok, but it seemed a little bit of a pain to get all the registers configured correctly, but that may just have been part of the learning curve.At work the mostly use arm MCU's which I am not directly involved with, but would like to learn about and possibly use GCC.I am confident in being able to select the correct chip from a given family (peripherals etc.), but I'm not sure of what the "best" family is. I'm thinking of pic, atmel, or arm. (there may be others that I have missed).I know pic has the pic kit and mplab which is free, but do the other families have free dev software? Are the In circuit programmers expensive?I know there are firmware's in existence to do exactly what I want, but I want to write my own mainly just for the experience. (and of course I can always look at the others for inspiration if needed)I know there is no silver bullet, but I would like to hear some opinions. I also would like something that is expandable to other things as well.Any advice would be greatly appreciatedThanks!

author: lucazader
author_rank: Regular Contributor
timestamp: June 04, 2019, 01:47:54 am
content: Plenty of options out there.I would advocate for an arm based system if you are wanting to get into learning gcc based tooling.Quite a few of the arm manufacturers have free IDE's which use gcc under the hood which might allow an easier transition for you.I would suggest the stm32 series. Their nucleo dev boards are super cheap (between $10-20 USD for most) and come with a build in st-link.You can generate projects using their stm32cubeMX. Which you can even setup with USB device with the HID class already up and running.But this is just what i am used to.Im sure other people will present other just as valid options momentarily.It might be good to get a dev board or two and see which one you like playing around with the most.

author: wraper
author_rank: Unknown
timestamp: June 04, 2019, 01:55:48 am
content: EFM8UB series would do USB very cheap + you can get free VID/PID from silabs and examples available. And you need is only a few decoupling caps to get the thing going, internal 100mA 3.3V vreg included. Free IDE, easy to debug. Dev board IIRC costs about EUR 30, includes built in J-link which can program/debug external devices as well. Standalone debugger costs about the same.

author: NorthGuy
author_rank: Super Contributor
timestamp: June 04, 2019, 02:07:27 am
content: Of you've already worked with PICs - PIC16F1454: about $1, requires only couple capacitors to connect to USB. If you need more pins and analog there's 20-pin PIC16F1459.

author: wraper
author_rank: Unknown
timestamp: June 04, 2019, 02:11:36 am
content: Quote from: NorthGuy on June 04, 2019, 02:07:27 am20 pins minus power, GND and USB is too little for keyboard without using additional IC to scan keys.

author: NorthGuy
author_rank: Super Contributor
timestamp: June 04, 2019, 02:58:55 am
content: Quote from: wraper on June 04, 2019, 02:11:36 amIf lots of pins are needed, then it's not going to be as cheap. Something like PIC24FJ64GB410 (100-pin TQFP), or PIC24FJ64GB412 (121-pin BGA) may work. These are about $4. Although PIC24s are quite different from 8-bit PICs.

author: rstofer
author_rank: Super Contributor
timestamp: June 04, 2019, 08:13:42 pm
content: I would expect the keyboard to be multiplexed and scannedhttps://www.embedded.com/electronics-blogs/without-a-paddle/4439874/Keyboard-and-display-multiplexing----the-traditional-approachThere are a lot of electrical approaches to this. If I had 256 keys to scan, I would send out a 4 bit value to the row select and use a 4-16 demux chip to do the actual selection. Then I would need 16 column inputs. Total: 20 pins for 256 switches.The problem with this is that it doesn't necessarily sort out near simultaneous keypresses. There used to be chips that scanned a keyboard and it looks like some are still around. I imagine it can all be worked out in firmware because something like Ctrl-Alt-Del just has to work.Then there is 'n key rollover'https://en.wikipedia.org/wiki/Rollover_(key)

author: Doctorandus_P
author_rank: Super Contributor
timestamp: June 05, 2019, 12:07:10 am
content: GH60

author: ajo518
author_rank: Contributor
timestamp: June 05, 2019, 01:40:11 am
content: The keyboard is indeed multiplex. There are 28 pins that make up the keyboard matrix. So that is deferentially a consideration as far as the specific chip, but I'm guessing almost every family has options that will work.As others have said it is a 10X17 grid. You activate one row say and then read back the columns. This is already laid out so no concern there.Say I went with an ARM option is there a large difference between the vendors? Are the in circuit debuggers manufacturer specific or just ARM specific? Is there a good in circuit programmer I should be looking at?Thanks for all the good input!

author: lucazader
author_rank: Regular Contributor
timestamp: June 05, 2019, 01:56:38 am
content: Arm is in general pretty similar. At least when it comes to the compiler and the actual core it's self.However the peripherals and USB stacks and classes will be different and more manufacturer specific.Usually the debuggers are manufacturer specific, however they are all pretty cheap.Eg an stlink v2 clone of ebay is about $3. and if you get a nucleo dev board it comes built in.All the other manufacturers are similar in offering low cost (eg less than $50) options.

author: Dabbot
author_rank: Regular Contributor
timestamp: June 05, 2019, 10:11:25 am
content: Also, if you select a chip with plenty of ADC pins, you can implement each group of keys as a resistor ladder and keep the pin count requirement down.

author: mariush
author_rank: Super Contributor
timestamp: June 05, 2019, 11:22:17 am
content: Or you could just add i/o expanders... a 16 i/o i2c/spi expander is under 1$ and can have interrupt on change to simplify your life.

author: NorthGuy
author_rank: Super Contributor
timestamp: June 05, 2019, 01:07:23 pm
content: Or a long shift register (probably can be had at close to 1 cent/flop). You just rotate a single '1' bit through it to activate each key sequentially. Then sample with a single MCU pin.This eliminates the need for diodes at every key.With the shift register, you only need 3 MCU pins. The money you save by using a low pin count MCU instead of a big one will pay for the flops.<edit>Sorry, I wasn't thinking. Diodes, of course, are necessary.

author: MarkF
author_rank: Super Contributor
timestamp: June 05, 2019, 04:13:30 pm
content: Another PIC choice might be the PIC18F4550.It has 35 IO pins plus USB. You would have to really take a look at mapping out the IO pins since you need 27 pins.