Keypad -- One-Wire


The keypad of the previous project tied up seven port lines total. What would you say if we could get it down to just one!

Here's the deal. Some keypads (I got mine from All Electronics) are arranged as one long line of switches with a common input (instead of the matrix affair we saw previously). Thus, we can set things up as a resistor chain, and pressing a key shorts a portion of the chain to ground. Sort of like a potentiometer with discrete steps.

Then we feed the dropped potential to the analog-to-digital (ADC) module within the PIC microcontroller and determine just where we are in the chain. That may sound dicey, but actually works extremely well in practice.


So, in a nutshell, pressing a key generates an analog voltage different from any created by the other keypresses, and then the ADC withn the PIC converts that to a binary number which is finally acted upon.

A couple things to pay heed to. For the ADC to be happy (and accurate) the output impedance of the source driving it should be fairly low, in the neighborhood of 10K or so. You'll note that the resistor string, along with R3 achieves that; this is essentially a 24k pot, whose wiper begins at the midpoint. It's impedance, then is a comfortable 12k or less.

And for accuracy, the resistor string should consist of 1% values. When you run the demo, you'll see that each ADC value may flicker up or down by one notch, but that is always well within the quantizing resolution. This is a reliable circuit.

Incidentally, an ADC value of 255 or so means no switch has been pressed; the module is seeing the full +5V input from R3.

Since this is our first project using the ADC, be sure to take time to read over the source code and see how the ADC library unit from PIC Micro Pascal is invoked. The syntax of its commands is a little obtuse, but with my example source code at the ready, I think you'll figure it out okay.

Click to get the source code.
Click to get the schematic PDF.

Next Project: IR Remote Control

No comments:

Post a Comment