Determine if a pullup is on a PIN or if it is floating
ke4pjw
Posts: 1,154
I did something like this on the P1, per @"Phil Pilgrim (PhiPi)" , to detect if a pin had a pullup on it, or if it was floating. It works incredibly reliably.
Can this also be done on the P2? I don't know if PINF is a FLTL or FLTH.
PINL(55) PINF(55) if PINR(55) == 1 ' Pin has a pullup
Comments
If you're looking for an external pull-up, you may want to use pinclear() so that any internal connections are removed.
So something like this?
I am going to give this a swing tonight. Thanks!
I tend to be cautious, so I might do this:
An extra cautiousness would be to have a known delay between the float and the pin read. Then a faster execution won't inadvertently sample before the pull-up crosses the threshold.
I had to use float low. I suspect pinfloat is the same at FLTH.
Thanks guys!
Why is that DRVH there? Did it help in some way?
Another possibility on the P2 is to enable a weak internal pulldown resistor and then read the input. Any external pullup lower then the internal pulldown will pull the input high. This doesn't depend on timing.
Andy
Hehe, one step further is use the compDAC pin mode to measure a floating ADC - https://forums.parallax.com/discussion/174441/measuring-floating-pin-voltage-adc-from-just-the-built-in-comparator
This will work well with even very high pull-up resistances.
Thanks guys, all around! What I have works but I will keep these in my back pocket. I am using a 100K pullup.
Oops, the pin mode above doesn't combine with the SAR routine. CompDAC pin mode can do a 1k5 pull-down though. So still a possible approach there,