Shop Learn
Reliably detect if a pin is high or low if it might be floating? — Parallax Forums

Reliably detect if a pin is high or low if it might be floating?

Is there are way to reliably detect if a pin is high or low if it is possibly floating on the P1? I made a mistake on a board layout years ago by not including a pulldown on an optional accessory output, and now want to detect if an accessory board is installed. I have not tested if just placing a pullup would work, but I am not sure if it would work reliably. I suspect with it is floating, it may false positive as "high".

Comments

  • evanhevanh Posts: 13,108

    Probably worth modifying all existing boards.

    Software only solution will struggle. It maybe to measure an R-C charge curve, depending on how long the tracks are. Would need to know a lot more about the circuit.

  • Thanks for your thought @evanh. I am just using the pin to detect if a module is plugged via pull-up. The module (a ESP8266) can be interrogated via serial, so I think I will go that route, as the option plug has the extra pics for serial. If the detect pin is high, interrogate the module, and if detected, enable the features for that module. I like the idea of measuring the RC curve, though.

    This is for AC dimming light controllers I designed over a decade ago. I have a handful out in the wild used by friends and others. I am adding the ESP8266 board so they can use E1.31 (DMX over IP) so they can be wireless.

    I have a whole stack of unpopulated boards and basically, WS2811 LEDs have made them obsolete, LOL. I still use 13 or so in my Christmas display, but they are all eventually going to be replaced with my P2 boards and WS2811 LEDs.

  • Pulse the pin high, then let it float. Does it stay high? Pulse it low, then let it float. Does it stay low? If the answer to both questions is yes, then the pin is floating.

    -Phil

  • evanhevanh Posts: 13,108

    Oh, do the serial interrogation option. That's a way better solution, IMHO.

  • @"Phil Pilgrim (PhiPi)" Thanks Phil. I am going to do this until I get my hands on actual hardware. I have a friend that is actually designing the daughter board. I have all of my DMX boards packed away for summer and am sending him code to try :)

  • Found this SPIN function in some old test code:

    PUB readPinStatus(ioPin) : state   '   returns: 0 for Low, 1 for HiZ, 3 for High
    
        outa[ioPin] := 0    ' set pin low  
        dira[ioPin] := 1    ' output low for a moment
        dira[ioPin] := 0    '
        outa[ioPin] := 1    ' set pin high
        state := ina[ioPin] ' read first input state
        dira[ioPin] := 1    ' output high for a moment
        dira[ioPin] := 0 
        state <<= 1         ' shift first state to bit1
        state |= ina[ioPin] ' store second state to bit0
    

    No idea about the original author, but seem to recall it coming from the forums many moons ago.

Sign In or Register to comment.