Connect any keyboard with any microcontroller using only one pin

May 1, 1998
After “Use A Tiny Microcontroller With A Large Keypad” was published (ELECTRONIC DESIGN, Sept. 2, 1997, p. 166), I got a number of responses that prompted me to develop a corollary design. Presented here is a design applicable to microcontrollers not...

After “Use A Tiny Microcontroller With A Large Keypad” was published (ELECTRONIC DESIGN, Sept. 2, 1997, p. 166), I got a number of responses that prompted me to develop a corollary design. Presented here is a design applicable to microcontrollers not equipped with a built-in ADC.

Looking at the figure, you’ll notice a familiar 4x4 keypad with a single difference —each row and column are separated by a resistor. If key #1 is pressed, the resistance between nodes A and B (R1AB) is equal to 1.5*R; for key #2—R2AB = 1.5*R+R = 2.5*R; and so on ... key #N—RNAB = N.5*R. This variable resistor network is connected to a 555 timer (CMOS version), configured as an oscillator with the period of oscillation equal to T = 1.4*RAB*C, directly proportional to RAB.

The oscillator runs only when a key is pressed, causing an interrupt request for the microcontroller. The INT0 pin is set up as edge-sensitive. The general algorithm can be described as: 1) after detecting the edge on the INT0 pin, wait 20 ms to eliminate ringing; 2) detect the next edge and start the internal timer; 3) the following edge stops the internal timer. The measured period (the time between two consecutive positive edges) will define the key number. Any microcontroller with a built-in timer (the vast majority of microcontrollers) can implement this idea.

For a specific example, I will use the 8051-family microcontroller with a 12-MHz clock. In this situation, the single count of the timer will be 1 µs. If we choose 47 nF for the capacitor and 3.9 kO as the resistor value, we will have T = 1.4*R*C = 256.6 ˜ 256 µs. That is the period difference between oscillations produced by two serial keys. After calculating the period interval produced by any key pressed, we need only to make integer division by 0xFF (25610) to get the key number of the depressed key. The value for R1 =1.5*R is chosen to provide the highest error margin for the elements by moving the period value in the middle of two consecutive numbers.

Some possible sources of errors in this application are: 1) component tolerances; 2) 256.6 µs instead of 256 for 1% resistors; 3) the closest value to 4*R, if R = 3.9k, will be 15.4K or 15.8K instead of the calculated 15.6k., an additional 1% error for each following column; 4) the 555 oscillator inaccuracy—temperature drift of 75 ppm/C° and variation 0.03% for a power-supply variation of ±0.1 V.

Sponsored Recommendations

Near- and Far-Field Measurements

April 16, 2024
In this comprehensive application note, we delve into the methods of measuring the transmission (or reception) pattern, a key determinant of antenna gain, using a vector network...

DigiKey Factory Tomorrow Season 3: Sustainable Manufacturing

April 16, 2024
Industry 4.0 is helping manufacturers develop and integrate technologies such as AI, edge computing and connectivity for the factories of tomorrow. Learn more at DigiKey today...

Connectivity – The Backbone of Sustainable Automation

April 16, 2024
Advanced interfaces for signals, data, and electrical power are essential. They help save resources and costs when networking production equipment.

Empowered by Cutting-Edge Automation Technology: The Sustainable Journey

April 16, 2024
Advanced automation is key to efficient production and is a powerful tool for optimizing infrastructure and processes in terms of sustainability.

Comments

To join the conversation, and become an exclusive member of Electronic Design, create an account today!