Shop OBEX P1 Docs P2 Docs Learn Events
Propeller Push Button Confusion — Parallax Forums

Propeller Push Button Confusion

artlogicartlogic Posts: 4
edited 2007-10-25 07:54 in Propeller 1
First off, I'd like to say that I am very new at electronics and only have a basic understanding of anything beyond simple digital logic, so please be kind.

I have seen two diagrams on how to attach a pushbutton to the propeller and I want to make sure I'm doing it correctly:

   3.3V
    |
  -|
    |
P1--*
    |
    <
    > 10k
    <
    |
   GND




or

   GND
    |
  -|
    |
P1--*
    |
    <
    > 10k
    <
    |
   3.3V




Are both these circuits equally viable? Is the only difference what the switch delivers to the prop when pressed? (Diag 1: logic 1 when pressed, Diag 2: logic 0 when pressed) Also, should I be worried that in the first diagram the propeller pin is connected directly to 3.3v? Thanks for the help.

Comments

  • hippyhippy Posts: 1,981
    edited 2007-10-23 19:32
    Both should work although ideally you should have a resistor between the button/10K join and the Propeller pin to prevent damage when the pin is an output and the button is pressed, otherwise you are shorting that output directly to 0V 0r 3.3V
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-23 19:34
    Both diagrams will work.
    You are correct about what logic level the Prop pin will see when the switch is closed.
    You are also correct in being concerned about the connection to 3.3V in the first diagram.

    It turns out that the same problem can occur with the second diagram and the Propeller pin
    being connected to ground. The issue is that the pin can be set to output mode through a
    programming error and, if the logic level output on the pin is opposite from that provided
    through the closed switch, you can get a short circuit, theoretically damaging the I/O pin.
    In practice, the Propeller is robust enough to survive this without damage. It's still a good
    idea to use a small value series resistor (like 220 ohms) between the Propeller pin and any
    point that might be connected directly to +3.3V or ground. There are some cases where
    this additional resistance might cause problems, usually where there's already a resistor in
    the circuit, typically for timing purposes. Don't sweat it now. You'll either have learned
    when it's important or someone will mention it in the documentation.
  • artlogicartlogic Posts: 4
    edited 2007-10-23 20:37
    Thank you for your quick and detailed replies - they help quite a bit. If I understand correctly, if I want to use the first diagram, something like this would be reasonable:

       3.3V
        |
        <
        > 220
        <
        |
      -|
        |
    P1--*
        |
        <
        > 10k
        <
        |
       GND
    
    



    Also, I am a little low on 10k resistors, could I replace this with a 2k? Could you recommend a resource for determining proper resistance values in these types of cases? Thanks!
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-23 20:42
    That diagram will work, but it's not what I meant. The 220 ohm resistor is supposed to go between the Propeller pin and the junction of the 10K resistor and the pushbutton.
  • deSilvadeSilva Posts: 2,967
    edited 2007-10-23 21:33
    @artlogic: Computing Voltages and Currents is something you should learn by all means as soon as possible, even if you are less interested in electronics.
    The simply and extremely obvious rules that apply are called Kirchhof's laws (although some Americans spell Gustav's name differently smile.gif )

    For resistors you have only one additional simple relationship between current and voltage (Ohm's law), and so it's all extremly easy.

    (a) Consider your circuit: 220 Ohms and 10 k Ohms... What is the voltage the Prop sees at its input pin? Difficult? Not at all! But let's try it this way: That WOULD be the voltage, if both resisters had the same value (10 k OR 220 Ohms?) Well it must be 1/2*3V3 for symmetry reasons. The general formula
    V = R2/(R1+R2) should not surprise you (where R1 is the upper, R2 is the lower value) and how to derive it is just simplest mathematics, no electricity involved in it at all!

    (b) When you put your 220 Ohm resistor in the place you did, this was excellent thinking! It was meant to reduce the current if the propeller pin were erroniously programmed as output.

    Mike was not so satisfied, as this had consequences to the voltage the Propeller pin sees when you press the button: It will no longer be 3V3 but the reduced value we computed above. But when you keep the relation of the resistor values at - say - 1:10, it will work flawlessly.

    Mike's suggestion is the "standard way" to do it,
    The reasoning behind this "standard circuit" is that:
    (1) in the case of input this 220 Ohms resistor will have no noticable effect, as the impedance of an input is >10MOhms.
    (2) in the case of output (be it low or high) this 220 Ohms resistor will just reduce the maximum current to I = U/R = 3V3/220 Ohms = 15 mA which is at the low side.

    I personally would not use this series resistor in a non-commercial circuit, just take the "pullup" variant. Then trouble will only if when the pin is not only programmed to output, but also set to high, and the key is pressed, and the internal current limiting does not work correctly...

    Post Edited (deSilva) : 10/23/2007 9:38:52 PM GMT
  • hippyhippy Posts: 1,981
    edited 2007-10-24 00:26
    What you're after is something like this ...

                             -.- 3V3                          -.- 3V3
                              |                                |
                              |                               .|.
                              O |-.                           | | 10K
                              O |-'                           |_|
                              |                                |
                     ____     |                       ____     |
            P1 <----|____|----{              P1 <----|____|----{
                              |                                |
                      1K     .|.                       1K      |
                             | | 10K                           O |-.
                             |_|                               O |-'
                              |                                |
                             _|_ 0V                           _|_ 0V
    
    
    
  • deSilvadeSilva Posts: 2,967
    edited 2007-10-24 14:10
    A good practical extension to deSilvas theory loaden posting, hippy smile.gif
    @artlogic: And if there is just no 10k in your box, take ANYTHING from 4k7 to 470k..

    There is a minor concern not to reduce the current too much (i.e. going to MOhms): The contacts of the switch could become corroded when there is not a reasonable amount of current flowing through them from time to time. This is an effect you most likely know from batteries in devices unused for a very long time
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2007-10-25 07:54
    Ok, my2cents smile.gif

    First off I avoid running a supply rail off the board, especially the one the cpu is running from. Anything can happen, you could short it to ground, or you could just pickup noise, whatever, so I just avoid it and use common ground type inputs.

    Second, DeSilva, you mentioned not reducing the current through the switch by too much on the basis of corrosion. Well, that's not exactly correct but the idea is to pass enough current through the switch to "wet" the contacts. What happens is that the contacts are not normally sealed from the environment and over time a film can build up on the contact surface leading to a high resistance condition, that is, instead of 0.1ohm contact resistance (for instance) you could end up with 100ohms or more. The solution to this is simple, if you pass enough current through the switch it "cleans" the contacts during make & break.

    BTW, I think batteries cause corrosion because of chemical leakage buildup in the battery compartment due to inadequate ventilation.

    Hippy's second circuit is the favored one, even with a 10K pullup (hey, what's a few hundred ohms of contact resistance compared to 10K?). For switch inputs the series resistor to the port pin could easily be 100K or more but 1K is fine as is the 220 that Mike mentioned. The reality of stuffing the port pin due to it being an output is possible though unlikely due to the self-limiting nature of the CMOS output stage and limitations of supply current etc (go on, you'll have a hard time trying to stuff it). So the series resistor is a good thing mainly for ESD as it limits the ESD current due to it's resistance in combination with IC's input capacitance and diode clamping.

    If the switch is not in close proximity to the pcb then I would decrease the pullup to 1K and perhaps even allow for a small 0.1uF cap from switch to ground. This helps with contact bounce, provides that "spark" of wetting current, and helps with ESD.

    *Peter*
Sign In or Register to comment.