Trying to understand a pull up resistor. - Page 1
Forum section: electronics / beginners

author: Hextejas
author_rank: Frequent Contributor
timestamp: January 22, 2018, 10:44:32 pm
content: 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?

author: IanB
author_rank: Super Contributor
timestamp: January 22, 2018, 10:53:47 pm
content: 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.)

author: filssavi
author_rank: Frequent Contributor
timestamp: January 22, 2018, 10:54:43 pm
content: 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

author: rstofer
author_rank: Super Contributor
timestamp: January 22, 2018, 11:29:47 pm
content: 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 IILwhich 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 IIof 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.pdfI did not use the 74LS00 or 74S00 data.

author: Brumby
author_rank: Unknown
timestamp: January 23, 2018, 12:46:16 am
content: Quote from: Hextejas on January 22, 2018, 10:44:32 pmQuite correct.QuoteBefore 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 thevoltageon 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:Quote from: IanB on January 22, 2018, 10:53:47 pm

author: hugo
author_rank: Regular Contributor
timestamp: January 23, 2018, 12:57:29 am
content: Let's say R1=5k and Vcc=5V. Switch open, MCU input pin sees 5V (high), I(R1)~ uA. 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).

author: Dubbie
author_rank: Unknown
timestamp: January 23, 2018, 01:12:10 am
content: 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.

author: Zero999
author_rank: Super Contributor
timestamp: January 23, 2018, 11:53:12 am
content: 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 Z1and 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= 5VWhen Z1is 5k and the switch is open, Z2will be near 1G and the voltage across it near 5V.When the switch is closed, Z2will fall to 10m and the voltage across it near zero.https://en.wikipedia.org/wiki/Voltage_divider

author: Hextejas
author_rank: Frequent Contributor
timestamp: January 23, 2018, 03:54:23 pm
content: 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

author: Zero999
author_rank: Super Contributor
timestamp: January 23, 2018, 04:10:44 pm
content: Quote from: Hextejas on January 23, 2018, 03:54:23 pmMost 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 hisprevious 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.

author: rstofer
author_rank: Super Contributor
timestamp: January 23, 2018, 04:38:55 pm
content: Quote from: Hextejas on January 23, 2018, 03:54:23 pmExactly. 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.QuoteMuch 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.QuoteExactly! 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.

author: paulca
author_rank: Super Contributor
timestamp: January 23, 2018, 04:51:48 pm
content: Quote from: rstofer on January 23, 2018, 04:38:55 pmOf 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.

author: rstofer
author_rank: Super Contributor
timestamp: January 23, 2018, 05:10:52 pm
content: Quote from: paulca on January 23, 2018, 04:51:48 pmWhy? A 100 Ohm resistor on a 5v circuit will only flow 50 mA. It would require at least a 1/4 Watt resistor.

author: Hextejas
author_rank: Frequent Contributor
timestamp: January 23, 2018, 07:42:44 pm
content: Quote from: rstofer on January 22, 2018, 11:29:47 pmThank 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 ?

author: james_s
author_rank: Super Contributor
timestamp: January 23, 2018, 07:45:55 pm
content: 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.

author: paulca
author_rank: Super Contributor
timestamp: January 24, 2018, 07:49:41 am
content: Quote from: rstofer on January 23, 2018, 05:10:52 pmSorry I was thinking 10R and wrote 100R

author: Brumby
author_rank: Unknown
timestamp: January 24, 2018, 08:52:47 am
content: Quote from: Hextejas on January 23, 2018, 03:54:23 pmI would call that an accurate statement.It also goes the other way:Quote from: Hero999 on January 23, 2018, 04:10:44 pm... and this thought leads into the fundamental reason why we even have to worry about such things...QuoteIn the absence of any otherdesiredinput 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.

author: paulca
author_rank: Super Contributor
timestamp: January 24, 2018, 09:28:37 am
content: 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.

author: Zero999
author_rank: Super Contributor
timestamp: January 24, 2018, 09:40:38 am
content: Quote from: paulca on January 24, 2018, 07:49:41 am10R? No problem, use a 2.5W resistor.Seriously, this highlights the point I made previously: power dissipation, limits the lower value.Quote from: paulca on January 24, 2018, 09:28:37 amLots 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.

author: rstofer
author_rank: Super Contributor
timestamp: January 24, 2018, 03:57:36 pm
content: Quote from: paulca on January 24, 2018, 09:28:37 amThey 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.