Keypad pin reduction

17 Jan 2012

I want to reduce the # of pins needed to detect keys presses from 4x3 and 4x4 keypads with 4 rows and 3 or 4 columns. On input K1 a 7 or 8 pin keypad is connected while on output K2 the pins are 1:GND; 2:Analog input pin with open collector; 3: Vout. The capacitor is used for debouncing and creates a R*C of about 50ms. The complete circuit fits on a 10x20mm PCB using SMDs.

What do you think about it? Is 22k resistor good enough to pull a pin up or down? /media/uploads/Renegr/resistor-keypad.png

18 Jan 2012

Ooops sorry, I had an error in reasoning. The debouncing capacitor won't work for analog inputs. Need to do this in software. I can simplify the cicuit to use just 6 resistors and 2 "output" pins

18 Jan 2012

Hi Rene, I have seen this used before. 22K is (for the mbed) a rather "soft" pull-up or pull-down. You might run into unpredictable behaviour like AC-interference. For the mbed I would advise a maximum pull-up/pull down value of 2K2, just to be safe. Have you tried a diode matrix with a few resistors to achieve the same?

Regards, Willem

18 Jan 2012

Thank you for that information, it's hard to find that usable informations. Sorry I don't have a big assortment of parts which can be assembled fast, just some SMD parts. Anyway I've redesigned the circuit to be again cheaper and smaller :) /media/uploads/Renegr/resistor-keypad1.png

19 Jan 2012

Hi Rene,

looks ok this way. Please let me know what your experiences with this method is?

Regards, Willem

21 Jan 2012

Hi Rene, I stumbled upon a similar design on the Internet. The guy also uses a very clever design, and includes an Excel spreadsheet for optimising resistor values.

Have a look here: http://www.sparkfun.com/products/8653

and look for the message from member #81485

This may help you out on selecting the resistors.

Regards, Willem

21 Jan 2012
21 Jan 2012

Thank you Willem. Didn't found them. But I think both have disadvantages like the first needs "many" different resistor values. It will be cheaper to buy a lot of resistors of the same values. Of course this is just marginal as resistors aren't that expensive :) The second circuit has the disadvantage that if S10 is pressed, 11mA will flow -> 55mW get lost. 440R for the lower resistors means 44k for the 100R resistor. I didn't find any sheet about the input impedance of the ADC but IMO 44k is to high. I've ordered some SMD resistors which fit between the pins of the 2.54 grid. It'll need nearly no space for the circuit. I'll attach an image when ready :)

23 Jan 2012

Hi Rene, me again. I have found a valuable resource on the subject here: http://www.rau-deaver.org/1-wire_keyboard.html A calculator can be found there too...

Regards, Willem

23 Jan 2012

Hehe hi Willem, nice, that's my idea. What I currently need to find out is: 1. what is the A/D max input impedance? I want to use the maximum possible. 2. at which minimum voltage difference I receive an interrupt?

Hopefully some of my ordered 5% resistors will have a smaller tolerance because with 5% it doesn't seem to work :)

25 Jan 2012

Rene, I have been searching the datasheet of the LPC1768 with a fine comb. Chapter 12 shows the ADC electrical characteristics. It show a parameter called Rvsi. This is the actual input impedance of the ADC and is about 7.5 kOhm

In electrical terms you will get the following schematic: /media/uploads/WillemBraat/mbed_adc.jpg

Rvsi is fixed and about 7.5 kOhm. R1 is the value of any resistor(s) between 5 volts (or 3.3 Volts) and the ADC input. The resistors in the keyboard matrix will form a variable resistance (R1) (depending on which key is pressed) and act as a voltage divider with Rvsi and will vary with the keys pressed.

If (just as an example) the keys in the matrix will add up to 3 kOhm and the supply voltage is 3.3 Volt the voltage fed to the ADC will be 7.5/(3+7.5) = 2,36 Volt.

It means that you will have to drive this input with a voltage source of at least a factor 10 smaller, meaning a 750 Ohm. That will almost force you to use an OpAmp to buffer the voltages from the keyboard, or use a capacitor at the ADC input pin to "buffer" the voltages. This capacitor has a low internal resistance and should be large enough to hold the voltage level and small enough to follow quick key presses. Just try a C-value of 100 nF as a starter to see what happens...

Regards, Willem

25 Jan 2012

Hi Willem, first tests with the 1 wire keyboard link you posted confirm that it will work fine given an ADC input impedance of 7.5k. But with this solution I need to poll the value of the ADC because InterruptIn and AnalogIn won't work together. I want to have an interrupt. So I connected 2 pins and configured 1 pin as InterruptIn pulldown mode and the other as AnalogIn. With every 1k resistor in series to Vout the ADC value decreases by 2%. Too bad my highest resistor currently is 1k.

28 Jan 2012

René, you make me curious on the results. How do you generate the interrupt? I was also wondering wether you see any influence of the contact resistance of the keyboards. They are usually between 100 and 300 ohm.

28 Jan 2012

Hehe Willem, I think I'm doing some funny and tricky things :) First because of my shortness on wire resistors > 1k I've soldered some wires on 0805 SMD resistors. Because I just have a 4x3 keypad I've chosen 3x 2.2k and 2x 10k resistors, connected p14 and p15 together and with the keypad. p14 is an InterruptIn in pulldown mode. With it I receive the interrupt. p15 is an AnalogIn which reads 0 as long as no key is pressed because of the pulldown of p14. The other "end" of the keypad goes to 3.3V. If the overall input resistance is > 28k no interrupt is received anymore.

100-300 ohm? I just measured about 10 ohm on my very cheap keypad.

30 Jan 2012

Hmmm, I suppose my keyboard may be faulty then. Will try another one straight from the bag, and will let you know!

Nice going on the resistor experience.. Are you getting a trustworthy response from the keyboard?

02 Feb 2012

11 of 12 keys always return the right code on first interrupt. Just the '0' button makes some problems. But I need to adapt the algorithm for debouncing generally a little bit. After getting the interrupt I'm starting a timer sampling the analog in for ?some? time and return the maximum found value which is then interpreted as the pressed key.

06 Feb 2012

Hi Rene,

I checked my keypads and they are also around 10-15 Ohms. The other one was faulty... don't know why.

Can you give the values for the resistors, I will also give it a go...

06 Feb 2012

Willem, depends on your keypad 4x3 or 4x4. I've used 3x2.2k + 2x10k for 4x3. This is nearly the maximum resistance to get an IRQ. I assume 3x1k + 2/3x5k should also work fine.

Sorry there's no progress in my code because I'm currently trying to implement the RFM70 wireless adapter (so it's not ready for publishing).

23 Feb 2012

Hey Willem, any news on your side? Does it work or didn't you have enough time?

Just a short piece of code from my side

void getRCFromVal( float val, char& r, char& c) {
    printf( "%f\r\n", val);
    r=-1;
    c=-1;
    if ( val >= 0.88) {
        c = 2;
        val -= 0.88;
        r = val/.03;
    } else if ( val >= 0.70) {
        c = 1;
        val -= 0.70;
        r = val/.035;
    } else {
        c = 0;
        val -= 0.52;
        r = val/.04;
    }
}

where val is the output from the ADC (normalized to 1). The function is called as soon as the interrupt is received. I've also started a ticker for debouncing which checks finds the maximum out of 10 samples and then prints out the values for r/c (row/column).

26 Feb 2012

Hi René,

I have been very busy with my job (aircraft ferrying). Coming week is a lot more quiet, and I will give it attention definitely!

Regards, Willem

26 Feb 2012

BTW are you interested in a PCB design for the circuit as a piggy-pack for the keyboard? WB

26 Feb 2012

Thanks but no. I've soldered some SMDs on a strip board between the contacts. It's not beautiful, but it's very small (just the size of the 2 connectors, the 2x and the 7x) and I don't want to win a design price :) RG