Hank Fletcher said:
Maybe I'm stating the obvious here, but I'm trying to realize the best way to interface multiple on/off inputs to a PIC.
I think I have this right: an 8-bit shift register still uses 4 PIC pins for its operation, providing only twice as many inputs that'd other wise be used. If using multiple shift registers, can you use the same clock and load pins for all shift register ICs, for a greater amount of inputs and also a greater, new-inputs-to-PIC-inputs ratio?
My impression is that it'd be easier to just build a resistor ladder for the inputs, given that most PICs have multiple A/D pins. It shouldn't be hard to get consistent results out of just one A/D pin that way. That's my vote, but maybe I'm missing something?
Another consideration is response time.
With the shifter, you have to latch in the external data, enable the output (if you have more than one source), clock in all those bits serially, store them as bytes//words, disable the output (if needed), then process all those bytes to make sense of what's happening.
With the ADC, you take one sample, store the value, then use a lookup table to determine the next action.
With shifting, the more inputs you add, the longer you spend pounding in bits, and add more bytes//words to process.
With ADC, you can ( I believe ) sample 50 digital inputs in one fell swoop. I say 50 because most embedded uprocessors nowadays have 10 bit ADCs, which gives you 1024 increments. 50 inputs leads to a pretty large table though. Basically, you are creating a voltage divider. See the first diagram. There is a pullup resistor to tell the processor nothing has been activated. Every resistor you "switch in" is a unique value, and brings the input voltage down to some key value. You can't make these resistors too big as you have to supply a minimum current to make the ADC work.
Since internal jitter (AKA "noise") is always a factor, you make each input value ten increments, that is, give or take five each way. The first 'band', 0 - 9, is a switch which connects directly to ground. The next has a center value of 14 or 15, and the band runs 10 to 19. The band at the top, the highest values, is the pullup resistor. Since most processors use their Vcc as the top of the ADC's reference, each increment is 5V/1024, or 4.88mV or so. This is awfully tight, which calls for high precision resistors and very careful value selection, so don't plan on 50 inputs any time soon. However, 10 to 20 should be easy enough.
Which brings us to the keypad. This usually uses 7 pins (12 keys, 3x4) or 8 pins (16 keys, 4x4). The usual practice is to output three or four lows for the columns, then read the four row values. These seven or eight bits go into a byte, whose value is used with a table to determine the next action. If the row bits (all pulled up) are all high, nothing has been pressed, and the read process ends early. That's an entire port consumed in the job. And it takes two actions to do this, even if nothing is pressed.
Or you can read it in a single ADC sample. See the diagram supplied. You have a single pullup resistor going to the ADC pin. Also connected to this pin is four unique resistors. If no key is pressed, these have no effect. The other end of these resistors goes to a column connection on the keypad. The other end of the keypad switch, the row part, goes to another unique resistor. These row resistors then go to ground.
The idea is simple enough: every key closure connects a unique set of two resistors (row and column) to the pullup resistor. This forms a voltage divider, whose output goes to the ADC pin on the processor. The values of the resistors are designed to produce 12 (3x4) or 16 (4x4) unique voltages. You could theoretically have even more more unique voltages, so more keys, but resistor selection gets hard, fast. Of course, no key pressed = pullup only = highest voltage = we're done.
As always, you have to allow for multiple inputs happening at the same time. This is where ADC sampling falls down and using shifters shines. With the ADC, you may have to divvy up the inputs to minimize possible overlaps. This may take considerable study on the users' part. With the shifters, you just shift all the inputs in, then study them at your liesure. Look for every 'low' (or whatever level you selected to indicate activity) in each byte to find the active inputs needing service.
END $.02
kenjj