Author Topic: Switch to Microcontroller digital input: default ground or Vref?  (Read 222 times)

0 Members and 1 Guest are viewing this topic.

Offline WatthTopic starter

  • Regular Contributor
  • *
  • Posts: 242
  • Country: fr
Hey everyone !
When designing a circuit where a tactile switch is connected to a microcontroller GPIO, is it preferable to have the signal compared
- to ground (with pulldown resist and the switch activation detected as HIGH) or
- to Vref (with pullup resistor and activation of the switch read as LOW)?
Is this choice in consideration to the µC or PCB design, or other?
Thanks for reading!
Because "Matth" was already taken.
 

Offline PGPG

  • Frequent Contributor
  • **
  • Posts: 396
  • Country: pl
Re: Switch to Microcontroller digital input: default ground or Vref?
« Reply #1 on: January 03, 2025, 07:04:52 pm »
I had to position such switch under one of holes destined for terminal blocks in DIN-rail case.
I connected its one pin (it was 2 pin tact-switch) with GND and rotated it such that this pin was first from the PCB border assuming that if someone will be doing something near terminal blocks and ESD could happen to be it to that GND connected pad and not the opposite one.
 
The following users thanked this post: Watth

Offline SteveThackery

  • Frequent Contributor
  • **
  • Posts: 787
  • Country: gb
Re: Switch to Microcontroller digital input: default ground or Vref?
« Reply #2 on: January 03, 2025, 07:10:25 pm »
Most of the circuits I've come across have a pull-up resistor on the pin, and the switch - when operated - connects the pin to ground. So it's an active low input.

I've been told it is considered bad to have Vcc connected directly to the switch, which is how it would be if the switch operated as a pull-up. Something to do with reducing the amount of wiring and exposed connections with Vcc on them, to reduce the chance of accidental shorts.
 
The following users thanked this post: Watth

Offline golden_labels

  • Super Contributor
  • ***
  • Posts: 1452
  • Country: pl
Re: Switch to Microcontroller digital input: default ground or Vref?
« Reply #3 on: January 03, 2025, 07:50:14 pm »
I don’t know, but consider it may be “inherited” from other situations:
  • Pull-up and active ground is the only option for open collector outputs.
  • The input pin uses ground as the reference. So the active signal is unaffected by noise at all, while inactive signal noise is a bit limited by the resistor and notably above the threshold level. This would be a thing to consider in the past.
People imagine AI as T1000. What we got so far is glorified T9.
 

Offline prints-f-darkness

  • Contributor
  • Posts: 18
  • Country: us
Re: Switch to Microcontroller digital input: default ground or Vref?
« Reply #4 on: January 03, 2025, 08:17:05 pm »
Hi,

In the microcontroller world, VREF is typically used internally for the ADC, DAC or OPAMP peripheral (it serves as a known reference voltage).
The GPIO only sees anything above like .7v or 1.2v (threshold will very) depending on the IC, so it would make the most since to use VCC not VREF.
Some MCU's actually have an internal pull up or pull down on the GPIO.

What I use is a simple circuit found on hackaday (https://hackaday.com/2015/12/09/embed-with-elliot-debounce-your-noisy-buttons-part-i/)


I really like this circuit for 3 reasons, its got hardware debounce (less code), its simple, and there is a series resistor on the switch, so any HV transients will be reduced before hitting the GPIO.

(Some MCU's can have ESD protection built into the IC's GPIO)
See page 1 https://www.st.com/resource/en/application_note/an5612-esd-protection-of-stm32-mcus-and-mpus-stmicroelectronics.pdf
Best Regards,
The Prints Of Darkness (I forgot the 'o')
 
The following users thanked this post: Watth

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6366
  • Country: es
Re: Switch to Microcontroller digital input: default ground or Vref?
« Reply #5 on: January 03, 2025, 09:14:24 pm »
Generally it's more common to pull to ground, most mcus can enable weak pullups, this way the only required part is the button itself.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf