Products > Embedded Computing

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

(1/5) > >>

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

rstofer:

--- Quote from: Kagord on February 24, 2019, 06:27:14 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?

--- End quote ---

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

Richard Crowley:

--- Quote from: Kagord on February 24, 2019, 06:27:14 pm ---Does this mean they don't know what the actual/specific resistance is in the controller? 
--- End quote ---
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.
--- End quote ---
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,
--- End quote ---
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? 
--- End quote ---
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.

rstofer:
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!

Kagord:
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?

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod