'What is a microcontroller" 'Pushbutton Resistor Question (Page 76)
Chicago Mike
Posts: 88
The example on page 76 of What is a microcontroller, and other examples in this chapter use 2 resistors to perform pulldown or pullup operations on a button. I understand why you would have to use resistors to do this in a pull-down style swtich, however i really would like an explanation as to why you would need to do this with a pull-up style switch?
So long as the pin is set as an input, why are the resistors being used? On top of this, why are these specific values being used in this case? a 220/Ohm and a 10K.·I've seen other examples in other text that have not used any resistors in this·application. (Just a switch to the pin on the 5volt rail).·I'm especially interested in why these values. Could they really be any value in this application so long as the Vss side of the switch is higher than the Vdd side?
I would love to know why? Thanks in advance.
·
So long as the pin is set as an input, why are the resistors being used? On top of this, why are these specific values being used in this case? a 220/Ohm and a 10K.·I've seen other examples in other text that have not used any resistors in this·application. (Just a switch to the pin on the 5volt rail).·I'm especially interested in why these values. Could they really be any value in this application so long as the Vss side of the switch is higher than the Vdd side?
I would love to know why? Thanks in advance.
·
Comments
·· In the examples the resistors serve very specific purposes.· First of all, the 10K resistor is used for pull-up/down.· The reason you need this is that without them, when the pin is not connected to Vdd or Vss it is floating, and thus is subject to drifting HIGH/LOW without the button being pressed at all.· Simply waving your hand near it could cause a change.
·· The 10K pull-up is used on an Active-Low Switch.· This is where the pin normally reads HIGH, but pressing the button makes it LOW.· The 10K pull-down is used on Active-High switch.· Here the pin normally reads LOW, but reads HIGH when the button is pressed.
·· As for the 220 Ohm resistor.· While not absolutely required (As the 10K is), it's there for safety.· What if you accidentally made the pin an output low, then pressed your active-high push-button?· This 220 Ohm resistor helps save the I/O pin from damage during such a mistake, and is well worth the $0.05 to be safe.· Beats a new Stamp Module.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Thanks again! I could believe I got a response last night two minutes after I wrote a message!
Mike.
10K is a good medium range for pull-up/pull-downs.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
Electronic Systems Technologies
Southern Illinois University Carbondale
Personal Links - ·Lot of BASIC Stamp info
and
SelmaWare Solutions
StampPlot Pro Version 3 Release 4
Graphical Data Acquisition for your Micro and Imagination!
Now allows additional controls to be added, or developed.
·
So, you want SOME resistor tying it high or low. OK, so why 10Kohms? Well, you don't want too much current to be used for this purpose, but you want enough current to give you a 'hard' high or low. A 10 Meg-ohm resistor would provide -- let's see --
V = IR, so I = V/R. 5/10e6 == 500 uA. Very small, could be affected by RF noise.
10 Kohms: 5/10e3 == 0.5 mA. Reasonable amount, will swamp any micro-amp noise signal. I've used 22 Kohm resistors in the past for pull-up/pull-down purposes. 10K is just a nice round number that gives good results.
Now, 220 ohms (5/220 == 22 mA) is enough to drive an LED. But its close to the max current a BS2 pin can source or sink. Plus, you have other uses for that current besides just getting a 'hard' one or zero, and heating up the resistor.
·· Martin and Allan have answered these questions for you.· I hope that helps you see why these values are typically used.· While the 220 Ohm resistors are something I first saw used here at Parallax, 10K is common all over the world for pull-up/pull-down resistors, depending on the bus type.· Some busses, such as I2C use 4.7K, as do some keyboard/keypad decoder chips.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
I'm so glad these forums are here. They are great!