Author Topic: Are AVR internal pull ups good enough?  (Read 10808 times)

0 Members and 1 Guest are viewing this topic.

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6004
  • Country: us
Are AVR internal pull ups good enough?
« on: April 07, 2014, 04:02:43 pm »
I want to connect 4 configuration dip switches to an ATMEGA328P.

Is it sufficient to use the internal 'weak' pull ups or is it safer to have external resistors of lower value (e.g. 10k)?
Drain the swamp.
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 14994
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Are AVR internal pull ups good enough?
« Reply #1 on: April 07, 2014, 04:19:28 pm »
One reason you might not want to use them is, if you have a long run, the traces will be more noise sensitive, and a lower resistance can help mitigate that.  Another reason is, if you have a lot of logic connected to the pins, the leakage current will be higher, and you may need a smaller (and more accurate) resistor to guarantee a valid logic high.  (This isn't a big deal for most things, since TTL logic naturally pulls high anyway, and CMOS has very little input leakage.  It would take a lot of CMOS loads to cause a problem.)

If the switch is not too far from the MCU, it will be absolutely fine.

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline linux-works

  • Super Contributor
  • ***
  • Posts: 1945
  • Country: us
    • netstuff
Re: Are AVR internal pull ups good enough?
« Reply #2 on: April 07, 2014, 04:32:40 pm »
if there is noise nearby, I'd use 10k pullups instead of the weaker 100k ones.

I once trusted the arduino's pullups (same with a port expander) and was getting random 'button presses' which didn't make sense to me.  there was a bit of ac current nearby and some pumps and solenoids; I guess that was enough noise to render 100k useless.  once I added 10k's, all the phantom button presses went away.

buy a resistor network (SIP) and it will make things a lot more reliable.  onboard pullups generally are not trustable for robust designs.
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 14994
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Are AVR internal pull ups good enough?
« Reply #3 on: April 07, 2014, 04:39:57 pm »
Also, the tolerance of crude monolithic resistors is abysmal, usually +/-30% for the good ones.  30-70kohms comes to mind, or maybe it was 70-130k.  Apparently, Atmel's analog design process stinks, so their tolerances are even worse than usual (this also follows for the logic thresholds, which are usually 30-70% of VCC for CMOS, but I want to say they rate them as 20-80%?).  Not to mention the abysmal internal reference, crappy ADC, comparator, and power-on reset circuit (hint: if you need any of these systems to work anywhere near ideal accuracy... don't use the internals, use external parts instead!).

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: Are AVR internal pull ups good enough?
« Reply #4 on: April 07, 2014, 04:56:04 pm »
The internal "resistor" is about 50 60k. Fairly good for digital applications and I have used it for switches and encoders, or cmos gates, as long as the load is substantially different. IE 10x bigger or smaller.
================================
https://dannyelectronics.wordpress.com/
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6004
  • Country: us
Re: Are AVR internal pull ups good enough?
« Reply #5 on: April 08, 2014, 04:00:54 pm »
Thanks everybody. I can have the switches right next to the MCU and there are no other loads on those pins so based on your responses it seems to be fine.
Drain the swamp.
 

Offline Stonent

  • Super Contributor
  • ***
  • Posts: 3824
  • Country: us
Re: Are AVR internal pull ups good enough?
« Reply #6 on: April 09, 2014, 12:25:42 pm »
As an aside, if you have any glitches in reading the switches, try adding a debounce routine. You wouldn't think dip
 switches would bounce but they still could from the slight bit of noise generated during the flip of the switch.
The larger the government, the smaller the citizen.
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6004
  • Country: us
Re: Are AVR internal pull ups good enough?
« Reply #7 on: April 09, 2014, 02:54:07 pm »
As an aside, if you have any glitches in reading the switches, try adding a debounce routine. You wouldn't think dip
 switches would bounce but they still could from the slight bit of noise generated during the flip of the switch.

Good point, thanks.

BTW, I would expect *any* mechanical switch to bounce.  ;-)
Drain the swamp.
 

Offline Crazy Ape

  • Regular Contributor
  • *
  • Posts: 181
Re: Are AVR internal pull ups good enough?
« Reply #8 on: April 09, 2014, 03:18:35 pm »

Good point, thanks.

BTW, I would expect *any* mechanical switch to bounce.  ;-)

What about a 'Mercury tilt switch'  ;)
 

Offline Jarrod Roberson

  • Regular Contributor
  • *
  • Posts: 71
Re: Are AVR internal pull ups good enough?
« Reply #9 on: April 09, 2014, 03:25:26 pm »
BTW, I would expect *any* mechanical switch to bounce.  ;-)

All mechanical switches have some "bounce". Jeri explains it very well, here.

 

Offline NANDBlog

  • Super Contributor
  • ***
  • Posts: 4631
  • Country: nl
  • Current job: ATEX certified product design
Re: Are AVR internal pull ups good enough?
« Reply #10 on: April 09, 2014, 03:52:14 pm »
OK, let's see a bad case situation. you have a 1mm PCB, and you run 0.5mm tracks on two side of the board, right on top of each other, one is from the switch, one is a noisy AC signal. You will have 0.06pF/mm coupling between them. If you run them along for 100mm, that is a total of 6pF coupling. Your input capacitance is only ,say 1pF, and your pull-up is 47Kohm. Now, if you put a 100Vpp AC signal at 10Khz on the noise source, you will have 1.8V noise on your switch, and you might be able to read a wrong value. I hope I was able to describe it with ridiculous numbers. But sometimes we design this kinda things, so in that case, you need the stronger pull-up.
 

Offline linux-works

  • Super Contributor
  • ***
  • Posts: 1945
  • Country: us
    • netstuff
Re: Are AVR internal pull ups good enough?
« Reply #11 on: April 09, 2014, 04:40:05 pm »
one of my arduino projects was to embed an lcd display, pid controller and set of relays and switch sensors into an espresso machine.  I rewired the 110v switches to be logic based and used relays to control things.  I was getting a lot of random stuff going on and general cpu freak-outs until I used real 10k pullups on all switches that I would logic-sense.  also had to add 10k's for my i2c bus.  just could not rely on the ones in the arduino chip or the port expander chips.  once I added the pullups, the random freak-outs stopped entirely and never came back.

playing around with toys in a lab is one thing.  when you want industrial stuff to work and not freak-out (lol) you use pullups outside the chip and never rely on the weak ones in the chip.  at least that's my new mantra ;)
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 14994
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Are AVR internal pull ups good enough?
« Reply #12 on: April 09, 2014, 05:17:01 pm »
If you've got wires going deep inside a machine, you should opt for something far more robust -- 24V 20mA signaling is very common in industrial practice, even 120VAC.  Run it straight into relays, if you can!

Do whatever analog signal conditioning you can; a simple RC filter going into the port, with a time constant on the order of the sample rate, does wonders for getting rid of ambient noise (that 100V 10kHz figure probably would get pushed into the 10kV range -- now we're talking, like, ESD resistance!).  Don't forget external protection clamp diodes, too.

It also helps to repeatedly poll and average the pin state.  I like to use a 5-10ms sample period and look three or four samples in a row (you can use a circular buffer, or just shuffle the array elements around, it's not like it's a lot of memory).  At any given time, the switch is considered 'on' if the pin read low for all samples in memory, or 'off' if it read high for all samples.  For 1 to N-1 samples high, make no change.  This implements a short sliding-average filter with hysteresis.  It doesn't guarantee that bounce or noise won't cause problems (that's nearly impossible), but it serves well enough that I can, for example, draw a wire over a rusty panel (grounded) and get a reliable "press" signal despite the immense noise of this action.

This is also easy to implement in VHDL if you're doing something on a CPLD or FPGA.

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: Are AVR internal pull ups good enough?
« Reply #13 on: April 09, 2014, 05:57:21 pm »
Any scheme designed by man will fail, sooner or later, or in at least one scenarios.

It is unnecessary and foolish to attempt to design a circuit that will work under all conditions. A good engineer knows what compromise to make so that an imperfect system will work perfectly for its intended applications.

I have yet to see the OP articulating a set of conditions that would suggest, to any reasonable person, that the weak pull-up will fail to work.

Rather than showering the OP with countless conditions under which a weak pull-up ****could**** fail, it would be quite helpful if you can demonstrate, with reasonable plausibility, that the weak pull-up ****will**** fail in this case; If so, propose a solution.

================================
https://dannyelectronics.wordpress.com/
 

Offline linux-works

  • Super Contributor
  • ***
  • Posts: 1945
  • Country: us
    • netstuff
Re: Are AVR internal pull ups good enough?
« Reply #14 on: April 09, 2014, 06:06:42 pm »
lets be real, here, guys.  pullups are a few pennies and are a good design assurance.

this is not huge real estate or circuit complexity or cost.  its not even worth thinking more than 2 minutes about.

put them in and you get more reliability than not having them.  its just that simple.  some things don't need deep thought and if insurance is cheap, sure, go for it.  nothing wrong with over-design when it costs just pennies.
 

Offline Araho

  • Regular Contributor
  • *
  • Posts: 72
  • Country: no
Re: Are AVR internal pull ups good enough?
« Reply #15 on: April 09, 2014, 06:23:42 pm »
Well, pullups do cost current, which can be a bummer if you need to stay within sleep-specs for USB, for instance.

But I use external pullups on at least all prototypes, and simply don't solder them in if they're not needed. That way I have a fail-safe, and the real estate needed is so low it isn't worth thinking twice about.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: Are AVR internal pull ups good enough?
« Reply #16 on: April 09, 2014, 06:39:50 pm »
Quote
nothing wrong with over-design when it costs just pennies.

Over-design is really a lazy way to cover one's lack of knowledge about potential shortfalls of a design.

Take pull-up for example. If you pick a 10k pull-up, what about cases where you need 1k? if you pick 1k, how about interference with cable runs? If you put one transmitter/receiver, how about a 20mile cable runs? ....  Where do you end your "over design"? If you end somewhere, you have to make compromises and take the risk that your over-design will fail under some scenarios.

The goal of any design is not to put forth a perfect product that will never fail. Instead, design a flawed product that works for your application.

Yes, pull-ups can be very expensive, contrary to popular believes.
================================
https://dannyelectronics.wordpress.com/
 

Offline suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1455
  • Country: us
Re: Are AVR internal pull ups good enough?
« Reply #17 on: April 09, 2014, 06:58:35 pm »
Well, pullups do cost current, which can be a bummer if you need to stay within sleep-specs for USB, for instance.

Or if you're designing a low power device.  I'm currently working on a prototype that has an idle current draw of just a few hundred uA, and an active current draw of around 1mA.  There are a lot of switches, and everything runs on 3.3.  In this application, a single 10k pull up/down resistor with a switch set the right (wrong?) way would double the idle current draw, and increase the active current draw by 33%.  If I used 10k pull resistors on all of my switches, my current draw would increase by a factor of 10 and battery life would plummet.

Instead, I use selectable pull up/down resistors in the uC that I can turn off when not needed together with software debouncing to account for any interference.  Would the system still work correctly if thrown into a 1000VAC bundle of wiring?  Probably not, but that's a compromise I'm willing to make.
« Last Edit: April 09, 2014, 07:01:35 pm by suicidaleggroll »
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: Are AVR internal pull ups good enough?
« Reply #18 on: April 09, 2014, 08:40:51 pm »
Quote
but that's a compromise I'm willing to make.

Precisely. The art of engineering is really the art of making compromised, and by definition, flawed designs. Knowing when / where / how to make that trade-off separates the men from the boys (of engineering).
================================
https://dannyelectronics.wordpress.com/
 

Offline linux-works

  • Super Contributor
  • ***
  • Posts: 1945
  • Country: us
    • netstuff
Re: Are AVR internal pull ups good enough?
« Reply #19 on: April 10, 2014, 02:47:54 pm »
Quote
but that's a compromise I'm willing to make.

Precisely. The art of engineering is really the art of making compromised, and by definition, flawed designs. Knowing when / where / how to make that trade-off separates the men from the boys (of engineering).

I hate to grossly over-engineer but a little 'head room' is not a bad thing in designs.  I do not like to make the design 'just barely work'; I want it to work in more cases than I initially had in mind.  higher temperature ranges, more tolerance for voltage variations, working in the fact of emi/rfi, whatever. 

I could argue that a good engineer adds sufficient headroom to his designs so that they work better (or in more configurations or environments) than is needed.

again, we're talking a few pennies for pullups.

I see the validity of the switchable argument; and if you need to do multiuse things on pins, you may want to remove a pullup on command.  I'm not a big fan of that kind of design but I do see the point in having switchable resistors.

just seems a mistake to count on those very weak ones.  the design works - up until it doesn't...
 

Offline peter.mitchell

  • Super Contributor
  • ***
  • Posts: 1568
  • Country: au
Re: Are AVR internal pull ups good enough?
« Reply #20 on: April 10, 2014, 03:22:14 pm »
The biggest things that pullups steal imho is board space and PnP time. If in all expected use scenarios they aren't needed, don't put them in, if someone uses it differently and it doesn't work, tell em it isn't meant to be used like that. Simple.
 

Offline linux-works

  • Super Contributor
  • ***
  • Posts: 1945
  • Country: us
    • netstuff
Re: Are AVR internal pull ups good enough?
« Reply #21 on: April 10, 2014, 03:46:23 pm »
see, that's were we disagree when it comes to product design.  what you envision the thing doing may not be the whole use-case set of it.

I've used things in situations that they were not designed for.  and I praised the designer who went over and above the call of duty and over-designed things.

if you are designing to a price sensitive point, I understand that; but for hobby use or one-off use, its not expensive and board space is usually not an issue.  maybe the thing won't be in a noise environment now but perhaps it might, later on.  all kinds of things you can't see until you design, ship and then watch what happens in the field.  gee, in the lab, things worked great; but some customers have having intermittent problems on buttons.  what on EARTH should we do??? ;)

again, I'm not suggesting gross over-design on everything; but a little headroom is not a bad concept to buy into.  especially when the insurance is measured in pennies.
 

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 12123
  • Country: gb
    • Mike's Electric Stuff
Re: Are AVR internal pull ups good enough?
« Reply #22 on: April 10, 2014, 04:12:51 pm »
..of course there is the real cheapskate approach of setting a pin high for one cycle then relying on pin capacitance to hold the value while you read it...

...I'll get my coat. ;)
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf