On Fri, 11 Apr 2003, Michael Park wrote: > >From: Patrick J > >Reply-To: pic microcontroller discussion list > >To: PICLIST@MITVMA.MIT.EDU > >Subject: Re: different approach to keyboard scanning? > >Date: Thu, 10 Apr 2003 02:11:28 +0200 > > > > > >Use the A/D inputs of the PIC instead ? > >(then you can define your own 0 and 1 voltage levels in software) > > Unfortunately, the PIC I use doesn't have A/D, and besides, the number of > A/D inputs would be impractical. > > > > >Tho I am not sure why you want to do this in the first place. It is quite > >common > >to read keyboards in X-Y fashion. Just not with diodes in the juncions as > >you do. > > Well, to read a 3x4 keyboard you normally need 7 I/O lines (unless you add > external chips). The way I want to do it would only need 4 lines. > > I also need n-key rollover, so diodes are going to be necessary at the > junctions in any case. I just wanted to see if I could get by with just > those diodes and a little cleverness. If you use only the upper (or lower) triangle then you can get rid of the diodes. The downside is that the number of switches that you can scan is cut in half. However, that is still greater than the general X-Y scanning: for n lines the maximum switches that the X-Y scanning method can scan is (n/2)*(n/2) = (n^2)/4 (if n is even). the maximum switches that can be scanned by using this 3-state logic is: n*(n-1)/2 = (n^2)/2 - n/2 = (n^2)/4 + (n^2)/4 - n/2 = (n^2)/4 + n*(n/2-1)/2 In other words, the 3-state logic will scan n*(n/2-1)/2 more switches. If n is not even then the most you can scan with the X-Y approach is: (n-1)/2 * (n+1)/2 = (n^2 -1)/4 Putting into a table: # scanned n X-Y 3 state ------------------ 4 4 6 5 6 10 6 9 15 7 12 21 8 16 28 9 20 37 10 25 45 11 30 55 12 36 66 13 42 79 14 49 91 15 56 105 16 64 120 (if I did this table correctly). Scott -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu