Products > Embedded Computing

Arduino Internal Pullup Resistor Question - Starting out and in the weeds

<< < (3/5) > >>

One thing you might want to do is update your mental model to include stray capacitances.

With a capacitance what you have is an R/C circuit charging from the supply voltage of the micro (say 5V).

The R is the pullup (20k to 50k, or 100k to 150k). The C is the stray capacitance, say 1pF. There is also the switch which can short out the capacitor to 0V, and when released, start the charging process so that the voltage across C gradually charges from 0V to 5V.

The time constant of 100kohms * 1pF is 100e3 * 1e-12 = 100e-9 or 100ns. So basically when you press the switch the voltage seen by the input to the micro goes to 0V instantly. When you release the switch the voltage goes to 5V, 100ns later. (Actually it will pass the input threshold of 2.5V about 100ns later and asymptotically approach 5V taking infinite time to do it, but we ignore that).

With the stray capacitance mental model it is clear why the manufacturer doesn't use say 1Mohm, despite the power saving (100kohm draws 5V / 100e3 or 50uA whereas 1Mohm draws 5V / 1e6 or 5uA while the switch is pressed), it's because 100ns is an acceptable time to respond to the switch release but 1us isn't (in their opinion, and assuming C = 1pF).

Another useful mental model is to consider the switch and associated wiring as an antenna. We can model this as a 10M resistor connecting the switch to a randomly changing voltage of say 0V to 5V. The 1M pullup and the imagined 10M resistor would form a voltage divider between the 5V supply and the random supply, thus forming a weighted average that favours the known fixed 5V supply by a factor of 10:1. With the 100k pullup this becomes a factor of 100:1 which is much safer. So basically with the 1M pullup your C is being charged by an unknown voltage from 4.5V to 5V whereas with the 100k pullup it is from 4.95V to 5V (with this model and assumptions of course). The latter way is much more predictable.

If an accurate R value is needed then the manufacturer can measure it after the chip is fabricated and use a laser to cut off part of the resistor's area in the silicon chip until the value is exactly 100kohm, before the chip is packaged. They don't do this for cheap commodity micros or programmable input pullups because it is expensive to do and because you can just allow for the larger value in your design: if pullup can be up to 150kohm then allow up to 150ns to respond to the release of the switch (and the estimated C = 1pF is not accurate, so laser trimming is pointless). Also as another poster mentioned, even the laser trimmed resistor can vary with temperature and supply voltage.

Hope it helps.

cheers, Nick

edit: change 1ms to 1us.

Richard Crowley:

--- Quote from: Kagord on February 24, 2019, 09:43:54 pm ---Makes sense, I think I got it.  But let me go over my thinking, so let's say the pull up resistor is within spec of 20-50K on a 5V pin.  The pinMode with INPUT_PULLUP is set and button open state is on, (actually, regardless of anything actually hooked up to that pin, digitalRead return is
--- End quote ---
Yeah, I'm not sure what all that means. I think you mean simply when the internal pullup is enabled and nothing is pulling the pin down.

--- Quote --- 1).  So behind the scenes, something is monitoring 5V constant (or ??) near that pin and returning 1 with the digitalRead function call.
--- End quote ---

On each input pin there is a digital "comparator" that decides whether the pin is "high"=1 or "low"=0.  The data sheet tells you at what voltage is considered zero and what voltage is considered one.

--- Quote ---When I hit the button we have a "theoretical" current of 0.1 to .25 mA running to ground, based on Ohm's Law, if I did my math right.
This creates a voltage drop from 5V to something less, but enough (within spec) to trigger 0 on the digitalRead function call. 
--- End quote ---
When you connect the pin to ground (by a button or whatever method, it doesn't matter) you will be drawing between 0.0001mA (1 micro amp = 1uA) and 0.0025ma = 2.5 uA

--- Quote ---With no resistor, maybe 5000 mA current goes to ground, which is bad, a short.
--- End quote ---

Not a very proper description  By "no resistor" we will assume that you mean "with a resistance of 0 ohms)  "no resistor" could also mean "with no connection = infinite ohms".
Clearly a pullup resistor of zero ohms is useless and absurd.

--- Quote ---If I use a resistor with millions of Ohms, the voltage drop isn't detectable.
--- End quote ---
On the contrary, the voltage drop is hyper-detectable. To the point where it will produce random results (i.e. "noise")  A resistor of infinite ohms (i.e. no resistance at all) is just as useless as zero ohms.

--- Quote ---And it's precise to have a known 5V and detect a drop, then detect voltage added to determine on/off, because current (let's say in small amounts) can come from anywhere.
--- End quote ---
It doesn't really matter what the voltage is.  The comparator operates on the percentage of VCC (the supply voltage).  For example, if the voltage is less than 15% of VCC then that is considered to be zero.  And if the voltage is more than 85% of VCC then that is considered to be one.

--- Quote ---So now, I have to put this in terms I know.  Let's say my car battery reads 12 volts, I turn on the headlights, the voltage drops to 9.5V, I can visually detect that with my multimeter (I.E I see a jump in the meter and can determine easily that something just started using using power), current is flowing.  I wouldn't want to just jumper cable the battery to see the voltage meter move.  The Arduino is doing something similar with the digitalRead functionality, 20-50K ohms is considered a good ranged for this.
--- End quote ---
That is a very rough analogy where you are depending on the internal resistance of the battery and the resistance of the headlight wires to form a very low-impedance "pullup".

The concept of the internal pullup resistor seems a lot simpler than what you are making out of it.  Not clear why it is so important?

"The concept of the internal pullup resistor seems a lot simpler than what you are making out of it.  Not clear why it is so important?"

It's not important, but I'm trying to really understand this, "end to end", what's going on.  I realize it's not a good sign that this is only the 2nd circuit I have looked at in my life, the first one being a blinking led (pin 13) on the Arduino, and I'm hung up on this 2nd circuit.  I find it really fascinating though, even this simplistic button circuit.  I think I'm going to have to take some electronics courses now to get grounded in theory.  I just bought a book and just learned electrons, in quantities I can't fathom, travel opposite of current flow, now I'm stumped on that as well, like if the electrons aren't current, what is actually moving in the other direction?  No need to answer, I'll internet research this or learn in a class.  This Odyssey of mine started because I bought a SmartThings, and saw Arduino somewhere in a review (never heard of it before) and starting looking into what that was, and I bought one, and now I'm here.  So yes, this is probably so basic for 99.9% of this forum, but for me, it's brand new.

Anyways, I think i was hung up on a voltage pin configured for input, that was pre-charged, or in electronic's vernacular, "voltage pulled up to the pin with a resistor" for output voltage.  I get it now, floating voltage doesn't work and this is a solution to that.  Now I want to read that voltage on that pin, but I have to find my dad's Micronta multimeter that is in a box somewhere in the attic.

Yes, the Arduino is NOT electronics. If you need a programmable "thing" then by all means use it but if you want to understand electronics then there is more ground work to do before you get to micro controllers. To understand what is happening here you need to understand potential dividers.


--- Quote from: Kagord on February 25, 2019, 06:44:20 pm ---"The concept of the internal pullup resistor seems a lot simpler than what you are making out of it.  Not clear why it is so important?"

It's not important, but I'm trying to really understand this, "end to end", what's going on.  I realize it's not a good sign that this is only the 2nd circuit I have looked at in my life, the first one being a blinking led (pin 13) on the Arduino, and I'm hung up on this 2nd circuit.

--- End quote ---

There is quite a path to understanding all of this but here's another rule:  Never let CMOS inputs float.  The voltage on the pin needs to be either higher that VIH or lower than VIL.  As long as you use a reasonable pullup resistor and pull to ground with a switch, you will meet the requirements.  I told you the VIH had to be higher than 0.6VCC and, for a 5V device this needs to be > 3V.  OK, our pullup resistor can drop 2 volts (5V - 3V) with 1 uA current (remember IIH?).  That means the maximum resistor value is 2V / 1 uA or 2 MOhms.  A resistor less than or equal to 2 MOhms will guarantee the logic level is met.

Then you were told that the current through the switch should be on the order of 5 mA.  Again, for a 5V device that works out to 5V / 0.005 A or 1K Ohms.  So, something on the order of 1K will CLEARLY meet the logic level requirements and also the minimum current through the switch.

That's all there is to the concept.  Well, there are a couple of other things like the 330 Ohm series resistor that I recommend but for which there is no absolute requirement and  if you decide to use a pulldown resistor and pull up to Vcc, I would absolutely use the series resistor.  I don't like dumping a solid VCC into a pin.  This is a 'yesterday' kind of rule but I still like it.

Start with Ohm's Law.  Migrate to the Real Analog course at Digilent
Or the EE program at Khan Academy

Do NOT involve yourself in the electron flow versus conventional current flow debate.  For almost every practical purpose, conventional current flow is the accepted way of dealing with things.  To my knowledge, only the US Navy insisted on electron flow for their ET program.  In the end, it doesn't make any difference but it is simply easier to assume current flows from + to -.

With conventional current flow, you can follow the arrow on transistors and diodes.  You don't have to think in terms of electrons flowing upstream.  You can read schematics from top to bottom (usually drawn with + rail on top).  Now, if you want to major in Physics, I suspect you would use electron flow.  Just for the device physics.  The engineers, the guys who hook things up, are going to use conventional current flow.


[0] Message Index

[#] Next page

[*] Previous page

There was an error while thanking
Go to full version