2008-11-19 03:04 AM
Detect a floating input
2011-05-17 03:52 AM
Hello,
I have a board which we populate or not an external pull-up. I'd like to detect when the input is floating in order to enable the internal pull-up. Is there a way to detect the floating input in the source code. Regards2011-05-17 03:52 AM
If you used strong external pull-downs, then you could test more easily for a floating input. At startup you would then just enable the internal pull-up, if the line still remains low (after a short delay) then you know there is an external pull-down present and you can disable the internal pull-up.
But I've just remembered the STM32 has the luxury of both internal pull-ups or pull-downs. So if you use a strong external pull-up (5K?) then you could enable the weak internal pull-down (approx. 40K?). If the line remains high after a short delay then you have an external pull-up present.2011-05-17 03:52 AM
I don't have a strong pull-down. Only a pull-up (1M Ohm).
I thought to set a pull-down, wait a while and reconfigure it in floating input. Read the value, if I read a one, that means we have an external pull-up. What do you think about that? Is there any possibility to get a bad reading?2011-05-17 03:52 AM
If these are just unused inputs then there is no harm in having both pull-ups active (no current is drawn if the pins are unused).
I wouldn't trust your method for determining if the input is floating. It might appear to work in some environments (eg. the lab) but it might not in a particularly noisy environment (near a mobile phone), especially if the pins are connected to tracks that might act like antennas.2011-05-17 03:52 AM
May be I'm wrong but...
Having much stronger external pull-up (say 10k) and connecting internal pull-down of 30k-50k (see datasheet) you will never get a voltage level detectable as low. But there will be no problem with low level having such pull-up not connected...2011-05-17 03:52 AM
Ok:
Weak Pull-up equivalent on STM32F103ZE = Rpu [Datasheet section 5.3.13] = 40KOhm, and Rpd (pull-down) is equivalent. So, you specified upper in this thread that your external pull-up is 1MOhm. So, if you connect the pull-down, you should have V*(40/1040) = 0.04*V [Where V is the voltage on top of the possible pull-up] Now, the datasheet states two kind of IOs: TTL and CMOS. For TTL, max Vlow max is 0.8V. Unless your V is 20V, the pull down is enough to garantee a low level detection with input-pull down. In CMOS mode, the Vlow max is Vcc*0.35, so the V*0.04 should also detect a low voltage. I do not know wich STM32 you use, nor the exact pins, so I can not say if they are TTL or CMOS. Let's assume it's TTL. You could activate the pull-down, read [should return 0], then release the pull up and read again. Should return 0 in case of free-floating bus (as you just grounded it) and 1 if there is a pull up. Care should be taken, because there is a lot of error risk. If your pin is connected to a trace acting like an antenna, or just with parasitic coupling to a Vcc, you could end-up having a high-level on it. To determine the likeliness of this, you could put the port in hiZ, then probe the pin with your scope. Make every other peripheral on the board active, and look if you see subtile differences and small spikes crossiong the Vcc*0,4. If interference is not a big issue, your program could also do the same verification on every pin in the same situation , or many times for each pin to ''statistically'' rule out a glitch. I think it is possible to do as described, and should be very reliable. However, I would never do that in a life-support/safety/spacecraft device. But heck, if it's an MP3 player and the failure would just mean a reboot (by watchdog or user), it should do.