Use a tiny microcontroller with a large keypad

Sept. 2, 1997
Like a student needing just one more night to prepare for a coming exam, a microcontroller designer often wishes for just one more I/O line as a project approaches its final stages. Even for the relatively capable 8X752 microcontroller at 28 pins,...

Like a student needing just one more night to prepare for a coming exam, a microcontroller designer often wishes for just one more I/O line as a project approaches its final stages. Even for the relatively capable 8X752 microcontroller at 28 pins, with its high processing power, direct connection of a 5 × 5 keypad would steal 10 I/O lines from a total of 21 lines, or would require a special interface.

For a small, low-cost 16-pin microcontroller like SGS-Thomson’s ST6201/2, with only 9 I/O lines, the prospect of using any keypad isn’t a glamorous one. Fortunately, the microcontroller designers have included an 8-bit analog-to-digital converter (ADC) into this microcontroller. The ADC may not be completely suitable to monitor high-resolution sensors, but it can be an excellent resource for scanning a keypad of theoretically up to 256 keys. Without being too ambitious, I will describe a connection for a 16-key keypad. Having 16 keys makes the design (hardware and software) much simpler, but the following guidelines also will work for a larger number of keys.

The 4 × 4 keypad shown is a typical layout, except that the rows and columns are separated by resistors (see the figure). The resistance between point A and ground—R(n)—depends on which key (n) is pressed: 0 Ω if the first key is pressed, 0.5 kΩ if the second is pressed, and so on with steps equal to 0.5 kΩ, up to 7.5 kΩ if the 16th key is pressed. R(n) = (n − 1) × 0.5 kΩ. The current source will excite the resistor network and the resulting voltage drop will be measured by the ADC. For a 0-5 V analog-to-digital range, a current source slightly higher than 2.5 V/7.5 kΩ = 0.33 mA is suggested. For instance, the value 0.34 mA fits the bill; it will offset the voltage drop, excluding jumps of 2 LSBs due to possible analog-to-digital conversion noise. Also notice that only half of the maximum input range is used. This makes it possible to:

  1. Get a 17th condition: No key is pressed when the ADC data equals 0xFF.
  2. Get the pressed key’s number by shifting the analog-to-digital conversion data three bits to the right (or division by 8).

The larger the keypad, the more attention you must pay to the resistor values and tolerances, ADC noise, and the accuracy of the current-source setting. In addition, if the result of the 256 divide by keys’ number isn’t power of 2, your software will be a little more complicated. Another approach might be just to use the second analog input for an additional 16 keys.

Sponsored Recommendations

What are the Important Considerations when Assessing Cobot Safety?

April 16, 2024
A review of the requirements of ISO/TS 15066 and how they fit in with ISO 10218-1 and 10218-2 a consideration the complexities of collaboration.

Wire & Cable Cutting Digi-Spool® Service

April 16, 2024
Explore DigiKey’s Digi-Spool® professional cutting service for efficient and precise wire and cable management. Custom-cut to your exact specifications for a variety of cable ...

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.

Comments

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