Efficient Keypad Scan?
I have a Grayhill Series 96 keypad, which I'm using in conjunction with my BASIC stamp. All the keypad scans that I've seen tend to be quite lengthy. I keep thinking there has to be a more efficient way to code the scan, but haven't found one yet.
Does anyone have an efficient keypad scan they'd like to share?
Many thanks!
Does anyone have an efficient keypad scan they'd like to share?
Many thanks!
Comments
·· I assume you mean an efficient one using parallel I/O?· How is your keypad arranged?· How many rows/columns?· I have a few routines, although in the last few years I had switched to using parallel to serial chips.· Now with the SX coming down in price you can roll-your-own, so to speak.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
My keypad has four rows and four columns.· I've·attached a keypad scan I had for class, which was modelled after my professor's keypad scan.· He mentioned that there were lots of ways to wire/program keypad scans, and said that one could probably find lots on the internet.· Maybe my googling skills have declined, but I have yet to find a better on on the internet.
Thanks again,
Diane
·· That code could be further simplified by adding the ASCII variable assignment to the IF...THEN statements.· A more conventional way would be to use a LOOKUP table after the scan routine.· Here's a Nuts & Volts article that has a keyscan routine you could check out.· Otherwise I will see if I can find the one I used to use.
http://www.parallax.com/dl/docs/prod/audiovis/Qvox306SoundOffAgain2.PDF
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
http://www.engr.udayton.edu/faculty/jloomis/ece445/stamp/nv_mag/st_ap22.pdf
And finally, Dr. Tracey Allen has some interesting information on the following page.· Lower down is the section about the keypad scan.· State machine stuff...keypad goodness!·
http://www.emesystems.com/BS2fsm.htm
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
·· Very interesting...Hadn't thought of that method.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Just tossing my two bits worth into the bit bucket
KK
·
I can name that circuit in one IC!
The schematic you posted is similar to one of my old tricks using binary weighted resistor values. (i.e. 1K 2.2K, 4.7K, 10K)
webpages.charter.net/schwabelove/BasicStamp/3x5KeyPad.gif
This circuit would use the PULSIN command, specifying a "0" or "1"for the "State" modifier would determine if you are
looking at the ROW or COLUMN data.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Chris - I just started working with the Basic Stamp, and although I'm familiar with the "Lookup Table" concept, hadn't thought of applying it to the Basic Stamp!
I haven't been issued a timer chip yet, so unfortuantely I can't try out the more advanced method.
·· With enough examples and time to experiment you'll find the best choice for you.· Different people will often like different methods of doing the same thing.· Let us know if you need further help.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
emesystems.com/BS2rct.htm#switches
It is an adaptation of Scott Edward's BS1 application note #18.
Chris pointed out the following key scan routine:
emesystems.com/BS2fsm.htm#keypad
Note that there is one routine there that includes debouncing and another much simpler that simply scans the keypad. You have to evaluate your project to know if debouncing is going to be necessary. The debouncing routine in that example uses a kind of programming element called a "vertical counter" to debounce all of the keys in parallel, and a separate routine for decoding.
In some applications, it can be useful to decode multiple key presses as "secret codes" or for other purposes. For example, "press "*" and "1" at the same time to enter the configuration menu". If you need that kind of capability, the key scan routine has to be designed to support it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Post Edited (Tracy Allen) : 2/14/2006 1:30:17 AM GMT
RCTIME is the stamp function you want to use with this example.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
http://www.elabinc.com/
EDE 1144 - 4x4 Keypad Encoder IC
EDE 1188 - 8x8 Keypad Encoder IC
Mohamed Refky
Although he said that my code is similar to his, he said that it's the smallest he's seen.
Maybe I should hint the whole "many buttons, one pin" idea to him. Sometimes I wish I had only taken six credits this semester so I could focus more on this stuff, as I find it supremely fascinating.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Is there a formula you used to determine the 2.2K and 15K resistor values in your circuit? I don't have any 15K resistor in my parts box. Also, what's the value of the capacitor in your circuit?
The 15K resistors are not that critical, I just wanted a good separation between Columns.
As far as the C value, this is determined the same way that you would normally choose a value
using the RCTIME function with the BS2. (See RCTIME under Help in the BS2 program)
I have re-posted the original keypad schematic which is simply an extension of the RCTIME
circuit referred to in the manual and BS2 program help documentation. The revision includes
values returned if you were to use 10K vs. 15K resistors.
I guess, that the basic relation between the 2.2K and the 15K is as follows:
Assume R1 = 15K's and R2 = 2.2K's
R1 >= [noparse][[/noparse] R2 * (# of rows) ]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 3/12/2006 4:08:21 PM GMT
Nice job on the code. I'm never one to leave these things alone, and the words "smallest he's seen" is a challenge.
Using the same logic as your program, PBASIC has a couple of commands that can make the code even smaller. Here is a condensed inner scanning loop:
That gets rid of the IF-THEN logic and lets the program deal with all the port bits in parallel, rather than one at a time. The operator DCD (short for "DeCoDe") takes the value i=0,1,2,3 as input and gives back OUTA=1,2,4,8 as output. That is, the binary pattern that sets one column HIGH, %0001, %0010, %0100 or %1000.
The operator NCD (short for "eNCoDe") lets the program deal with the whole port inB all at once. It takes an input in the range of 0 (no keys pressed) to 15 (all keys pressed at once), and gives back the number 0,1,2,3,4, which is the index of the highest bit set in the on port nibble inB. If no keys are pressed the value is zero (and the scan loop continues), but if one or more keys are pressed, (x=NCD inA) will give 1,2,3 or 4 and the program will jump to the LOOKUP. If two or more keys are pressed at once, the higher one wins. Your code gives the highest priority to the lowest numbered key, but that might not matter. If it does, then use (x = NCD (inB REV 4)), which reverses the order of priority.
The LOOKUP (x-1)*4+i,... uses the value of both x-1 and i to compute a position in the lookup table.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Cab anyone help me translate the diagram of the RC Time by Beau into actual pin connections. I have tried all afternoon but no luck. I get the RC Time running on the BS2 with a 10K pot. I must not connect some of the resistors correctly. The 2 at the end of the row and Col.. Can anyone give me some direction...please and thank you.
Gilles
Thanks for the help! I knew there was a way to further refine the code!!!
I'm not sure I understand what your question is. Have you been able to get the RCTIME command to work with a 10K pot?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Yes the RC Time works fine with the pot.
I am using a multimeter to check the R value at the 2 points of the 470 Ohm R
On your diagram, at the top and to the right the first 10K resistor does it;
a) connect right resistor wire to keypad pin1 and the other resistor wire (left) goes to pin 2 with the second resistor.
or
b)does the 1st resistor (10K) wire attach to pin 1 of the keypad but the other lead connect back to pin 8??
If i connect the resistor 10K from pin 1 to 2 another resistor from 2 to 3 and so on to pin 4 which ties to the top of the 470 Ohm,
and the row resistor also pin 5 to 6 6 to 7 7 to 8 with the 2.2 K and then to the 470 ohm
that does not seem to work for me when I press a key the R value changes but not according to the values on the diagram.
I'll probably kick myself when I finally get it but for now it's a puzzle?
any idea?
Thanks for your time
Gilles
Secondly, in your post your keep referring to a 470 ohm resistor - that should be a 470K ohm resistor.
Thank you. Daah..., I was using a 470 instead of a 470K resistor. And a) description is the way to go. Works fine now.
Gilles
Gumby,
I'm glad you found a solution and everything is working ok now.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.