Shop OBEX P1 Docs P2 Docs Learn Events
grounding output pin w/no resistor? — Parallax Forums

grounding output pin w/no resistor?

northcovenorthcove Posts: 49
edited 2009-06-07 22:26 in Propeller 1
Am I harming the Propeller by testing for momentary switch closures that ground a pin without a resistor using the following code?

dira [noparse][[/noparse] pin ]~~    'briefly set as output
outa [noparse][[/noparse] pin ]~~   'charge it (lasts < 150uSec at PLL2X)
dira [noparse][[/noparse] pin ]~     'set input
return !ina [noparse][[/noparse] pin ] & 1 'return button down




Thanks!

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-06-04 20:45
    Yes, you probably are. The pin may eventually fail. Use a pullup instead, and just read the input.

    -Phil
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-06-04 20:53
    It simply won't work even if it would be harmless for the pin.

    If you switch the pin to ground, what do you expect when reading ina? It will be 0 if the switch is 'on' but it can be anything if the switch is 'off' because then it's floating. It will see whatever the electromagnetic fields surrounding will generate.
  • northcovenorthcove Posts: 49
    edited 2009-06-04 21:07
    The funny thing is that this technique has been working on my project for 4 months with no problems. I haven't fried any Propellers...yet. However, I'm revamping my PCB design and figure I oughta do as Phil suggested. Another funny thing is my original prototype boards used pullups but I pulled them out to eliminate components because my kludge worked.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-06-04 21:15
    It works, but you're stressing the pin more than it should be. Eliminating a one-cent part is false economy anyway. (MagIO2 just misread your code, BTW.)

    -Phil
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-06-04 21:35
    There is a way to do this without damaging a pin. See the 4x4 keypad decoder in the object exchange that doesn't require any external resistors, capacitors, or external IC's.

    obex.parallax.com/objects/279/


    With the keypad, the method uses a capacitive PIN approach to read the keypad.

    The basic idea is that ALL pins are made LOW and an OUTPUT to "discharge" the I/O pins.

    Then, ALL pins are set to an INPUT state.

    At this point, only one pin is made HIGH and an OUTPUT at a time.

    If the "switch" is closed, then a HIGH will be read on the input, otherwise a LOW will be returned.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2009-06-06 03:42
    The problem with shorting a pin has more to do with thermal stress as the current tends to be self-limiting anyway. Short pulses where abnormal currents flow are used all the time in electronic circuits so it is nothing new here either. In fact CMOS can tend to short out completely as it switches through it's transition point where both P and N are conducting. A 20ma max LED will burn out if you pass 100ma through it yet many LEDs have more than that routinely as they are multiplexed and the average current (with limits) is 20ma or less.

    I have used your approach many times although I must admit I will use some sort of current limit resistor to cover me in the case of a software glitch. Of course a pullup will work but there are reasons why you would also do it this way. Anyway, kludges are good for where you need a kludge, just don't let it become a habit.

    *Peter*
  • northcovenorthcove Posts: 49
    edited 2009-06-07 04:38
    My new boards (only32x38mm w/all SMD components) just arrived from ExpressPCB so it's a done deal. For safety I have added a 4K7 between the pins and gnd. Thanks for all your feedback.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-06-07 15:24
    northcove said...
    For safety I have added a 4K7 between the pins and gnd.
    I do hope you meant to say, "... between the pins and Vdd."

    -Phil
  • northcovenorthcove Posts: 49
    edited 2009-06-07 16:13
    There is a 4K7 between each microswitch & vss which limits the current between an output pin and vss when the switch is closed.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-06-07 17:10
    I'm perplexed that you would do it that way (unless it's to save power when the button is pressed), when it's so much easier just to use a pullup and read the pin (i.e. no setting outputs to charge the gate, etc.):

    attachment.php?attachmentid=61406

    -Phil

    Post Edited (Phil Pilgrim (PhiPi)) : 6/7/2009 5:16:23 PM GMT
    127 x 193 - 663B
  • northcovenorthcove Posts: 49
    edited 2009-06-07 17:33
    I agree that pulling up as you suggest is better, however 1) it works w/no resistors, 2) I don't like soldering 0603 SMD resistors, 3) it eliminates 16 resistors on each board, 4) the board will be reused in other applications where those pins should not have any resistors, 5) my board must be smaller than 32x32mm to fit into an enclosure, 6) 3 additional lines of Spin code for each poll is acceptable, and 7) the boards have already been etched.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-06-07 18:04
    Well, I'm guess I'm still confused. I only posted the comment because you said you had added the resistors. My point was that if you were going to add them anyway, make them pullups on the pins instead of current limiters on the switches.

    But you have boards, and they work, so I guess it doesn't matter.

    BTW, you can get 0612 quad resistors that are easier to solder than 0603 singles, since they won't tombstone, and take up way less space than four 0603s. You will need some solder braid to mop up the inevitable bridge, though.

    -Phil
  • northcovenorthcove Posts: 49
    edited 2009-06-07 18:20
    I added some axial resistors into the control wiring, not on the board. This board is my first SMD, and only my 3rd PCB so I'm still learning heaps (like SMD resistor arrays are available.) I'm soo thankful for Digi-Key with free shipping to NZ.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-06-07 19:39
    Ah, so, now I get it.
    northcove said...
    I'm soo thankful for Digi-Key with free shipping to NZ.
    What?!!! Free shipping?!! We don't get that here in the 'States! (Now I wonder if they tack on a little extra so you guys can get it for free. Hmm.)

    -Phil
  • northcovenorthcove Posts: 49
    edited 2009-06-07 19:51
    I'm not sure how Digi-Key recoups their shipping costs for NZ. Could be a a special deal with UPS for LAX-AKL air freight and a deliberate cost centre to build market share. A spot check for P8X32A from US & NZ DigiKey is roughly the same price after exchange rate conversion. Free shipping is only for orders over NZ$125. Naturally, all my orders are just over that amount.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2009-06-07 21:05
    I like the capacitor charging trick too, with a small series resistor, both to save power but also to act as a short term, dynamic memory to detect events that might be missed by simple polling. In that case, the order is inverted:

    ' in a loop...
    pinState := ina [noparse][[/noparse] pin ] ' low if event occurred
    dira [noparse][[/noparse] pin ]~~    'briefly set as output
    outa [noparse][[/noparse] pin ]~~   'charge it 
    dira [noparse][[/noparse] pin ]~     'set input primed for event to pull it low.
    ' continue...
    




    The shipping issue is off topic, but hey, I just got a shipment from Newark/Farnell in the UK shipped to California for $20 via air, while stuff sent domestic via air costs a fortune. So it can work both ways, but go figure?!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-06-07 21:26
    Tracy,

    That's a neat idea: no latches required if you check it often enough. When you do that, do you add an extra cap? It seems as if just a gate charge would leak off pretty quickly.

    -Phil
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2009-06-07 22:26
    Generally with external cap in the range of 1nF to 0.1uF.

    In the case of a leaky switch, the attached circuit to help isolate the leakage.
    attachment.php?attachmentid=61416
    At room temperature in a dry room and on a clean circuit board, the droop even with no external capacitor is on the order of millivolts per second. It can hold its state for a suprisingly long time. BUT! If one waves a hand at it, the charge transfer from body capacitance, static or AC line coupling can carry it rapidly one way or the other.

    <<Did I burn out a Propeller pin?>> A good quick test of the functionality of unconnected pins is to charge them first one way, then check for state, and then charge them the opposite way, and again check for state. That tests all three functions, output high, output low, and input high Z.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
    152 x 88 - 5K
Sign In or Register to comment.