What is meant by dpst switches

Smart ways to recognize a key (less power consumption)


During a meeting for a specific project, I was asked to think about the way a button press could be detected with an MCU. The detection should use as little power as possible. At first glance, I thought of the typical route with pull-up or pull-down:

simulate this circuit - circuit diagram created with CircuitLab

Some anti-bounce functions are not considered here as this is beyond the scope of this question. In both cases, the total current value that flows depends on the resistance value when the button is pressed. To minimize it (the current) I could increase the resistance value, but not so much since, if I'm right, it also depends on the leakage value of the input pin. Also, a large resistance would slowly recover.

My question is as follows: what smart ways are there to detect a button that is not consuming power (usually for high power applications)? Are there any methods that hardly use any power when the button is pressed?





Reply:


One low power method I used once was connecting a switch between two microcontroller I / O pins.

An I / O has been configured as an output (SWO). The second was configured as an input (SWI) whose programmable internal pull-up is activated.

The switching status was seldom (every 10 ms) scanned by a software interrupt routine. The reading sequence was: drive SWO low, read SWI, drive SWO up.

This meant that a pressed switch only drew the SWI pulldown current through itself and SWO for less than 1us, while an unpushed switch drew no current. This current consumption for <1 us every 10 ms resulted in a tiny average current consumption.







An SPDT ( S. ingle P. ole D. ouble T hRow) would be your highly efficient button.

Source: http://www.ni.com/white-paper/3960/en/

In your case the 1P would go to the MCU, the 1T to VCC, the 2T to GND.





How long is the button pressed? If it's not a toggle switch (which keeps its state) but a momentary switch, the current flowing when the button is pressed is largely irrelevant due to the short amount of time the button is actually closed.

Either of the two circuits you showed are fine, it doesn't matter.

You can assume that the input loss and / or current in an MCU input is negligible . All MCUs nowadays are in CMOS technology and have practically no input power. So stop thinking about it, it's not there.

Instead of an external resistor, you can also use the internal pull-up resistor that is built into many MCU inputs. This resistor may be of a relatively low value (possibly 50 kOhms) so there will be a small amount of current flowing when the button is pressed.

You can also use 1 Mohm resistor for a pull up / pull down. You may only need a lower value in very "dirty" environments (electrically speaking). You can also place a 100 nF capacitor in parallel with the switch to suppress interference from other circuitry nearby.

Pro tip: reserve a space for such a capacitor on the board, but don't mount a cap. still. In case of problems: put it in place and see if it helps.

To find out the status of the switch, use either Polling (as in TonyM's answer) or one Interrupt . It depends on the application which one is better for power consumption (the MCU).







One method I've used takes advantage of the capacitive nature of CMOS inputs.

simulate this circuit - circuit diagram created with CircuitLab

In the circuit above the switch, the pull-down resistor can charge / discharge the input capacitances of the GPIO to ground when closed.

The trick with this circuit is to use the bi-directional nature of a GPIO to keep the input high when the switch is open.

The control routine periodically switches the pen high or briefly activates the pull-up, long enough to maintain a charge on the caps. The input pin then acts like a dynamic memory bit and, in most devices, holds that charge for a considerable and usable period of time.

When configured correctly, the charge on the pin will discharge faster than the refresh rate when the button is pressed. This state can then be recognized as part of the refresh algorithm as a read operation prior to the refresh operation or used to trigger an interrupt.

During the refresh pulse, current is briefly consumed in order to charge both the capacitors and the resistor and to switch it when it is closed. However, the length of the refresh pulse is short and the interrogation frequency makes the refresh current relatively insignificant.

Obviously this method is active. If the microphone is put to sleep, the state of the switch when it wakes up is indeterminate. The first refresh cycle after waking up must ignore the read pin. This method should also not be used to wake up the microphone. Before going to bed, it is also advisable to activate the pen as a low output to park it in the de-energized state.

For reading more static switches such as Device DIP switches, a dedicated routine can be used instead of a continuous refresh cycle. After reading, the GPIO pins should be "parked" in an active low output state (zero current) to avoid the floating inputs problem.

NOTE: This technique suffers a little from noise sensitivity when the track lengths are long and move through a noisy area. Hence, R1 should be near the input pin. However, I wouldn't recommend it if you want to place a switch some distance away on a faceplate unless you add extra capacitance to the pin.




If your button is a piezo switch, the only power required is the power produced by pressing the button.

For example: R2 / C1 collect the energy generated by pressing the piezo. D1 prevents the C1 voltage from getting too high. R1 empties C1 when the button is released. The MCU-GPIO must be in input mode without pull mode. VoilĂ , button detect with zero power consumption from the supply.

simulate this circuit - circuit diagram created with CircuitLab







If the device needs to be able to stay in either state indefinitely, then using an SPDT switch is the least powerful method because a static circuit can be switched so that it does not have any current on its own internal leakage and that of the switch pulls out. An added benefit of SPDT switches is that they can be debounced almost perfectly, regardless of how fast they are operated or how grumpy the contacts are, provided one contact stops jumping before the other is closed for the first time is read.

There are two good approaches to wiring such switches:

simulate this circuit - circuit diagram created with CircuitLab

The first approach requires one less resistor than the second, but the second is more tolerant of any overlap between the two poles (it draws more current than usual, but doesn't shut off the supply). It should be noted that if the switch goes into a moderate resistance state for an extended period of time, it may use significantly more current than usual, but none of the resistors will carry any appreciable current during normal operation, except for the brief moment between when the switch changes state, the output responds.


Use the internal pullup of the microcontroller and disable the pullup when the press is detected. Then occasionally turn it back on briefly to check the button status.

We use cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.

By continuing, you consent to our use of cookies and other tracking technologies and affirm you're at least 16 years old or have consent from a parent or guardian.

You can read details in our Cookie policy and Privacy policy.