Active multiplexing saves inputs

Microcontrollers must often read the status of switches in control applications. A typical switch configuration uses pullup resistors on both of the switches to pull the signals high or low for the microcontroller to read. The controlling output in the circuit in figure 1 uses two switches. When both switches are open, resistors R1 and R2 keep the input at an undetermined value between low and high, which is 1.5 V if the supply voltage is 5 V. Thus, an analogue input would be preferable to a digital input. With the values in the figure, 0.5 mA of current flows through the resistors, even when both switches are open. You must multiply that value by the number of inputs used to get the total current.

The controlling output in this circuit uses two switches.
Figure 1. The controlling output in this circuit uses two switches.

Figure 2 shows an alternative circuit. It adds an inverter gate that pulls the microcontroller inputs to the opposite state of the driving output. An inverter gate has clearly defined levels of inputs. Thus, you can use normal logic inputs rather than analogue inputs. You can choose a resistor value as high as the input characteristics allow yet low enough to minimize noise immunity. When both switches are open or the controlling output is in a high-impedance state, the current flowing through the resistor is only the current that flows into the microcontroller's input.

The controlling output in this circuit uses two switches.
Figure 2. The controlling output in this circuit uses two switches.

Switching a signal's state uses energy, so change states only when reading the switches. Otherwise, leave the input and output pins in a high-impedance state. If your design has position-cam switches that never close simultaneously, you can refer to the circuit in figure 3 to reduce the number of inputs coding the switches. Table 1, a truth table, provides the possible states.

Table 1. Truth table of possible states
Out IN3 IN4 Switch
1 1 0 1
0 0 1 2
1 0 1 3
0 1 0 4
1 1 1 5
0 0 0 6
 
You can use this circuit to reduce the number of inputs coding the switches.
Figure 3. You can use this circuit to reduce the number of inputs coding the switches.

You can expand this scheme to any number of switches and inputs. You can read 12 inputs with three switches. You can also mix the circuits in figures 2 and 3 on the same microcontroller, separating independent switches (figure 2) and "interlocked" switches (figure 3) on different inputs.

EDN