Sonsivri

Electronics => Projects => Topic started by: zuisti on May 11, 2011, 02:39:21 14:39



Title: PIC keyin: max 15 buttons using only 4 pins, debounced, full IT controlled
Post by: zuisti on May 11, 2011, 02:39:21 14:39
This is a simple passive binary encoder (I'm using cheap Si diodes like 4148) plus a special
IT routine, which resolves the bouncing and double keystroke problems (I think so, try it ...)

Key pressing is sensed via PORTB pin change IT, and TIMER2 is used for a 20 msec debouncing.
Lookup table to define key return values (keys defined to zero value are ignored).

Sensing depressed key(s) is possible also at power on (see the demo program).

Only one key is sensed at a time, then the system is insensitive to the other button is
pressed, and a new key will be accepted only when all buttons are released.

Written a small program in Proton to demonstrate the concept:
Attached a ZIP with the basic source, the HEX file and the DSN.

The program is using the internal pullups:
.... Clear OPTION_REG.7 ' RBPU, portb pullups on
In a noisy environment I use external pull-up resistors directly on the encoder output lines,
and small RC filters to defend the PIC inputs. In this case the internal pullups are disabled.

I'm using also assembly snippets so for recompiling use the Proton 3408 (max. 3506), because
the 3511..3515 versions have some bugs (the version 3517 will be fixed these as I've read).
Note: my tests indicate that this is just for handling of some embedded assembly instructions
and only on 14-bit core devices (PIC16xxx). PIC18xxx is working as well.

The IT routine wich I'm using  is easy to write also in C language (it's well commented).

Greeting
zuisti




Title: Re: PIC keyin: max 15 buttons using only 4 pins, debounced, full IT controlled
Post by: borberk on May 11, 2011, 04:14:52 16:14
Similar solution is to use one A/D port and resistor chain connected to Vcc. Buttons are grounding resistor interconnections and voltage applied to A/D is changing.


Title: Re: PIC keyin: max 15 buttons using only 4 pins, debounced, full IT controlled
Post by: max on May 11, 2011, 07:28:50 19:28
Hi,

See the following link

http://www.sonsivri.com/forum/index.php?topic=26492.msg89795#msg89795

Using just 4 diodes and 4 i/o pins you can sense 12 switches,
using 5 diodes and 5 i/o pins you can sense 20 switches.
I have tested the circuit physically and its working fine.

Regards


Title: Re: PIC keyin: max 15 buttons using only 4 pins, debounced, full IT controlled
Post by: zuisti on May 11, 2011, 11:08:52 23:08
Similar solution is to use one A/D port and resistor chain connected to Vcc.
Hi 'borberk';
Thank you for your response.
Yes, I've already tried this solution too: only one input pin, but more CPU time is required.
The key-code assigning, the debouncing and the protecting against double keystrokes is also
more difficult as in my present 'clear digital' solution, wich is simple, extremely fast,
and works full in the background (it runs in IT time and only if a keystroke is occured).
However, for some non-time-critical applications I'm using also the A/D method.

http://www.sonsivri.com/forum/index.php?topic=26492.msg89795#msg89795
Using just 4 diodes and 4 i/o pins you can sense 12 switches...
Thanks 'max';
Your circuit is also interesting but it also requires a continous (periodic) polling
in a loop to sense a keystroke, then - after a debouncing time - again to determine it.