Shop OBEX P1 Docs P2 Docs Learn Events
Pushbutton reading software - Use pushbuttons without pullup resistors!! — Parallax Forums

Pushbutton reading software - Use pushbuttons without pullup resistors!!

MicrocontrolledMicrocontrolled Posts: 2,461
edited 2010-03-12 03:10 in Propeller 1
I have now made my second contribution to the OBEX. This is neither a big nor impressive object, but it is a useful object. I find that while experimenting I run out of pull-up resistors for pushbuttons. This becomes a big deal, as the pushbuttons often return false signals. Here I have developed an object that turns the pin to output, outputs and positive charge and then immediately switches back to input and reads the "ina" register. It works great! Just like you have a pull-up, but you don't! I also have 3 additional PUB's (all use the same method) that take a timeout, wait for a button press, and one that reads a specified group of inputs. If you just need the simple button reading, you can remove all of the PUB's except it and the object only consumes 10 longs.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't click on this.....

Use the Propeller icon!! Propeller.gif

Comments

  • SapiehaSapieha Posts: 2,964
    edited 2010-03-10 19:14
    Hi microcontrolled

    VERY riski bisnes.

    Regards

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nothing is impossible, there are only different degrees of difficulty.
    For every stupid question there is at least one intelligent answer.
    Don't guess - ask instead.
    If you don't ask you won't know.
    If your gonna construct something, make it·as simple as·possible yet as versatile as posible.


    Sapieha
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-03-10 19:16
    Micro,

    If the button is pressed, and it's connected directly to the pin, won't your high output be shorted to ground? This could eventually cause the Prop's output driver to fail.

    -Phil
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2010-03-10 19:29
    I never considered that. It is really only connected for a small portion of time as:
    dira[noparse][[/noparse]pin]~~
    outa[noparse][[/noparse]pin]~~
    dira[noparse][[/noparse]pin]~
    state := ina[noparse][[/noparse]pin] 
    
    


    doesn't allow it much time to fry out the chip's output!
    If it is a concern, should I pull it from the OBEX?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't click on this.....

    Use the Propeller icon!! Propeller.gif
  • LeonLeon Posts: 7,620
    edited 2010-03-10 19:36
    Shorting a high output to ground for any length of time isn't a good idea, you will be exceeding the maximum ratings.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Leon Heller
    Amateur radio callsign: G1HSM
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-03-10 19:37
    microcontrolled said...
    If it is a concern, should I pull it from the OBEX?
    I would. It's always better to use pull-ups.

    -Phil
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2010-03-11 01:34
    *Sigh*

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't click on this.....

    Use the Propeller icon!! Propeller.gif
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2010-03-11 01:55
    Don't be sad, the idea is sound enough and suitable for a Q&D but could lead to failure. I've used this technique for many years except I usually have a current limit resistor in series with the I/O plus I like to add an additional capacitor across the input (on the switch side). The idea is that the RC I/O is more general-purpose and allows me to:
    • Debounce the switch and provide "wetting" current because of the small capacitor
    • Also use the input as a general switched input either switched high, switched low, or floating as software can detect all these states easily.
    • You can also output an analog voltage on the pin using the DUTY mode.
    • Connect an LED etc directly due to the series resistor current limit.
    • Use a parallel LED and switch combo as well.

    Like your av, eight 32-bit heavies ganging up on an 8-bit "pipsqueak", it's just a "no contest"

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    *Peter*
  • MagIO2MagIO2 Posts: 2,243
    edited 2010-03-11 07:10
    Why not use 2 pins. One replacing the ground-line of the switch. It's tristate when you charge the other pin and you pull it low before reading the other pin.
    Of course it's a waste if you only have one button (adds 100% to the pincount ;o), but if you have more than one the waste gets smaller with every button because all buttons can use the same 'grounding-pin'.

    I mean .. I can't imagine running out of resistors for myself, but if that can be a real problem ... for example for a studend ... hard decision ... food or one more resistor ...
    And by murphys law this always happens on public holidays.


    Post Edited (MagIO2) : 3/11/2010 7:18:48 AM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-03-11 20:47
    Micro,

    All is not lost, it turns out. If, instead of connecting the common switch terminals to Vss, you connect them all to a single 330-ohm resistor that goes to Vss, your scheme should still work, and the outputs will be protected.

    However, there is still one very remote failure mode: if two buttons are pressed at once, while the program simultaneously malfunctions and sets the pin for one of them high and the other one low, you will get a short. But that's too unlikely to be concerned about, methinks.

    -Phil
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2010-03-12 01:48
    Thanks Phil!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't click on this.....

    Use the Propeller icon!! Propeller.gif
  • BeanBean Posts: 8,129
    edited 2010-03-12 03:10
    If you were making a thru-hole kit I would use two I/O pins for a button because it means one less componet that the builder has to install. Plus the I/O pins are next to each other so you don't need to make a connection to ground and Vdd. So the layout would probably be easier too. This is of course if you have the extra I/O pins available.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.

    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    ·
Sign In or Register to comment.