13-06-2013, 04:35 PM
Read multiple switches and a potentiometer setting with one microcontroller input pin
Read multiple switches.pdf (Size: 296.87 KB / Downloads: 68)
The circuit in this Design Idea
provides a way to convey mixed
analog and digital inputs into a micro-
controller using one input pin. The out-
put of the circuit connects to a micro-
controller’s ADC-input pin. The circuit
comprises a single variable resistor and
a number of SPST (single-pole/singlethrow)
switches (Figure 1). The push-
buttons allow the user to select modes,
states, or options, and the analog input
provides a method of conveying an ad-
justable parameter. The implementa-
tion requires you to analyze a parallel
resistor circuit and a voltage divider.
If you carefully select the resistor val-
ues, the circuit provides a discernible
analog input as well as a number of dis-
crete pushbutton-input states.
Selecting the resistor values is a
multistep process, and a spreadsheet,
which you can download at www.edn.
com/100422dia, aids in performing the
calculations. Say, for example, that you
want 5-kV potentiometer RADJ to pro-
duce a 0 to 100% value into the micro-
controller. Typically, you would map
the sampled value of 0 to 255 into a
0 to 100 value to represent a percent-
age. However, by selecting the values
of bias resistor RBIAS, you arrive at a di-
rect analog input centered on the 0 to
255 range of the ADC—for example,
78 to 178.