2
\$\begingroup\$

I am designing a simple contact switch(tactile, which conducts when you pushes, and springs back to not-conducting when released) interface with a microcontroller.

It's GPIO has option for both internal pull-up and pull-down.

1) Which one should I use? For 2 layered board, pull-up makes me easier to do PCB artwork, since one-end of switch connects to GND. Other than that, is there any difference or reason for me to use one configuration over another?

2) Is there any possiblity that the noise from physical contact make MCU malfunction?

\$\endgroup\$
1
  • \$\begingroup\$ i recommend pull-up and connect the switch to GND. that is more conventional and is compatible with WIRE-OR (or open drain) logic. to debounce the switch, in your MCU software, when the I/O pin (to the switch) is first detected to be changed from the current known state of the associated flag, do not change the flag state but start a timer and read the I/O say 10 ms later and change the flag state only if the I/O pin is again read to be the same changed value. a small cap on that I/O pin (to GND) might also smooth things out. \$\endgroup\$ Commented Nov 2, 2017 at 8:36

3 Answers 3

4
\$\begingroup\$

1) Which one should I use?

Whatever suits your overall design best

1) For 2 layered board, pull-up makes me easier to do PCB artwork, since one-end of switch connects to GND.

That is exactly the reason pull-ups are used more often than pull-downs (and some chips only have pull-ups): a ground line is often more conveniently available for the other side of the switch (and open-colledror/drain outputs are more common than their top-side counterparts).

1) Other than that, is there any difference or reason for me to use one configuration over another?

2) Is there any possiblity that the noise from physical contact make MCU malfunction?

I would guess that (in a reasonably well designed system) the power is more noisy that the ground, so an active-high switch would potenetially induce more noise. But even that should be no problem on a digital input with sufficient margin.

So by all means, go for pull-up and an active-low switch.

\$\endgroup\$
1
  • \$\begingroup\$ Actually, when you say "exactly the reason", there are many reasons. Another is that Rpu-GND on wiring is much less vulnerable to accidental shorts to chassis ground than Vdd-Rpd. This is a consideration when routing wiring round equipment that may trap and short it. Another is historical: 74LSxx and 74xx gate inputs need a much lower pull-down resistance than pull-up resistance, so pull-up/switch-down was preferred and common, using less pulling-resistor current. That wasn't a factor from 74HC(T)xx onwards or with CMOS. \$\endgroup\$
    – TonyM
    Commented Nov 2, 2017 at 8:42
2
\$\begingroup\$

Standard practice is to enable internal pull-up of ~100k with a debounce cap across switch such that RC=T > bounce time or use software debounce.

Depending of ESD risk the contact may also have a series current limiting R to allow the IC diodes rated for 5mA to do their job or better , add Transil or TVS protection.

\$\endgroup\$
1
\$\begingroup\$

Either will work, a pull up with the switch shorting to ground, or a pull down with the switch shorting to Vcc. If layout is easier for you using a pull up then that's fine.

Noise from switch bounce shouldn't upset your microcontroller, especially if you've followed the manufacturer's recommended decoupling scheme.

\$\endgroup\$
1
  • \$\begingroup\$ Switch bounce is not the same as noise. \$\endgroup\$
    – awjlogan
    Commented Nov 2, 2017 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.