Electronic Design

  
Reprints     Printer-Friendly    Email this Article    RSS        Font Size     What's This?


[Ideas For Design]
Novel Switch Interface Scheme Reduces Microprocessor Pin Count

Kartik Joshi  |   ED Online ID #18652  |   April 24, 2008


The most common method for interfacing multiple switches—multiplexing— allows for the connection of (N/2)2 switches with N microcontroller IO lines. The method described below, which has its roots in an LED interface technique commonly known as “Charlieplexing,” makes it possible to interface N*(N – 1) switches with N IO lines.

In conventional multiplexing of an N-by- N matrix with 2N IO lines, half of the lines are configured for input and half for output (at logic 0), permanently using a pin either for just the input or for just the output. The proposed method uses both states of an IO pin, increasing the number of switches that can be interfaced to it.

In the proposed method, every IO pin is connected to every other pin with two switch-and-diode series circuits. Figure 1 shows a two-pin example. In this configuration, switch S1 can be read by configuring Pin2 to input mode and Pin1 to output mode (with logic 0). Switch S2 can be read by configuring Pin1 to input mode and Pin2 to output mode. This technique allows designers to interface six switches with only three pins, and a whole numeric keypad of 12 switches with four pins.

This configuration easily scales to any number of IO pins, but between two IO pins, the circuit essentially remains the same. For a circuit with N IO lines, each IO pin has N – 1 diodes leading in, and N – 1 diodes leading out. At any time, one pin is switched to logic 0, while the other N – 1 pins are configured in input mode for reading N – 1 switches attached to this pin. Generally, the N – 1 diodes leading into this pin can be replaced by a single diode, with all of the N – 1 switches connected to its anode.

Figure 2 shows a circuit for interfacing 12 switches using only four microcontroller IO pins. To read switches S1-S3, Pin1 is set to logic 0, and Pin2, Pin3, and Pin4 are set to input mode. Similarly, to read switches S4-S6, S7-S9, and S10-S12, Pin2, Pin3, and Pin4 are, respectively, set to logic 0, while the rest are set to input mode.

The circuit in Figure 3 demonstrates how a full numeric keypad interface can be connected to only four pins of a microcontroller (an Atmel ATMEGA8 in this case). The switches are pushbutton types, and the diodes are generic rectifying diodes. The demonstration program (go to www.electronicdesign.com), written in C using WINAVR, successively sets one of the IO pins to 0, and the rest to input, and it sets the state of the switches, which was relayed serially in mode 9600-8-N-1.

References:
1. Anurag Chugh, Dhananjay V. Gadre, “Eight-Pin Microcontroller Handles Two-Digit Display With Multiple LEDs,” www.electronicdesign.com, ED Online 15512
2. “Charlieplexing” at http://en.wikipedia.org/wiki/Charlieplexing. Retrieved Sep. 3, 2007.


Reprints   Printer-Friendly  Email this Article  RSS    Font Size   What's This?


  • Model Extractor For CMOS Sports Improved RF/DC Parameters
  • Floorplanning A Power Delivery Network With Spice
  • BGA Breakouts & Routing
  • Cadence Shoots For The Silicon Compiler Dream
  • Digi-Key Part Data Enters OrCAD Environment
  • Modeling/Simulation Tool Gets Physical
  • Show Videos Take Center Stage On ElectronicDesign.com
  • Hardware/Software Co-Design Comes Of Age
    1) Still Working On My Solar-Panel ROI
    (884 views today)
    2) Build A Smart Battery Charger Using A Single-Transistor Circuit
    (319 views today)
    3) A Solar Story
    (253 views today)
    4) Beyond The $10 Million Light Bulb
    (222 views today)
    5) Bob's Mailbox
    (209 views today)
    ALL TOP 20



    Reader Comments

    Very Interesting - could you post the C code

    Anonymous -June 01, 2008

    See patent 4673933, "Switch matrix encoding interface using common input/output parts"

    Anonymous -May 06, 2008

    Where's the C code for this located? I would be interested in seeing how switch debouncing and multiple key press issues were handled.

    Anonymous -May 05, 2008

    Why is it that when an article indicates an attachment in the online version it is never, ever posted?

    Anonymous -April 30, 2008

    look at http://www.piclist.com/techref/io/keyswitch.htm, third idea down. You need only one MC pin to connect almost any size N by N keypad.

    Anonymous -April 23, 2008

    POST YOUR COMMENTS HERE
    Name:

    Email:
    Your Comments:

    Enter the text from the image below


    Please refresh the page if you have trouble reading this text.

    Search Electronic Design
         
      
     
    Email Newsletter
    Sponsored By:
    Electronic Design UPDATE provides readers with late-breaking news, opinions from industry experts, and timely technology stories. It's a unique opportunity to get your product message in front of engineers, engineering managers, and corporate managers while they're reading about critical information online.

    Enter Email to Subscribe
      

    Electronic Design Europe Electronic Design China EEPN Power Electronics Auto Electronics Microwaves & RF RF Design
    Schematics Find Power Products Military Electronics Featured Vendors EE Events Free Design Resources