Author Topic: Trying to understand a pull up resistor.  (Read 4114 times)

0 Members and 1 Guest are viewing this topic.

Offline HextejasTopic starter

  • Frequent Contributor
  • **
  • Posts: 315
  • Country: us
Trying to understand a pull up resistor.
« on: January 22, 2018, 10:44:32 pm »
This schematic is used to explain it and what I got from it was that it kept the pin high.
But what happens when the switch closes?  Won't the current flow concurrently to the pin and to gnd?
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 12414
  • Country: us
Re: Trying to understand a pull up resistor.
« Reply #1 on: January 22, 2018, 10:53:47 pm »
Think about voltages and voltage dividers. (And don't worry about wasted current. It might not matter unless low power consumption is high on the list of considerations.)
 

Offline filssavi

  • Frequent Contributor
  • **
  • Posts: 433
Re: Trying to understand a pull up resistor.
« Reply #2 on: January 22, 2018, 10:54:43 pm »
Current always flows to ground be it through the button or through the MCU internal circuitry, now obviously being the button resistance much less you will have that most of the current flies through the switch
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9940
  • Country: us
Re: Trying to understand a pull up resistor.
« Reply #3 on: January 22, 2018, 11:29:47 pm »
Another way to think about it is that the switch puts 0V on the pin end of the resistor.  Therefore, all of Vcc is dropped across the resistor and the pin voltage is exactly the switch voltage - 0V.

In some logic families, the switch will not only sink the resistor current, there will be some pin current flowing out of the pin.  Look at section 6.5 and the parameter IIL which stands for input current with the input low.  Note that the current is -1.6 mA.  The minus sign means the current is flowing out of the pin when the pin voltage is low.  So, our switch needs to sink the resistor current and another 1.6 mA from the pin.

Note that II of 1 mA means the resistor must provide 1 mA while holding the pin voltage above 2V according to table 6.3 parameter VIH.

From Ohm's law, the resistor should be less than 3000 Ohms:  (5V - 2V) / 1 mA = 3000 Ohms.  But that is too close to the threshold - I usually use 2.2k or even 1k.  There is an advantage to having more current flowing through the switch in that it helps clean the contacts or burn through any oxidation.

I chose the 7400 but there are similar specs for all integrated circuits.

http://www.ti.com/lit/ds/symlink/sn74ls00.pdf

I did not use the 74LS00 or 74S00 data.
 

Offline Brumby

  • Supporter
  • ****
  • Posts: 12389
  • Country: au
Re: Trying to understand a pull up resistor.
« Reply #4 on: January 23, 2018, 12:46:16 am »
This schematic is used to explain it and what I got from it was that it kept the pin high.
Quite correct.

Quote

But what happens when the switch closes?  Won't the current flow concurrently to the pin and to gnd?
Before you worry about currents, you need to understand the voltages and the impedances (resistances).

Yes, current will flow to ground and through the MCU pin - but it's the voltage on the MCU pin that is important.  With the switch closed, the resistor is doing nothing but wasting power from the supply - but that is the cost of this type of circuit element.

As said above:
(And don't worry about wasted current. It might not matter unless low power consumption is high on the list of considerations.)
 

Offline hugo

  • Regular Contributor
  • *
  • Posts: 172
  • Country: ca
Re: Trying to understand a pull up resistor.
« Reply #5 on: January 23, 2018, 12:57:29 am »
Let's say R1=5k and Vcc=5V.

[1] Switch open, MCU input pin sees 5V (high), I(R1)~ uA.
[2] Switch closed, MCU input pin sees 0V (low), I(R1)~1mA.

When the MCU is battery powered, the value of the pull-up resistor could go up to 50k (weak pull-up).
 

Offline Dubbie

  • Supporter
  • ****
  • Posts: 1115
  • Country: nz
Re: Trying to understand a pull up resistor.
« Reply #6 on: January 23, 2018, 01:12:10 am »
When I was learning this, the thing that made the penny drop for me was to just consider pull up and down resistors as a simple resistor divider. When the switch is closed, it is an 0.01ohm resistor and when it is open it is a 10Gohm resistor. Once you know how to calculate the voltage in the middle of a resistor divider, then it all becomes clear.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 20004
  • Country: gb
  • 0999
Re: Trying to understand a pull up resistor.
« Reply #7 on: January 23, 2018, 11:53:12 am »
Electricity is lazy and always takes the path of least resistance. The switch will have a much lower resistance (mOhms), than the input of a logic gate (GOhms), so when it's closed, nearly all the electrons will flow through the switch, rather than the gate input, causing the voltage to fall to near zero.

As mentioned above, if you look it like a potential divider, with the pull-up Z1 and the gate input and switch in parallel Z2. If the pull-up resistor is 5k, the gate is CMOS, so has a resistance of 1G and the switch has a resistance of 1T when open and 10m when closed.

With VIN = 5V

When Z1 is 5k and the switch is open, Z2 will be near 1G and the voltage across it near 5V.

When the switch is closed, Z2 will fall to 10m and the voltage across it near zero.


https://en.wikipedia.org/wiki/Voltage_divider
 

Offline HextejasTopic starter

  • Frequent Contributor
  • **
  • Posts: 315
  • Country: us
Re: Trying to understand a pull up resistor.
« Reply #8 on: January 23, 2018, 03:54:23 pm »
Thank you all for the excellent attempts to clarify this for me. It also seems to me that the sizing of the resistor would be based upon what is needed by the IC.
So, it confuses me a bit when I see others posting about this circuit and speaking of the resistor size somewhat casually.
I wish that I could find an example but it went something like this. " And now for a pull up we will use, Oh, i think that 10k will be about right "

And where does "pull up" come from ? Is it that we are pulling the pin up above a zero state and possibly keeping it there ?

Thanks again
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 20004
  • Country: gb
  • 0999
Re: Trying to understand a pull up resistor.
« Reply #9 on: January 23, 2018, 04:10:44 pm »
Thank you all for the excellent attempts to clarify this for me. It also seems to me that the sizing of the resistor would be based upon what is needed by the IC.
So, it confuses me a bit when I see others posting about this circuit and speaking of the resistor size somewhat casually.
I wish that I could find an example but it went something like this. " And now for a pull up we will use, Oh, i think that 10k will be about right "

And where does "pull up" come from ? Is it that we are pulling the pin up above a zero state and possibly keeping it there ?

Thanks again
Most modern ICs have a CMOS input, with an input resistance in the order of GOhms, so the resistor value is unimportant. The upper limit on resistance, is set by capacitive noise pick-up and the lower limit, by power dissipation. If it's very low power circuit, with short PCB traces connecting the switch to the input, then a 10M pull-up resistor may be acceptable, but if the switch is on the long end of a piece of cable, the resistor value would need to be much lower, perhaps under 1k, with some filter capacitor(s) and ESD supression diodes.

Older logic familiarities, such as DM74xxxx or LS (not HC, AC, HTC etc. which are CMOS),  have low impedance bipolar transistor input stages, so one needs to be more careful with the value of pull-up/down resistor values used. rstofer has covered this fairly well in his previous post.

The words pull-up, means to pull the input voltage up, towards the positive supply voltage and pull-down, means to pull the input towards the negative supply voltage.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9940
  • Country: us
Re: Trying to understand a pull up resistor.
« Reply #10 on: January 23, 2018, 04:38:55 pm »
Thank you all for the excellent attempts to clarify this for me. It also seems to me that the sizing of the resistor would be based upon what is needed by the IC.
Exactly.  For CMOS devices where input current is essentially zero, the pull-up value can be quite high.  Basically, it just has to provide enough impedance to limit noise.

The problem comes up at the switch and that's why you will see much lower values.  Switch contacts oxidize and it takes a certain amount of voltage to break through.  Keeping the contacts 'closed' takes a certain amount of current.  Switches with gold plated bifurcated contacts will switch low level signals much better than a common wall switch.  It is for this very reason that low current switches were invented.

Quote
So, it confuses me a bit when I see others posting about this circuit and speaking of the resistor size somewhat casually.
I wish that I could find an example but it went something like this. " And now for a pull up we will use, Oh, i think that 10k will be about right "
Much of design is based on what worked the last time.  There's a reason I went through all the detail in resistor sizing above.  It really does come down to reading datasheets and calculating things.  People got caught out all the time using too large of a resistor with TTL inputs.  Well, TTL isn't used much and with CMOS the values can be higher but there is still the switch itself.
Quote
And where does "pull up" come from ? Is it that we are pulling the pin up above a zero state and possibly keeping it there ?

Thanks again
Exactly!  Many logic families, particularly CMOS, don't want inputs floating.  It will actually damage the device under certain circumstances.  In all cases, the designer wants to know what logic level is on each pin.  Design can't be based on how things float.  So, pull-up resistors are used to guarantee a logic '1'.

OK, why use a resistor if we're only pulling a pin, no switch?  Because certain logic families aren't happy with a hard signal level.  You will see pins pulled directly to ground but you will not often see pins pulled directly to Vcc.

Much of the folklore about pull-up resistors goes back to TTL (or earlier) and this type of logic is obsolete.  CMOS has essentially no input current so it doesn't matter how low the value is.  You aren't saving energy by using a high value resistor because there is none dissipated because there is no current flow.  You might as well use a reasonable value to limit noise because you really aren't wasting any energy.

If I had an input from a crusty toggle switch, I would probably use a pull-up around 1k (maybe less if the contacts are really nasty).  Most other things would probably be 10k.  This is based on what worked the last time and really only applies to CMOS but CMOS is about all we use these days.  If I did run across TTL, I would use 1k to a switch (again, could be less) and 2.2k for a simple logic pull-up.  I showed earlier how to calculate the proper values.
 

Offline paulca

  • Super Contributor
  • ***
  • Posts: 4285
  • Country: gb
Re: Trying to understand a pull up resistor.
« Reply #11 on: January 23, 2018, 04:51:48 pm »
Much of the folklore about pull-up resistors goes back to TTL (or earlier) and this type of logic is obsolete.  CMOS has essentially no input current so it doesn't matter how low the value is.  You aren't saving energy by using a high value resistor because there is none dissipated because there is no current flow.  You might as well use a reasonable value to limit noise because you really aren't wasting any energy.

Of course in the example schematic, if you used a low value, such as a 100R you might get some smoke when you close the switch, depending on the PSU.

"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9940
  • Country: us
Re: Trying to understand a pull up resistor.
« Reply #12 on: January 23, 2018, 05:10:52 pm »
Much of the folklore about pull-up resistors goes back to TTL (or earlier) and this type of logic is obsolete.  CMOS has essentially no input current so it doesn't matter how low the value is.  You aren't saving energy by using a high value resistor because there is none dissipated because there is no current flow.  You might as well use a reasonable value to limit noise because you really aren't wasting any energy.

Of course in the example schematic, if you used a low value, such as a 100R you might get some smoke when you close the switch, depending on the PSU.


Why?  A 100 Ohm resistor on a 5v circuit will only flow 50 mA.  It would require at least a 1/4 Watt resistor.
 

Offline HextejasTopic starter

  • Frequent Contributor
  • **
  • Posts: 315
  • Country: us
Re: Trying to understand a pull up resistor.
« Reply #13 on: January 23, 2018, 07:42:44 pm »
Another way to think about it is that the switch puts 0V on the pin end of the resistor.  Therefore, all of Vcc is dropped across the resistor and the pin voltage is exactly the switch voltage - 0V.

In some logic families, the switch will not only sink the resistor current, there will be some pin current flowing out of the pin.  Look at section 6.5 and the parameter IIL which stands for input current with the input low.  Note that the current is -1.6 mA.  The minus sign means the current is flowing out of the pin when the pin voltage is low.  So, our switch needs to sink the resistor current and another 1.6 mA from the pin.

Note that II of 1 mA means the resistor must provide 1 mA while holding the pin voltage above 2V according to table 6.3 parameter VIH.

From Ohm's law, the resistor should be less than 3000 Ohms:  (5V - 2V) / 1 mA = 3000 Ohms.  But that is too close to the threshold - I usually use 2.2k or even 1k.  There is an advantage to having more current flowing through the switch in that it helps clean the contacts or burn through any oxidation.

I chose the 7400 but there are similar specs for all integrated circuits.

http://www.ti.com/lit/ds/symlink/sn74ls00.pdf

I did not use the 74LS00 or 74S00 data.
Thank you rstofer, you have been most helpful.
Having read this post, and looking at the datasheet, it looks like that if I use the same gate as the SN7400, I can use the same resistor.
Also from the datasheet (which i mostly (98%) dont understand), I counted the nand gates pins as thus. Quad, (4x3) 2 input pins, 1 output = 12. Plus VCC and Gnd = 14.
That makes sense but the drawings show something different. A SN5400-W, 14 pin CFP shows 8 pins,  and an 18 pin SO shows 14.
Wassup with that ?
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: Trying to understand a pull up resistor.
« Reply #14 on: January 23, 2018, 07:45:55 pm »
That's clearly a typo, or the wrong graphic is shown. Don't get too caught up in that, errors in datasheets are not particularly uncommon.
 

Offline paulca

  • Super Contributor
  • ***
  • Posts: 4285
  • Country: gb
Re: Trying to understand a pull up resistor.
« Reply #15 on: January 24, 2018, 07:49:41 am »
Why?  A 100 Ohm resistor on a 5v circuit will only flow 50 mA.  It would require at least a 1/4 Watt resistor.

Sorry I was thinking 10R and wrote 100R
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 

Offline Brumby

  • Supporter
  • ****
  • Posts: 12389
  • Country: au
Re: Trying to understand a pull up resistor.
« Reply #16 on: January 24, 2018, 08:52:47 am »
And where does "pull up" come from ? Is it that we are pulling the pin up above a zero state
I would call that an accurate statement.

It also goes the other way:
The words pull-up, means to pull the input voltage up, towards the positive supply voltage and pull-down, means to pull the input towards the negative supply voltage.

... and this thought leads into the fundamental reason why we even have to worry about such things...
Quote
and possibly keeping it there ?
In the absence of any other desired input signal - Yes.

While the high impedance of these inputs allows for a greater capabilities, they are - by definition - susceptible to even the weakest of signals that can find its way into the circuit ... unless measures are taken.

Connecting them to the output of another device which has a low impedance is one - and another is the addition of a "pull up" or "pull down" resistor.  Whether you want to "pull up" or "pull down" will depend on what you want the input to be in the absence of the desired signal.

As for choosing a value for such a resistor - the reason why people are so casual about it is that the actual value is rarely important ... it just needs to be small enough to do the job and big enough to not adversely affect the desired signal, with a leaning to going higher in value to reduce power wasting.


Do a couple of projects and you will get used to it.
 

Offline paulca

  • Super Contributor
  • ***
  • Posts: 4285
  • Country: gb
Re: Trying to understand a pull up resistor.
« Reply #17 on: January 24, 2018, 09:28:37 am »
A question might be... if high impedance inputs are so sensitive to floating voltages, why don't ICs just include a pull up/down within?

The only thing I can think is that not having it within the chip allows you choose if it's a pull up or pull down.
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 20004
  • Country: gb
  • 0999
Re: Trying to understand a pull up resistor.
« Reply #18 on: January 24, 2018, 09:40:38 am »
Why?  A 100 Ohm resistor on a 5v circuit will only flow 50 mA.  It would require at least a 1/4 Watt resistor.

Sorry I was thinking 10R and wrote 100R
10R? No problem, use a 2.5W resistor.  :box:

Seriously, this highlights the point I made previously: power dissipation, limits the lower value.

A question might be... if high impedance inputs are so sensitive to floating voltages, why don't ICs just include a pull up/down within?

The only thing I can think is that not having it within the chip allows you choose if it's a pull up or pull down.
Lots of microcontrollers have pull-up resistors/current sources built-in, but they have to be enabled.

One of the reasons for not including pull-up/down resistors by default is it increases the power dissipation, another is the IC designer doesn't know whether the user wants pull-up or pull-down resistors.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9940
  • Country: us
Re: Trying to understand a pull up resistor.
« Reply #19 on: January 24, 2018, 03:57:36 pm »
A question might be... if high impedance inputs are so sensitive to floating voltages, why don't ICs just include a pull up/down within?

The only thing I can think is that not having it within the chip allows you choose if it's a pull up or pull down.

They will often have weak pull-up or pull-down resistors and, in some cases, the user can select which to connect through some register setting.  Those resistors are enough to establish a logic level but they often won't flow enough current to make switching reliable when using a mechanical device.

It's not about the logic level, that's easy.  Getting a mechanical switch to work is the real concern.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf