Author Topic: Arduino Internal Pullup Resistor Question - Starting out and in the weeds  (Read 4373 times)

0 Members and 1 Guest are viewing this topic.

Offline Kagord

  • Contributor
  • Posts: 11
  • Country: us
OK, just starting out here on my journey and trying to really understand fully this pull up resistor concept, this is only my 2nd project in electronics, the blinking led on pin 13 I understood.  But this pull up resistor, I'm spinning on.

Explanation of pullup resistors solving for a push button on/off and why it's needed, kind of get that.


So, as I understand this, we set up a pin to default read on (voltage present).  Shorting the pin to ground turns off.  The video states a 10K pullup resistor. 

The Arduino documentation:
The value of this pullup depends on the microcontroller used. On most AVR-based boards, the value is guaranteed to be between 20kΩ and 50kΩ. On the Arduino Due, it is between 50kΩ and 150kΩ. For the exact value, consult the datasheet of the microcontroller on your board.

OK, here's a datasheet I googled...
https://www.farnell.com/datasheets/1682209.pdf
"Each pin can provide or receive a maximum of 40 mA and has an internal pull-up resistor (disconnected by default) of 20-50 kOhms"

Does this mean they don't know what the actual/specific resistance is in the controller?  But more to the point, why 10K, or 20K, or 50K, does it matter, how low can you go, who knows the reasoning here for the level needed for resisting the current flow in this application.  I assume if there is no resistor present, that's not good, but how is the value of the resistor determined and how is that important.  Is there science behind it, or is someone just innately saying, ahh, 20K-50K, that will work every time for most anticipated scenarios that could be present? 

Edit, any help appreciated in understanding this concept more, I don't have any electronics background, but feel the need to understand the why, TIA.

« Last Edit: February 24, 2019, 06:44:35 pm by Kagord »
 

Online rstofer

  • Super Contributor
  • ***
  • Posts: 9325
  • Country: us
Re: Arduino Internal Pullup Resistor Question - Starting out and in the weeds
« Reply #1 on: February 24, 2019, 06:51:19 pm »
OK, here's a datasheet I googled...
https://www.farnell.com/datasheets/1682209.pdf
"Each pin can provide or receive a maximum of 40 mA and has an internal pull-up resistor (disconnected by default) of 20-50 kOhms"

Does this mean they don't know what the actual/specific resistance is in the controller?  But more to the point, why 10K, or 20K, or 50K, does it matter, how low can you go, who knows the reasoning here for the level of resisting the current flow.  I assume if there is no resistor present, that's not good, but how is the value of the resistor determined and how is that important.  Is there science behind it, or is someone just innately saying, ahh, 20K-50K, that will work every time for most anticipated scenarios that could be present?

Yes, it means that they don't know nor care what the value turns out to be.  It doesn't matter because while it is suitable for pulling up unused pins, it is just about worthless for external interfaces.  The value is too high, it is too susceptible to external noise, generally worthless.  OTOH, we want to define unused pins as input and pull them to some guaranteed level - high or low, doesn't matter.  Since we have the internal pullup resistor, we will pull the unused pins high.

Second thing:  NEVER use a solid Vcc as an input.  That's an old school rule but it was an actual LAW (not really, but close).  Use something like a 1k pullup on the pin and pull it down to a solid ground.

OTOH, there's another RULE that should be a LAW:  Always put a 330 Ohm resistor in series with every used IO pin, input or output.  How many chips do you imagine have been blown up when a pin was configured for output, set high and then shorted to ground with a pushbutton on the wrong pin?  More than one!

CMOS doesn't take much input current so a 330 Ohm resistor won't change the voltage very much.  The only reason we're using a 1K pullup is to provide enough current flow for the switch to function properly.  The problem with high value resistors is they don't provide enough current flow to keep the contacts clean.

A low value of pullup resistor only conducts current when the switch is closed.  When the switch is open, the only current flow is the pin input current and that is VERY low.  Yes, you can go up to 10k and maybe higher.  I don't but it probably works.  1K almost always works.

ETA:  Why do we define unused pins as input?  Because if we have an 'oopsie' and short the pin to Vcc or Gnd, all it does is change an input signal that is never used.  If the pin were output, we stand a good chance of watching the magic smoke come pouring out of the chip.  Remember that 330 Ohm resistor?  It too helps with 'oopsies'.

« Last Edit: February 24, 2019, 06:57:11 pm by rstofer »
 
The following users thanked this post: Richard Crowley, Moriambar

Offline Richard Crowley

  • Super Contributor
  • ***
  • Posts: 4314
  • Country: us
  • KJ7YLK
Re: Arduino Internal Pullup Resistor Question - Starting out and in the weeds
« Reply #2 on: February 24, 2019, 07:40:19 pm »
Does this mean they don't know what the actual/specific resistance is in the controller? 
It means that the internal pullup resistors are not a precision part of the circuit and the exact value is not all that important.

Quote
But more to the point, why 10K, or 20K, or 50K, does it matter, how low can you go, who knows the reasoning here for the level of resisting the current flow.
Sure they could make it much lower, but:
1) The internal pullup is just a handy convenience for ultra-low parts count circuits. 
2) If a more robust pullup value (or a pulldown resistor) is required, it is trivial to add one externally.
3) The lower the value of the internal pullup resistor, the more power the chip dissipates when current is flowing through the resistor and out of the pin to ground. This is an undesirable condition and trivially avoided by using higher-value internal pullup resistors.
So there appear to be several disadvantages and no advantages to using lower-value pullup.

Quote
I assume if there is no resistor present, that's not good,
The impedance of the I/O nodes in input mode is pretty high and with no definite resistance pulling either up or down, the input value (0 or 1) will be unpredictable. And THAT is not good.

Quote
but how is the value of the resistor determined and how is that important.  Is there science behind it, or is someone just innately saying, ahh, 20K-50K, that will work every time for most anticipated scenarios that could be present? 
Essentially.  It is a reasonable and pragmatic balance between the needs of the majority of users' application circuits and the limits of the chip/package power dissipation budget.
 

Online rstofer

  • Super Contributor
  • ***
  • Posts: 9325
  • Country: us
Re: Arduino Internal Pullup Resistor Question - Starting out and in the weeds
« Reply #3 on: February 24, 2019, 08:10:16 pm »
Another reason for keeping the internal pullup resistor some high value:  Suppose your application calls for a pulldown resistor.  You are now forming a voltage divider and you pulldown needs to be a fairly small value to guarantee your pin voltage is well withing the switching threshold.

If the factory put in a 1k pullup, you would need a 100 Ohm pulldown to get within 10% of Vcc.  That's a pretty low value...

There's some amazing information in datasheets.  Check the switching thresholds and the low and hgh voltage input currents.  Then play with Ohm's Law!

 

Offline Kagord

  • Contributor
  • Posts: 11
  • Country: us
Re: Arduino Internal Pullup Resistor Question - Starting out and in the weeds
« Reply #4 on: February 24, 2019, 09:43:54 pm »
Thanks for the replies!

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 1).  So behind the scenes, something is monitoring 5V constant (or ??) near that pin and returning 1 with the digitalRead function call. 

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.  With no resistor, maybe 5000 mA current goes to ground, which is bad, a short.  If I use a resistor with millions of Ohms, the voltage drop isn't detectable. 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.

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.

Do I have this right, TIA?
« Last Edit: February 24, 2019, 10:04:39 pm by Kagord »
 

Online Simon

  • Global Moderator
  • *****
  • Posts: 16927
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Arduino Internal Pullup Resistor Question - Starting out and in the weeds
« Reply #5 on: February 24, 2019, 10:01:11 pm »
The pullup is built into the chip which is why the exact value is unknown as it's manufactured from silicon and is subject to manufacturing conditions. The actual digital input to the microcontroller is a very high resistance something in the order of 1+Mohm. So if that input is connected to 5V via 50K then the vast majority of the voltage will actually fall across the input and signal a high. This relatively high resistance though in the order of 20-50K can be safely pulled to ground as not a lot of current flows.

If you are interested, in reality that pullup is enabled on legacy AVR's like the one on the UNO by setting the pin to be an input and then sending the command to turn on the output on that pin. Nothing comes out as it is set as an input and the output driver is disconnected but the result is that this internal resistor is activated between the pin and the supply voltage. Being silicon I'd wager that the resistance may even vary with supply voltage but that is another story.
 

Online rstofer

  • Super Contributor
  • ***
  • Posts: 9325
  • Country: us
Re: Arduino Internal Pullup Resistor Question - Starting out and in the weeds
« Reply #6 on: February 24, 2019, 10:02:00 pm »
You have it more or less correct.

The button pulls the pin to ground - not almost ground, absolutely ground (+- a very few millivolts because the contacts probably aren't bifurcated and gold plated).

You can't use megohms for the reason I explained above - you won't flow enough current through the switch to get reliable switching.  You can use very low Ohms (10?) but why?  You want to flow enough current to be reliable while not consuming vast amounts of power when switching.  1k?  2.2k? 3.3k? 4.7k? 10k?  Those should all work but I would not choose 10k, especially at 3.3V.

Given the intermittent operation of the switch, I would choose 1k.

Look around at published circuits and see what the authors used.
« Last Edit: February 24, 2019, 10:04:04 pm by rstofer »
 

Online Simon

  • Global Moderator
  • *****
  • Posts: 16927
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Arduino Internal Pullup Resistor Question - Starting out and in the weeds
« Reply #7 on: February 24, 2019, 10:08:27 pm »
The other thing to consider is that you want around 5mA minimum flowing through the switch or the contacts will eventually stop working because of oxidisation. That minimum current means that any layer that tries to form and insulate the contact is burnt off by the albeit tiny spark the 5mA causes.
 

Online rstofer

  • Super Contributor
  • ***
  • Posts: 9325
  • Country: us
Re: Arduino Internal Pullup Resistor Question - Starting out and in the weeds
« Reply #8 on: February 24, 2019, 10:10:47 pm »
Read the datasheet!  See 26.2 DC Characteristics and the first two values (VIL and VIH) are the switching threshold values.  0.3*VCC for VIL and 0.6*VCC for VIH.

Then look at IIL and IIH - a mere 1 uA of current flowing into or out of the pin.

https://www.sparkfun.com/datasheets/Components/SMD/ATMega328.pdf
 

Online rstofer

  • Super Contributor
  • ***
  • Posts: 9325
  • Country: us
Re: Arduino Internal Pullup Resistor Question - Starting out and in the weeds
« Reply #9 on: February 24, 2019, 10:12:19 pm »
The other thing to consider is that you want around 5mA minimum flowing through the switch or the contacts will eventually stop working because of oxidisation. That minimum current means that any layer that tries to form and insulate the contact is burnt off by the albeit tiny spark the 5mA causes.

Exactly!  That why I keep suggesting 1K.  Now, for Vcc=3.3V perhaps a smaller value is better.  670 Ohms?
 
The following users thanked this post: Kagord

Offline nick_d

  • Regular Contributor
  • *
  • Posts: 120
Re: Arduino Internal Pullup Resistor Question - Starting out and in the weeds
« Reply #10 on: February 24, 2019, 10:52:25 pm »
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.
« Last Edit: February 25, 2019, 12:39:50 am by nick_d »
 

Offline Richard Crowley

  • Super Contributor
  • ***
  • Posts: 4314
  • Country: us
  • KJ7YLK
Re: Arduino Internal Pullup Resistor Question - Starting out and in the weeds
« Reply #11 on: February 24, 2019, 11:59:32 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
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.

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. 
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.

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.
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.
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.
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?



 

Offline Kagord

  • Contributor
  • Posts: 11
  • Country: us
Re: Arduino Internal Pullup Resistor Question - Starting out and in the weeds
« Reply #12 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.  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.
 

Online Simon

  • Global Moderator
  • *****
  • Posts: 16927
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Arduino Internal Pullup Resistor Question - Starting out and in the weeds
« Reply #13 on: February 25, 2019, 06:55:54 pm »
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.
 

Online rstofer

  • Super Contributor
  • ***
  • Posts: 9325
  • Country: us
Re: Arduino Internal Pullup Resistor Question - Starting out and in the weeds
« Reply #14 on: February 25, 2019, 08:27:15 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.

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
https://learn.digilentinc.com/classroom/realanalog/
Or the EE program at Khan Academy
https://www.khanacademy.org/science/electrical-engineering

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.

« Last Edit: February 25, 2019, 08:36:30 pm by rstofer »
 

Offline retrolefty

  • Super Contributor
  • ***
  • Posts: 1648
  • Country: us
  • measurement changes behavior
Re: Arduino Internal Pullup Resistor Question - Starting out and in the weeds
« Reply #15 on: February 25, 2019, 09:00:24 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.

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
https://learn.digilentinc.com/classroom/realanalog/
Or the EE program at Khan Academy
https://www.khanacademy.org/science/electrical-engineering

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.

 The US Air Force also taught electron flow, we were told to just ignore the historical error that is 'conventional flow'
 

Offline Richard Crowley

  • Super Contributor
  • ***
  • Posts: 4314
  • Country: us
  • KJ7YLK
Re: Arduino Internal Pullup Resistor Question - Starting out and in the weeds
« Reply #16 on: February 26, 2019, 03:50:09 am »
Anybody who has been stuck in Los Angeles traffic for 3 hours intimately understands "hole flow". 
At least from the perspective of the electron.
 

Online Simon

  • Global Moderator
  • *****
  • Posts: 16927
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Arduino Internal Pullup Resistor Question - Starting out and in the weeds
« Reply #17 on: February 26, 2019, 07:28:16 am »
I spent years trying to understand it from the electron point of view and I got nowhere. Once i tarted to look at everything flowing from positive things made sense.
 

Offline Kagord

  • Contributor
  • Posts: 11
  • Country: us
Re: Arduino Internal Pullup Resistor Question - Starting out and in the weeds
« Reply #18 on: February 26, 2019, 07:14:32 pm »
Start with Ohm's Law.  Migrate to the Real Analog course at Digilent
https://learn.digilentinc.com/classroom/realanalog/

Started last night, Pre-Requisites, Calculus, Differential Equations,  I think this is going to take a wee bit longer than a few weeks.  |O

Edit, I found the Multi-Meter, there's a battery of the month club card in the box, going to Radio Shack next for my free battery, there's some no name cheap tandy that is kind of a mess.
« Last Edit: February 26, 2019, 07:22:33 pm by Kagord »
 

Online Simon

  • Global Moderator
  • *****
  • Posts: 16927
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Arduino Internal Pullup Resistor Question - Starting out and in the weeds
« Reply #19 on: February 26, 2019, 07:29:37 pm »
You don't need calculus. Calculus is for things live Fourier analysis and control systems. All you need is good old algebra and start to work on some basics of electronics.
 

Online rstofer

  • Super Contributor
  • ***
  • Posts: 9325
  • Country: us
Re: Arduino Internal Pullup Resistor Question - Starting out and in the weeds
« Reply #20 on: February 26, 2019, 09:25:33 pm »
Simon has it right!  Don't overthink the math while electronics is a hobby.

Ohm's Law including the Power equation only requires simple division.
The voltage divider is a step up but really turns out to be 2 consecutive applications of Ohm's Law.

Eventually, maybe years down the road, Kirchhoff's Law and Thenenin's Theorem come up.  Norton comes up at the same time.  Even these require just simple arithmetic although, I'll concede, mesh and nodal analysis will likely require some matrix algebra or Gauss Jordan Elimination.  Easy stuff, really!

Where you get into higher order math is when you want to play with the step response of a tuned circuit (RC, RL, RLC) and along about here you really need to step up your game.  But do you really need to deal with this stuff?  Maybe, but it can probably be handled with a hand wave. 
"It looks a lot like this...".

Yes, in the time domain, almost everything is a differential equation..  That's why Laplace Transforms were invented.  But that is years down the road, if ever.  Sure, all the EEs around here know that kind of stuff but the hobbyists?  Probably not! 

Just learn how to sling Ohm's Law around so you can solve for any 1 of the 3 variables and you're good for a long time.

E = I * R
I = E / R
R = E / I

P = I * E  (power equation)  I & E can be substituted with their Ohm's Law equivalent so P = (E2) / R or P =( I2) * R, etc

Those 4 will get you a long way down the road.



« Last Edit: February 26, 2019, 09:29:23 pm by rstofer »
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4099
  • Country: us
Re: Arduino Internal Pullup Resistor Question - Starting out and in the weeds
« Reply #21 on: February 27, 2019, 02:53:28 am »
Damn, I disagree with every single part of Rstofer's post. Maybe I'm wrong but I think this post is completely out of touch with modern CMOS practice. Maybe as pertains specifically to the OP, some of it is useful. But as a general rule (or LAWs)? I do no subscribe to any of these rules.

Quote
Yes, it means that they don't know nor care what the value turns out to be. 
Well, the chips are "grown" in a lab. The values that results will vary, from batch to batch. These values represent the extremes of what they get before they throw out batches as bad. There are a ton of other electrical values they have to test for, so allowing a relatively large range in the pullups greatly increass yields and reduces your cost. It's a value that is not particularly important and can be replaced externally, if it does matter.

Quote
It doesn't matter because while it is suitable for pulling up unused pins, it is just about worthless for external interfaces.  The value is too high, it is too susceptible to external noise, generally worthless. OTOH, we want to define unused pins as input and pull them to some guaranteed level - high or low, doesn't matter.  Since we have the internal pullup resistor, we will pull the unused pins high.

This is an opinion. You don't have to define unused pins as inputs. In fact, you should define NC pins as outputs for the lowest amount of power draw when that matters! The internal pullup is literally there for interfacing with external signals, and the value is appropriate for general purpose use. The transition between logic high and low in CMOS is much closer to Vss than Vdd, compared to older logic. I wanna say it's 1.5V for a 5V device. So there's a good amount of tolerable noise that is invisible to a digital input pin. Older logic chips had transition levels closer to the middle.

Quote
Second thing:  NEVER use a solid Vcc as an input.  That's an old school rule but it was an actual LAW (not really, but close).  Use something like a 1k pullup on the pin and pull it down to a solid ground.
This is fine, but it is relative. You are using "solid Vss" as an input. The main reason to use solid Vss and a high impedance (pulled up) Vdd is due to convention. There are many examples of the opposite. Many modern digital watches, for some reason, use the positive rail as com, and the inputs are pulled down to ground. There are also many IC's that have logic level push pull outputs made to interface to microcontroller input pins. It's not all open collector outputs, anymore.

Quote
OTOH, there's another RULE that should be a LAW:  Always put a 330 Ohm resistor in series with every used IO pin, input or output.  How many chips do you imagine have been blown up when a pin was configured for output, set high and then shorted to ground with a pushbutton on the wrong pin?  More than one!
I'm not sure what this is all about. If you are making an arduino board for playing around with, sure. Try to minimize mistakes by the user. 99.99% of microcontrollers are not "end user configurable computers." They are put into products. You don't add 20 parts to your product just in case you accidentally configure the microcontroller incorrectly on board number 17. You make the firmware and board, and then you pump them out. If driving a transistor or LED or any number of other things, you will need to use an appropriate resistor, as you have calculated, anyway. And the value won't necessarily be 330R.

Quote
CMOS doesn't take much input current so a 330 Ohm resistor won't change the voltage very much.  The only reason we're using a 1K pullup is to provide enough current flow for the switch to function properly.  The problem with high value resistors is they don't provide enough current flow to keep the contacts clean.
This 330R is not a terrible idea, but not really necessary. If your inputs/output are all Vdd or lower, with a modern 3-5V micro you are not particularly likely to burn out a pin by accidentally making it an output and further accidentally connecting it to voltage rail anywhere between Vss and Vdd. You will just watch your output voltage sag to match the rail, and your micro will burn 20mA of power. With older 12V stuff, that would be a more legitimate concern. And even then, only if you're making a "12V arduino" for consumer edutainment.

Quote
A low value of pullup resistor only conducts current when the switch is closed.  When the switch is open, the only current flow is the pin input current and that is VERY low.  Yes, you can go up to 10k and maybe higher.  I don't but it probably works.  1K almost always works.
If you have noise issues with 10K pullup, it's likely there's so much noise many modern micros won't function at all. And if there are issues that don't affect the micro, then you have a functioning micro. You can deal with bounce and/or noise with firmware. Not that it's always practical. Now if there's a 10 foot cable between your switch and your micro and it's wrapped around a motor, then you might have some noise. You can cross that bridge when you get there, and you will learn more.  And maybe if you have an impossibly clean button and can tap it fast enough to manually do I2C protocol, or something, then you need 1K pullup... or w/e is specified by the protocol for that bus or w/e value is dictated by the signal speeds you need for your application. For a physical switch to be pushed by a 200 lb gorilla (and limited in frequency by bounce, in case you are planning to use a button pushing robot), 50K is quite often as good as anything.

Quote
ETA:  Why do we define unused pins as input?  Because if we have an 'oopsie' and short the pin to Vcc or Gnd, all it does is change an input signal that is never used.  If the pin were output, we stand a good chance of watching the magic smoke come pouring out of the chip.  Remember that 330 Ohm resistor?  It too helps with 'oopsies'.
Again, after you've removed the oopsies, then you can remove this nonsense from your BOM and costs and reduce your failure rate.

Furthermore, as long as the voltages the output pin are exposed to are no lower than Vss or higher than Vdd, I have had this type of failure roughly zero times. IME, it's only when driving a transistor that is sourcing voltage out of this range where a dead transistor kills the micro. If it's logic level stuff, the dead transistor is the only part that needs to be replaced (and potentially changed part numbers), IME.

OP, if you follow this advice, in particular regarding the 1K pullup and the 330R series resistor, make sure you are putting that 1K resistor on the output of the button (or other open drain/collector device). You should not put the 1K pullup on the micro pin, itself, as that would make your ViL (logic low input level) at around 1/4 Vdd. This is borderline. It's close to the limit between logic high and low for CMOS. That's for a switch that is tied to Vss. For the output of another IC that may have an allowable VoL up to 0.2V (3.3V) or 0.5V (5V), that puts your ViL squarely in grey territory. So to be clear, the pullup should go on the opposite side of the 330R series resistor from the micro.

You're already playing in a padded child-proof room with the Arduino platform. IMO, the first thing you do shouldn't necessarily be to add more padding and limitations to combat ghosts that aren't there. And if you break a couple eggs on the way to your first omelette, that's probably more efficient than stopping to learn how to pad your spoons.
« Last Edit: February 28, 2019, 09:05:43 pm by KL27x »
 
The following users thanked this post: nick_d


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf