Shop OBEX P1 Docs P2 Docs Learn Events
'What is a microcontroller" 'Pushbutton Resistor Question (Page 76) — Parallax Forums

'What is a microcontroller" 'Pushbutton Resistor Question (Page 76)

Chicago MikeChicago Mike Posts: 88
edited 2005-09-06 23:28 in Learn with BlocklyProp
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.

·

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-06 00:27
    Mike,

    ·· 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
  • Chicago MikeChicago Mike Posts: 88
    edited 2005-09-06 13:43
    That makes sense. I guess the question I have is, where did these specific values come from? Perhaps I'm looking to deep into this, but why specificly 10K. The 220, as that its offering protection in this case, could probably be anything (within reason... You would want it rather low), but 10K, what formula did this calulate off of?



    Thanks again! I could believe I got a response last night two minutes after I wrote a message!

    Mike.
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2005-09-06 14:42
    With the 10K, what you are looking for is a value, that if you have multiple switches in parallel, will not draw excessive current (10 10K's would be 1K).· But, you don't want the value so high that input device doesn't get sufficient current to sense the state.· 5V/10K = 0.5mA, more than enough for IIL and IIH (current input·low and high).

    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.
    ·
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-09-06 14:48
    An 'open' input is also known as an "antenna" -- as such, it will pick up the 60 HZ 'hum' coming off of light fixtures quite easily.

    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.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-06 15:28
    Mike,

    ·· 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
  • Chicago MikeChicago Mike Posts: 88
    edited 2005-09-06 23:28
    I get it! Thank you all for your help.

    I'm so glad these forums are here. They are great!
Sign In or Register to comment.