unconnected pins usually don't float

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Over the years I've read lots of comments about floating input pins.  I've usually found that unconnected pins read as zero, but never did any thorough testing.  A few years ago I tested the protection diodes on AVR chips, and came to the conclusion that the leakage from the ground diodes is greater than the Vcc diodes, making unconnected pins usually read as 0.  Today I decided to do some specific testing, and my theory has been mostly confirmed.  However it doesn't take much to make a pin float.  For example connecting a 5cm wire (i.e. antenna) is enough to make a pin randomly read as high.  Since pins are usually connected to something, even if it is only a PCB trace, unused pins will often float.  And sometimes they are unintentionally connected to something, such as when flux residue creates a high resistance path between pins (something I've had happen).  Even after a good cleaning, in my testing, an input adjacent to an IO that is connected to Vcc will usually read high and not low.  So the usual advise to consider what you do with unused pins is still valid.

Now before the other old farts say, "No s***, Sherlock", I want to point out that all the comments I previously read about floating inputs were written as if they were gospel.  A good scientist takes nothing on faith; they test.

 

The test code uses a 32-bit counter, waiting for an input to go high, and then turns on an active-low LED and writes the result to eeprom.

#include <avr/io.h>
#include <avr/eeprom.h>

const uint8_t TEST_GPIO = 3;
const uint8_t LED_GPIO = 2;

int main(){
    uint32_t time = 0;
    do {
        time++;
    } while (bit_is_set(PINB, TEST_GPIO));
    DDRB |= (1<<LED_GPIO);
    eeprom_write_dword(0, time);
}

I read the eeprom with avrdude -U eeprom:r:eedump, and od -t x1 eedump.

 

 

EDIT: Profanity edit

I have no special talents.  I am only passionately curious. - Albert Einstein

 

Last Edited: Mon. Feb 17, 2020 - 10:56 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That is actually a good test. And, I suspect that your hypothesis is largely true.

 

On an AVR, it is pretty easy to avoid this situation all together. If a pin is unused, just turn on the pull-up resistor for that pin. The additional current is very low, being only the leakage current on the lower rail protection diode and lower FET. In this context, "very low" is probably in the pA range though the Mega328P spec sheet calls out a maximum of 1uA with no typical.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:

On an AVR, it is pretty easy to avoid this situation all together. If a pin is unused, just turn on the pull-up resistor for that pin. The additional current is very low, being only the leakage current on the lower rail protection diode and lower FET. In this context, "very low" is probably in the pA range though the Mega328P spec sheet calls out a maximum of 1uA with no typical.

 

Or set the DIDR.  Or don't bother if it's not running on battery power.  Or if you are doing ADC oversampling to improve resolution, a floating input with a short antenna wire can be a wanted source of dithering noise.

 

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No mention of parasitic capacitance? Try toggling a port pin set as an output and observe the state of the adjacent pins as inputs.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hmm.  I never interpreted "float" as "float high"...  Perhaps I should have, given the English definition of the word.

My thought was "free floating" as opposed to "moored or attached."

 

"Optiloader" actually uses the properties of floating pins to try to detect whether it is connected to chip.   The IO pin that should be connected to RESET on the target AVR is briefly written LOW, then switched to input and read.  If it's actually connected to a programmable AVR, the pullup present on RESET (external or even internal) will have quickly pulled the pin high again.  If it's not, the low level will persist on the "floating" pin for quite a while, do to the pin's self capacitance.

 

 

While you're checking such things, you might want to check how random a floating analog pin really is, when read by the ADC.   Arduino folk keep recommending such a reading as a seed for the pseudo-random number generator, but I've always had doubts.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A pin can be floating but not change state. The problem is how do you measure the voltage of the pin without affecting it?

I too are suspicious of using an open adc pin for random values - the state can be biased just by breathing on the chip.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah.  I know:  "Floating - like in space, subject to minor forces pushing you in any direction", rather than "floating, like in water - going up."

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

westfw wrote:

"Optiloader" actually uses the properties of floating pins to try to detect whether it is connected to chip.   The IO pin that should be connected to RESET on the target AVR is briefly written LOW, then switched to input and read.  If it's actually connected to a programmable AVR, the pullup present on RESET (external or even internal) will have quickly pulled the pin high again.  If it's not, the low level will persist on the "floating" pin for quite a while, do to the pin's self capacitance.

I've done some experiments with detecting AVRs, and that may not be the most reliable way to do it.  As I mentioned above, unconnected pins adjacent to Vcc and Rst seem to be more likely to read as high vs low.  If you allow just enough time for the RESET pullup to charge the parasitic capacitance, you'll reduce the chance of false positives.  In my testing 1us was always enough.  If your wiring and connectors add an exceptional amount of capacitance, go with 2us.  I also don't recommend supplying power until after the chip has been probed, to avoid the risk of shorting the IO used to supply the power.  While I never completely finished my autodetect code, I started by probing with pullup enabled so as to avoid damage from shorting.  Knowing the different electrical characteristics of AVR IOs, and how the power-on-reset sequence works, I came up with a system for almost foolproof detection.  Some of the important facts I took advantage of:

RESET has no protection diode to Vcc.  Every other IO has Vcc and Gnd protection diodes.

Pullup power is enough to turn on a target AVR, but is not enough current to get the voltage high enough to bring it out of RESET.

Any two IOs other than reset can be used to power up an AVR, due to the protection diodes.  When you factor the voltage drop from the diodes, you can determine if you are connected to Vcc and Gnd or IO.

 

westfw wrote:

While you're checking such things, you might want to check how random a floating analog pin really is, when read by the ADC.   Arduino folk keep recommending such a reading as a seed for the pseudo-random number generator, but I've always had doubts.

As I mentioned above,  a completely unconnected pin tends not to float, but if you want a random input, a 5cm antenna wire might be fine.  The other thing I observed, was that the time for a floating pin to flip states seemed random.  So even without ADC, you could just count the time between state changes, and use the lower 8 bits.  While random number generation isn't one of my obsessions, it would be interesting to write a program to send the "random" counts to a computer for Chi-squared testing.   Many of the search results for AVR random number generators refer to using WDT jitter or external avalanche circuits.  So perhaps a floating input is worth investigating.

 

 

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

ralphd wrote:
Now before the other old farts say, "No s***, Sherlock", I want to point out that all the comments I previously read about floating inputs were written as if they were gospel.  A good scientist takes nothing on faith; they test.

Watson, here.  Maybe many of us old farts have been involved with AVR8 designs that have mysterious power draw.  Maybe when otherwise floating pins were tied, as with the methods you mentioned and others, the mysterious power draw had disappeared, just like a poltergeist.  Maybe it was the magic disenchantment spells of inline assembly language in GCC.  Maybe we have heard of CMOS latchup nearly 50 years ago, being old farts.  Indeed, we treat it as gospel.  Do we try to create the situation in each application, your "test", or do we design and implement to minimize or avoid it?  Perhaps we don't see how close we can drive to the road shoulder and be pulled into the ditch and be overturned.  Rather, we take as gospel the old wive's tale:  Stay in your lane.

 

 

Probably you should thoroughly test all variations of the AVR instruction set for each model you use, instead of taking documentation such as the datasheets and Instruction Set and compiler code generation models as Gospel.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Mon. Feb 17, 2020 - 10:57 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The crux of the issue is what works on your desk will probably fail miserably in the real world. For those of us that have done EMC testing, we get a glimpse of what actually happens.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
the mysterious power draw

 

Rick powers his car with quantum energy teleportation from AVR pins... holy Microverse. It makes sense now.