Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

88%
+13 −0
Q&A How to calculate pullup resistor value for pushbutton?

To understand this issue, we have to look at how your circuit works and what the pullup does within it. You have a pushbutton you want to read with a microcontroller. The pushbutton is a momentary...

posted 4y ago by Olin Lathrop‭  ·  edited 4y ago by Olin Lathrop‭

Answer
#2: Post edited by user avatar Olin Lathrop‭ · 2020-06-21T12:40:38Z (almost 4 years ago)
  • <P>To understand this issue, we have to look at how your circuit works and
  • what the pullup does within it.
  • <p>You have a pushbutton you want to read with a microcontroller. The
  • pushbutton is a momentary SPST (Single Pole Single Throw) switch. It has
  • two connection points which are either connected or not. When the button
  • is pressed, the two points are connected (switch is closed). When
  • released, they are not connected (switch is open). Microcontrollers don't
  • inherently detect connection or disconnection. What they do sense is a
  • voltage. Since this switch has only two states it makes sense to use a
  • digital input, which is after all designed to be in only one of two
  • states. The micro can sense which state a digital input is in directly.
  • <P>A pullup converts the open/closed connection of the switch to a low or
  • high voltage the microcontroller can sense. When the switch is pressed,
  • the line is forced low because the switch essentially shorts it to ground.
  • However, when the switch is released, nothing is driving the line to any
  • particular voltage. It could just stay low, pick up other nearby signals
  • by capacitive coupling, or eventually float to a specific voltage due to
  • the tiny bit of leakage current thru the digital input. The job of the
  • pullup resistor is to provide a positive guaranteed high level when the
  • switch is open, but still allow the switch to safely short the line to
  • ground when closed.
  • <P>There are two main competing requirements on the size of the pullup
  • resistor. It has to be low enough to solidly pull the line high, but high
  • enough to not cause too much current to flow when the switch is closed.
  • Both those are obviosly subjective and their relative importance depends
  • on the situation. In general, you make the pullup just low enough to make
  • sure the line is high when the switch is open, given all the things that
  • might make the line low otherwise.
  • <P>Let's look at what it takes to pull up the line. Looking only at the
  • DC requirement uncovers the leakage current of the digital input line. The
  • ideal digital input has infinite impedance. Real ones don't, of course,
  • and the extent CMOS inputs are not ideal is usually expressed as a maximum
  • leakage current that can either come out of or go into the pin. Let's say
  • your micro is specified for 1 &micro;A maximum leakage on its digital
  • input pins. Since the pullup has to keep the line high, the worst case is
  • assuming the pin looks like a 1 &micro;A current sink to ground. If you
  • were to use a 1 M&Omega; pullup, for example, then that 1 &micro;A would
  • cause 1 Volt accross the 1 M&Omega; resistor. Let's say this is a 5V
  • system, so that means the pin is only guaranteed to be up to 4V. Now you
  • have to look at the digital input spec and see what the minimum voltage
  • requirement is for a logic high level. That can be 80% of Vdd for some
  • micros, which would be 4V in this case. Therefore a 1 M&Omega; pullup is
  • right at the margin. You need at least a little less than that for
  • guaranteed correct behaviour due to DC considerations.
  • <P>However, there are other considerations, and these are harder to
  • quantify. Every node has some capacitive coupling to all other nodes,
  • although the magnitude of that coupling falls off with distance such that
  • only nearby nodes are relevant. If these other nodes have signals on
  • them, these signals could couple onto your digital input. A lower value
  • pullup makes the line lower impedance, which reduces the amount of stray
  • signal it will pick up. It also gives you a higher minimum guaranteed DC
  • level against the leakage current, so there is more room between that DC
  • level and where the digital input might interpret the result as a logic
  • low instead of the intended logic high. So how much is enough? Clearly
  • the 1 M&Omega; pullup in this example is not enough (too high a
  • resistance). It's nearly impossible to guess coupling to nearby signals,
  • but I'd want at least an order of magnitude margin over the minimum DC
  • case. That means I want a 100 k&Omega; pullup or lower, although
  • if there is much noise around I'd want it to be lower.
  • <P>There is another consideration driving the pullup lower, and that is
  • rise time. The line will have some stray capacitance to ground, so will
  • exponentially decay towards the supply value instead of instantly going
  • there. Let's say all the stray capacitance adds up to 20 pF. That times
  • the 100 k&Omega; pullup is 2 &micro;s. It takes 3 time constants to get
  • to 95% of the settling value, or 6 &micro;s in this case. That is of no
  • consequence in human time so doesn't matter in this example, but if this
  • were a digital bus line you wanted to run at 400 kHz data rate, it wouldn't
  • work.
  • <P>Now lets look at the other competing consideration, which is the
  • current wasted when the switch is pressed. If this unit is running off of
  • line power or otherwise handling substantial power, a few mA won't matter.
  • At 5V it takes 5 k&Omega; to draw 1 mA. That's actually "a lot" of
  • current in some cases, and well more than required due to the other
  • considerations. If this is a battery powered device and the switch could
  • be on for a substantial fraction of the time, then every &micro;A may
  • matter and you have to think about this very carefully. In some cases you
  • might sample the switch periodically and only turn on the pullup for a
  • short time around the sample to minimize current draw.
  • <p>Some switches also work better or have longer life when there is some
  • minimum current when on. For small pushbuttons, this is usually below 1 mA.
  • <P>Other than special considerations like battery operation, 100 k&Omega;
  • is high enough impedance to make me nervous about picking up noise. 1 mA
  • of current wasted when the switch is on seems unnecessarily large. So 500
  • &micro;A, which means 10 k&Omega; impedance is about right for "ordinary"
  • cases.
  • <P>To understand this issue, we have to look at how your circuit works and
  • what the pullup does within it.
  • <p>You have a pushbutton you want to read with a microcontroller. The
  • pushbutton is a momentary SPST (Single Pole Single Throw) switch. It has
  • two connection points which are either connected or not. When the button
  • is pressed, the two points are connected (switch is closed). When
  • released, they are not connected (switch is open). Microcontrollers don't
  • inherently detect connection or disconnection. What they do sense is a
  • voltage. Since this switch has only two states it makes sense to use a
  • digital input, which is after all designed to be in only one of two
  • states. The micro can sense which state a digital input is in directly.
  • <P>A pullup converts the open/closed connection of the switch to a low or
  • high voltage the microcontroller can sense. Without a pullup, when the switch is pressed,
  • the line is forced low because the switch essentially shorts it to ground.
  • However, when the switch is released, nothing is driving the line to any
  • particular voltage. It could just stay low, pick up other nearby signals
  • by capacitive coupling, or eventually float to a specific voltage due to
  • the tiny bit of leakage current thru the digital input. The job of the
  • pullup resistor is to provide a positive guaranteed high level when the
  • switch is open, but still allow the switch to safely short the line to
  • ground when closed.
  • <P>There are two main competing requirements on the size of the pullup
  • resistor. It has to be low enough to solidly pull the line high, but high
  • enough to not cause too much current to flow when the switch is closed.
  • Both those are obviosly subjective and their relative importance depends
  • on the situation. In general, you make the pullup just low enough to make
  • sure the line is high when the switch is open, given all the things that
  • might make the line low otherwise.
  • <P>Let's look at what it takes to pull up the line. Looking only at the
  • DC requirement uncovers the leakage current of the digital input line. The
  • ideal digital input has infinite impedance. Real ones don't, of course,
  • and the extent CMOS inputs are not ideal is usually expressed as a maximum
  • leakage current that can either come out of or go into the pin. Let's say
  • your micro is specified for 1 &micro;A maximum leakage on its digital
  • input pins. Since the pullup has to keep the line high, the worst case is
  • assuming the pin looks like a 1 &micro;A current sink to ground. If you
  • were to use a 1 M&Omega; pullup, for example, then that 1 &micro;A would
  • cause 1 Volt accross the 1 M&Omega; resistor. Let's say this is a 5V
  • system, so that means the pin is only guaranteed to be up to 4V. Now you
  • have to look at the digital input spec and see what the minimum voltage
  • requirement is for a logic high level. That can be 80% of Vdd for some
  • micros, which would be 4V in this case. Therefore a 1 M&Omega; pullup is
  • right at the margin. You need at least a little less than that for
  • guaranteed correct behaviour due to DC considerations.
  • <P>However, there are other considerations, and these are harder to
  • quantify. Every node has some capacitive coupling to all other nodes,
  • although the magnitude of that coupling falls off with distance such that
  • only nearby nodes are relevant. If these other nodes have signals on
  • them, these signals could couple onto your digital input. A lower value
  • pullup makes the line lower impedance, which reduces the amount of stray
  • signal it will pick up. It also gives you a higher minimum guaranteed DC
  • level against the leakage current, so there is more room between that DC
  • level and where the digital input might interpret the result as a logic
  • low instead of the intended logic high. So how much is enough? Clearly
  • the 1 M&Omega; pullup in this example is not enough (too high a
  • resistance). It's nearly impossible to guess coupling to nearby signals,
  • but I'd want at least an order of magnitude margin over the minimum DC
  • case. That means I want a 100 k&Omega; pullup or lower, although
  • if there is much noise around I'd want it to be lower.
  • <P>There is another consideration driving the pullup lower, and that is
  • rise time. The line will have some stray capacitance to ground, so will
  • exponentially decay towards the supply value instead of instantly going
  • there. Let's say all the stray capacitance adds up to 20 pF. That times
  • the 100 k&Omega; pullup is 2 &micro;s. It takes 3 time constants to get
  • to 95% of the settling value, or 6 &micro;s in this case. That is of no
  • consequence in human time so doesn't matter in this example, but if this
  • were a digital bus line you wanted to run at 400 kHz data rate, it wouldn't
  • work.
  • <P>Now lets look at the other competing consideration, which is the
  • current wasted when the switch is pressed. If this unit is running off of
  • line power or otherwise handling substantial power, a few mA won't matter.
  • At 5V it takes 5 k&Omega; to draw 1 mA. That's actually "a lot" of
  • current in some cases, and well more than required due to the other
  • considerations. If this is a battery powered device and the switch could
  • be on for a substantial fraction of the time, then every &micro;A may
  • matter and you have to think about this very carefully. In some cases you
  • might sample the switch periodically and only turn on the pullup for a
  • short time around the sample to minimize current draw.
  • <p>Some switches also work better or have longer life when there is some
  • minimum current when on. For small pushbuttons, this is usually below 1 mA.
  • <P>Other than special considerations like battery operation, 100 k&Omega;
  • is high enough impedance to make me nervous about picking up noise. 1 mA
  • of current wasted when the switch is on seems unnecessarily large. So 500
  • &micro;A, which means 10 k&Omega; impedance is about right for "ordinary"
  • cases.
#1: Initial revision by user avatar Olin Lathrop‭ · 2020-06-15T20:01:28Z (almost 4 years ago)
<P>To understand this issue, we have to look at how your circuit works and
what the pullup does within it.

<p>You have a pushbutton you want to read with a microcontroller.  The
pushbutton is a momentary SPST (Single Pole Single Throw) switch.  It has
two connection points which are either connected or not.  When the button
is pressed, the two points are connected (switch is closed).  When
released, they are not connected (switch is open).  Microcontrollers don't
inherently detect connection or disconnection.  What they do sense is a
voltage.  Since this switch has only two states it makes sense to use a
digital input, which is after all designed to be in only one of two
states.  The micro can sense which state a digital input is in directly.

<P>A pullup converts the open/closed connection of the switch to a low or
high voltage the microcontroller can sense.  When the switch is pressed,
the line is forced low because the switch essentially shorts it to ground.
However, when the switch is released, nothing is driving the line to any
particular voltage.  It could just stay low, pick up other nearby signals
by capacitive coupling, or eventually float to a specific voltage due to
the tiny bit of leakage current thru the digital input.  The job of the
pullup resistor is to provide a positive guaranteed high level when the
switch is open, but still allow the switch to safely short the line to
ground when closed.

<P>There are two main competing requirements on the size of the pullup
resistor.  It has to be low enough to solidly pull the line high, but high
enough to not cause too much current to flow when the switch is closed.
Both those are obviosly subjective and their relative importance depends
on the situation.  In general, you make the pullup just low enough to make
sure the line is high when the switch is open, given all the things that
might make the line low otherwise.

<P>Let's look at what it takes to pull up the line.  Looking only at the
DC requirement uncovers the leakage current of the digital input line. The
ideal digital input has infinite impedance.  Real ones don't, of course,
and the extent CMOS inputs are not ideal is usually expressed as a maximum
leakage current that can either come out of or go into the pin. Let's say
your micro is specified for 1 &micro;A maximum leakage on its digital
input pins.  Since the pullup has to keep the line high, the worst case is
assuming the pin looks like a 1 &micro;A current sink to ground. If you
were to use a 1 M&Omega; pullup, for example, then that 1 &micro;A would
cause 1 Volt accross the 1 M&Omega; resistor.  Let's say this is a 5V
system, so that means the pin is only guaranteed to be up to 4V.  Now you
have to look at the digital input spec and see what the minimum voltage
requirement is for a logic high level.  That can be 80% of Vdd for some
micros, which would be 4V in this case.  Therefore a 1 M&Omega; pullup is
right at the margin.  You need at least a little less than that for
guaranteed correct behaviour due to DC considerations.

<P>However, there are other considerations, and these are harder to
quantify.  Every node has some capacitive coupling to all other nodes,
although the magnitude of that coupling falls off with distance such that
only nearby nodes are relevant.  If these other nodes have signals on
them, these signals could couple onto your digital input.  A lower value
pullup makes the line lower impedance, which reduces the amount of stray
signal it will pick up.  It also gives you a higher minimum guaranteed DC
level against the leakage current, so there is more room between that DC
level and where the digital input might interpret the result as a logic
low instead of the intended logic high.  So how much is enough?  Clearly
the 1 M&Omega; pullup in this example is not enough (too high a
resistance).  It's nearly impossible to guess coupling to nearby signals,
but I'd want at least an order of magnitude margin over the minimum DC
case.  That means I want a 100 k&Omega; pullup or lower, although
if there is much noise around I'd want it to be lower.

<P>There is another consideration driving the pullup lower, and that is
rise time.  The line will have some stray capacitance to ground, so will
exponentially decay towards the supply value instead of instantly going
there.  Let's say all the stray capacitance adds up to 20 pF.  That times
the 100 k&Omega; pullup is 2 &micro;s.  It takes 3 time constants to get
to 95% of the settling value, or 6 &micro;s in this case.  That is of no
consequence in human time so doesn't matter in this example, but if this
were a digital bus line you wanted to run at 400 kHz data rate, it wouldn't
work.

<P>Now lets look at the other competing consideration, which is the
current wasted when the switch is pressed.  If this unit is running off of
line power or otherwise handling substantial power, a few mA won't matter.
At 5V it takes 5 k&Omega; to draw 1 mA.  That's actually "a lot" of
current in some cases, and well more than required due to the other
considerations.  If this is a battery powered device and the switch could
be on for a substantial fraction of the time, then every &micro;A may
matter and you have to think about this very carefully.  In some cases you
might sample the switch periodically and only turn on the pullup for a
short time around the sample to minimize current draw.

<p>Some switches also work better or have longer life when there is some
minimum current when on.  For small pushbuttons, this is usually below 1 mA.

<P>Other than special considerations like battery operation, 100 k&Omega;
is high enough impedance to make me nervous about picking up noise.  1 mA
of current wasted when the switch is on seems unnecessarily large.  So 500
&micro;A, which means 10 k&Omega; impedance is about right for "ordinary"
cases.