Wiring input switch to ATmega88 with internal pull-ups

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi there,

I've read a number of posts on this topic, but would like clarification that the following is okay.

I wish to wire a simple switch to an input pin on the ATmega88. The circuit is as simple as the following:

               ---
    Pin -------o o--------- GND

Enabling the internal pull-up on the input pin will ensure it is high when the switch is open, cool. However, when the switch is held closed, the input drops low sourcing current through the pull-up. I'm concerned that an extra resistor should be added somewhere between the pin and ground to limit this current.

The datasheet says that the minimum internal pull-up resistance is 20kOhm, so at 5v this will provide a tiny current, 5/20k = 0.25mA. The power is 1.25mW. This looks to be very small, well below the 40mA DC current limit per pin.

Given I'm not implementing a super-low power device, is my circuit okay, even if the switch is held closed for long periods?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No need for a poll :) All answers apply. It all depends on the environment.

It's perfectly fine to use the internal pull-up: that's what they are for.
BUT:
- If your switch is on a cable a few feet from the AVR, then you need to take extra precautions.
- If your environment is very noisy (switching power-supply, relays etc), it is necessary too to take extra measures.

Nard

A GIF is worth a thousend words   They are called Rosa, Sylvia, Tessa and Tina, You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm happy using the pull-ups. More I'm wondering if grounding the input without another resistor is entirely safe. Since you didn't mention this, I'm starting to suspect there is no problem there?

FWIW, the switch will be on a circuit board, close to the ATmega88. There are no relays nearby, but there are two servos, although they are running from a regulated 6v supply with bypass caps and protection diodes. The ATmega is to be on a regulated 5v supply with a cap close to the supply pins too. I'm hoping noise should not be a problem :-/

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I see. I didn't answer that one indeed.

Let me put it this way: if you don't do silly things during the development of the program, there is no need for a safety-resistor in the line from input-pin to switch.
But if you're human, work too hard/too long, and by accident configure that pin as an output ..... then a safety-resitor is a wise choice. 470 ohm is a good choice then: it's very low compared to the internal pull-up, and high enough to limit the output-current to 10 mA.
To make it complete: if you encounter noise-issues, add a capacitor of 10 nF (BPF) to the pin. Not necessary in your current configuration.

Cheers

Nard

A GIF is worth a thousend words   They are called Rosa, Sylvia, Tessa and Tina, You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brilliant! I failed to consider misconfiguration of the pin - thank you for pointing this out!

I'll add a series resistor as you say.

Many Thanks,

Mike

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Many switches has problems with oxidation, and thus malfunction, if the current in the on position is below approx. 2 mA

ekh

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Many switches has problems with oxidation, and thus malfunction, if the current in the on position is below approx. 2 mA

ekh

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That is a good point. So while internal pull-ups are perfectly OK, there might be a need for stronger pull-up to get the required say 2mA when pushing the button. The series resistor is a nice idea too.

Would the oxidation problem stay away, if there is no strong pull-up to provide 2mA, but a capacitor which is disharged through the switch when flipped? The capacitor would filter out the button signal too, and the series resistor would limit the current so that the discharge current is smaller than what it would be when short-circuited. There is still the problem that if AVR pin is set to an output, it will charge the cap with quite a big current, but it might survive as the DC is not that great. Worst case is if the signal is outputting some square wave. So it would be the ultimate switch connection to add another series resistor..

Care must be taken so that the contacts stay clean but the pulsed current spike does not eat away the contacts.

  
                          Rs    Rpu
 AVR pin with      o----+-[]-+--[]--o Vcc
 internal pull-up       |    |
                      C =    =| SW
                        |    |
               GND o----+----+

  Optional pull-up resistor Rpu = 1k..10k (DC 5mA..500uA @ 5V Vcc)
  Series resistor Rs = 100R (pulsed 50mA @ 5V Vcc)
  Filter/Storage capacitor C = 1nF..100nF
  ( or whatever caps there are on the board that makes suitable RC constants) 

- Jani

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The 2 mA as minimum for a reliable contact may be valid for some switches, but not all. Look f.i. at the switches/buttons on your cell-phone: no way there is 2 mA flowing when pushed.
Small signal switches have (in general) silver, sometimes even goldplated contacts.

Nard

A GIF is worth a thousend words   They are called Rosa, Sylvia, Tessa and Tina, You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And most advanced have mercury wetted contacts. But I got a feeling this RoHS has put an end to that.

- Jani