Path: EDN Asia >> Design Ideas >> IC/Board/Systems Design >> Employ ADC to read multiple switches
IC/Board/Systems Design Share print

Employ ADC to read multiple switches

06 Jul 2015  | Les Hughson

Share this page with your friends

The spreadsheet in figure 4 details the operation of each circuit (download the design files at the end of the article). The yellow cells are where you enter the resistor values used, the supply voltage, and the ADC resolution. The green cells are calculated outputs showing the operation of the circuit. The first three columns show a truth table of the button inputs, and the R Buttons column shows the total pull-down resistance resulting from the different button combinations. The Vout and Counts columns show the voltage input to the ADC and the resulting ADC reading. Count Mid Points shows values midway between the expected ADC values – it is these that are used to differentiate the different inputs and decode the button pushes. This ensures that all possible input values are decoded and maximum allowance is made for variation due to resistor tolerance, noise, etc.

Figure 4: Spreadsheet of design calculations for a two-button section.

The software decodes which combination of the four buttons is pushed, debounces the button inputs, and handles button repeat operations when certain buttons are held down.

As can be seen, the code distribution is not at all linear. However, even the closest values still maintain a reasonable separation for practical operation. A graph of the results (figure 5) shows the non-linearity and also highlights that almost half the ADC input range is unused by this circuit.

Figure 5: Button states vs. values.

This is a reasonable trade-off for simplicity, but it made me wonder if I could do better, and brought me back to reconsider the initial idea of figure 1. It seems logical to expand the two buttons to four by extending the resistor value progression from 10K, 20K to 10K, 20K, 40K, 80K. However, this does not address the non-linearity problem or the wasted ADC range.

An improved approach would be to replace the pull-up resistor (R1 in figure 3) with a constant current source. Then, the button resistor network will convert the constant current into a nice, evenly stepped output voltage. This could probably be done using a voltage reference (e.g., TL431) and a transistor. But that means additional active components and careful design. This is getting away from the initial vision of a simple resistor network.

Another approach would be to treat the four-button resistor network as if it were a variable-resistance sensor, like a thermistor, and use the same methods used to read those. This lead to the idea of putting the button network in a bridge circuit. This also matches the signal spread to the ADC input range. With careful resistor selection, it is also possible to improve the non-linearity. After some experimentation, this lead to the circuit in figure 6.

Figure 6: Four-button circuit.

This circuit uses only one ADC input for the four buttons, leaving the other ADC input for more buttons or other uses. The four buttons and series resistors form one side of the bridge, and R9/R10 forms the other leg. This is used as the reference voltage for the ADC – equal to the ADC's maximum input voltage. The resistor values are selected so that R10 = R15 and R9 equals the parallel combination of R11 to R14, thus allowing full use of the ADC input range. Keeping R15 and R10 small improves the linearity of the result at the expense of reducing the actual voltage swing.
 First Page Previous Page 1 • 2 • 3 Next Page Last Page

Want to more of this to be delivered to you for FREE?

Subscribe to EDN Asia alerts and receive the latest design ideas and product news in your inbox.

Got to make sure you're not a robot. Please enter the code displayed on the right.

Time to activate your subscription - it's easy!

We have sent an activate request to your registerd e-email. Simply click on the link to activate your subscription.

We're doing this to protect your privacy and ensure you successfully receive your e-mail alerts.

Add New Comment
Visitor (To avoid code verification, simply login or register with us. It is fast and free!)
*Verify code:
Tech Impact

Regional Roundup
Control this smart glass with the blink of an eye
K-Glass 2 detects users' eye movements to point the cursor to recognise computer icons or objects in the Internet, and uses winks for commands. The researchers call this interface the "i-Mouse."

GlobalFoundries extends grants to Singapore students
ARM, Tencent Games team up to improve mobile gaming

News | Products | Design Features | Regional Roundup | Tech Impact