SLTF Consulting
Technology with Business Sense



Interfacing to large switch banks requires more than stringing a few additional wires

Scott Rosenthal
September, 1995

The tendency for many engineers is to put off designing the user interface until the last moment figuring: How hard can a few switches be to set up? Unfortunately, with embedded development routinely making this assumption is an open invitation to disaster. For instance, consider the following scenario:

A client has a switch panel he wants you to connect to a computer. The panel's maximum size is 3' wide and 2' high, and is expandable by adding from one to ten columns. Each column uses a membrane switch pad containing 50 switches and 50 associated LEDs. To make the pad inexpensively, he's run one wire per switch and one wire per LED to the end of a flex cable. One common wire handles the switches and another handles the LEDs. The switch pads and switch panel are already designed and fabricated, and he'd like you to simply connect the switch panel into a computer. The computer must detect each switch press and light the corresponding LED. Finally, the system must be rugged, reliable and cheap.

When speaking of electronic hardware, 50 of anything is a lot, but 500 of something (50 switches x 10 columns) is ridiculous! The solution to the previous requirements lies in an understanding of switches, LEDs, cables and the intended application. The first part of this column is a refresher on bringing switch signals into a computer. This topic gradually builds to a system for implementing the above requirements.

Reading the switch

Nothing's more basic in an embedded system than reading a switch. It seems so simple-just connect the switch to a computer's input pin and then read it. But as with everything else in the embedded (real) world, there's always some catches. The first one is that a switch, by itself, won't switch logic levels. It needs a pull-up resistor to force its output to a High state while its pole is open (see figure). When the switch pole closes, it connects the input to the computer to ground, or a logic Low state.

Fig-Although the fundamental idea 
behind sensing a switch position 
involves very basic electronic 
theory, servicing a large number of
channels can involve complex design

The concept remains simple, but now comes the decision as to what value resistor to use. The answer depends on several factors including the logic family, the system's noise environment, the distance from the switch to the computer and the other resistor values already used in the system.

Different logic families need different currents to correctly set the gate into a High state. Standard TTL needs 400 µA, so in a typical TTL system, 10ký resistors are about the largest you can use. With LS-class TTL, its on-chip internal pull-ups remove the necessity to use external resistors, but being prudent and not wanting to chance a potential problem, I still add them as insurance. CMOS inputs need essentially no current to hold them in a High state, but you still have other considerations to worry about.

To begin with, all embedded designs work in electrically noisy environments-remember all the digital clocks, address and data lines running through the typical system. In addition, designers often locate switches physically remote from the PC, and a long-wire run can act as an antenna coupling unwanted signals ranging from hum originating in nearby fluorescent lights to radio and TV station signals. Hence, a pull-up resistor must be small enough to keep the High signal at a One, regardless of noise.

In addition, you must keep in mind total system-power dissipation because the pull-up resistors pass all their current to ground if the switches are closed. In a battery-powered (or otherwise power-limited) device, switches can contribute significantly to the overall power budget. Finally, remember that the flex circuits become increasingly popular because switch connections can have relatively high impedances.

Yet another consideration for the choice of resistors involves what the rest of the system uses. If you determine that a design needs 22ký resistors, don't go specing this value if the system uses 20ký resistors elsewhere. For pull-up applications, precision doesn't usually matter, so be nice to your stock room (and your company's bottom line) and keep commonalty in the parts lists.

Back to the spec

With this preliminary discussion out of the way, let's return to the original problem with its 50 to 500 switches. Using the previous discussion as a design guide, these switches require 500 resistors and 500 input gates to the computer. Assuming 74LS244 variety buffers for inputting all these signals, your system's I/O section will require 63 chips just for reading the switches. Of course this count doesn't include the bus buffers necessary for the CPU to drive this many peripheral chips. For the 500 resistors, you'll get a bit luckier and need only 56 10-pin SIP packages.

One potential solution to the problem of burgeoning chip-count is to find a way to reuse or multiplex the switch signals. But for this solution to work, you must put some additional requirements on the system. First, the switch panel must respond to only one switch press at any time. Second, holding down one switch while pressing a second one must be illegal. Assuming these constraints are amenable, you can significantly reduce the I/O subsystem's complexity. Referring back to system requirements, each switch pad contains 50 switches, and one switch panel can accommodate as many as ten pads. Multiplexing these switches reduces the problem from 63 '244 chips down to seven with only six resistor SIPs. To form the rows for the multiplexing matrix, connect together the like-numbered pins from each switch pad. The column selection comes from the computer scanning each pad's common wire.

The scanning process consists of the computer sequentially setting each column to zero and then reading the row lines to detect the logic Low signal resulting from a closed switch. This sequence is simple and easy to implement, but given the overall system requirements outlined at the beginning of this column it won't work. To begin with, the only reliable way of making all the connections the matrix requires is with a printed circuit board. When was the last time you saw a circuit board 3' long? Also consider the added complication (which I glossed over completely) regarding the 50 LEDs/switch panel and how to drive them.

Micro to the rescue

Of other possible solutions, mine took into account the finished system's target selling price, customer requirements for reliability and ruggedness as well as the necessary idiot-proofing. The solution was a small circuit board for each column. Each 2 x 3" board holds a small 8051-style micro, a small Xilinx FPGA and an RS485 transceiver. Each board manages one switch pad, controlling the switch reading and debouncing, the LED lighting and PC interfacing. The following summarizes some of the reasoning behind the choices:

Circuit board-Putting local intelligence on each switch pad allows the customer to easily add additional columns, permits the system to use a simpler (and less costly) PC and makes for easy field connections. This solution also increases system reliability by using a simple 7-wire cable for connection between each column and the PC.

Microprocessor-The micro controls the switch scanning, the debouncing, the LED lighting, the programming of the gate array and communications between the host PC and other circuit boards.

Xilinx-Although these chips aren't cheap, they pay their way on this project by implementing the logic that allows the board to maintain its small size. The programming for the FPGA resides in the micro. On power up, the CPU programs the chip, thereby saving external ROM.

RS485-This interface allows the system to implement a multidrop system where all the circuit boards act as listeners. When a board recognizes its address, it responds to the host PC-a simple interface that works flawlessly.

Simple switches obviously get complicated when strange requirements override their simple nature. The key is to find solutions that look at all sides of the problem and to back up the solution with facts, numbers and experience. PE&IN

Copyright © 1998-2012 SLTF Consulting, a division of SLTF Marine LLC. All rights reserved.