mannok
Posts: 63
Joined: Sun Jan 11, 2015 11:19 am

Stupid question about GPIO floating state

Fri Dec 20, 2019 2:47 am

I know that I can stabilize unconntected GPIO input pin by setting it to PULL_DOWN or PULL_UP. However, I wonder why an unconnected GPIO pin will be floating? As long as it is not connecting to an external voltage source, shouldn't it be 0V?

User avatar
rpdom
Posts: 17029
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Stupid question about GPIO floating state

Fri Dec 20, 2019 4:52 am

Why would it be 0V? It's not connected to anything so has no fixed voltage.
Unreadable squiggle

mannok
Posts: 63
Joined: Sun Jan 11, 2015 11:19 am

Re: Stupid question about GPIO floating state

Fri Dec 20, 2019 5:25 am

If it is not 0v and keep fluctuating... then where is the voltage comes from?

User avatar
rpdom
Posts: 17029
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Stupid question about GPIO floating state

Fri Dec 20, 2019 6:12 am

Random electro-magnetic interference from the air. Radio waves and all sorts of things can generate tiny currents in wires. The GPIO input is very sensitive if it doesn't have any pulls set.
Unreadable squiggle

mannok
Posts: 63
Joined: Sun Jan 11, 2015 11:19 am

Re: Stupid question about GPIO floating state

Fri Dec 20, 2019 7:12 am

rpdom wrote:
Fri Dec 20, 2019 6:12 am
Random electro-magnetic interference from the air. Radio waves and all sorts of things can generate tiny currents in wires. The GPIO input is very sensitive if it doesn't have any pulls set.
Ohhhh... I see... Thank you...
Would these random factor can cause a voltage with >3V to the GPIO even if there is a pull down resistor?

I mean the purpose of a pull down resistor is to induce the noise voltage between 0.8V - 1.3V to GND. However, I wonder if the noise comes from random electro-magnetic interference can be larger than 1.3V? let say it is 3.0V, then the pull down resistor will become useless in the ocassion...

mattmiller
Posts: 2236
Joined: Thu Feb 05, 2015 11:25 pm

Re: Stupid question about GPIO floating state

Fri Dec 20, 2019 7:21 am

The pull-down (or pull-up) only sets the input to low or high in the absence of a real signal.

Once you apply a 3V signal to the input, it will go high

If working in a harsh RF enviorment, it is normal practice to add extra external pull up/down resistors of a lower value than the nominal 50K internal ones

PS It is not a stupid question :)

mannok
Posts: 63
Joined: Sun Jan 11, 2015 11:19 am

Re: Stupid question about GPIO floating state

Fri Dec 20, 2019 7:31 am

mattmiller wrote:
Fri Dec 20, 2019 7:21 am
The pull-down (or pull-up) only sets the input to low or high in the absence of a real signal.

Once you apply a 3V signal to the input, it will go high

If working in a harsh RF enviorment, it is normal practice to add extra external pull up/down resistors of a lower value than the nominal 50K internal ones

PS It is not a stupid question :)
Yes, so I wonder would the noise (fake signal) be large enough e.g. 3V to make that pull-down resistor lose its effectiveness? (Since 3V is high enough to make the noise seems to be a real signal)

I think it is dumb because seems that this is a very first step to play with the GPIO :(

User avatar
davidcoton
Posts: 4909
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: Stupid question about GPIO floating state

Fri Dec 20, 2019 10:19 am

RF interference and (even more so) static electricity can induce very high voltages, way over 3V3.
But GPIO inputs are clamped to the range 0V to 3V3 (give or take one diode Vf) so that no damage will occur.
The source of stray voltages can't supply a significant current, except in extreme RF environments.
If you apply a voltage that is out of range, however, you risk destroying the clamp diodes and your Pi.

And a final thought. Attaching a long wire to a GPIO input without a pull will pick up enough voltage to cause stray input signals. Often the on-board (selectable) pull resistor is not enough to cure this, lower value pull resistors, decoupling capacitors to ground, and small series resistors are sometimes necessary.
Signature retired

mattmiller
Posts: 2236
Joined: Thu Feb 05, 2015 11:25 pm

Re: Stupid question about GPIO floating state

Fri Dec 20, 2019 11:22 am

I think it is dumb because seems that this is a very first step to play with the GPIO
Aah - that's a different point :)

GPIO stands for GENERAL PURPOSE input output

Everyone has a different requirement as to what the pins are used for

So tying them up or down as a default would not suit the purposes of a lot of people so that is why most of the pins are not set one way or another

Some learning programming environments DO default to setting the pins as inputs with (usually) pulldown resistors enabled so that this problem is not encountered

mannok
Posts: 63
Joined: Sun Jan 11, 2015 11:19 am

Re: Stupid question about GPIO floating state

Fri Dec 20, 2019 11:41 am

davidcoton wrote:
Fri Dec 20, 2019 10:19 am
RF interference and (even more so) static electricity can induce very high voltages, way over 3V3.
But GPIO inputs are clamped to the range 0V to 3V3 (give or take one diode Vf) so that no damage will occur.
The source of stray voltages can't supply a significant current, except in extreme RF environments.
If you apply a voltage that is out of range, however, you risk destroying the clamp diodes and your Pi.

And a final thought. Attaching a long wire to a GPIO input without a pull will pick up enough voltage to cause stray input signals. Often the on-board (selectable) pull resistor is not enough to cure this, lower value pull resistors, decoupling capacitors to ground, and small series resistors are sometimes necessary.
davidcoton, thank you for the detail explanation. this makes sense.

However, I am still confusing at a point. You mentioned that RF interference can induce very high voltages. The purpose of a pull-down resistor is to stabilize the stray voltages to "logical 0". (If I understand correctly, "stray voltage" here means 0.8V to 1.3V which we consider as which has fell in "undefined logical area")

My confusion is... according to what you mentioned "RF interference can induce very high voltages, way over 3V3". A pull-down resistor in this case still cannot overcome this "wrong" signal. Since this "fake high voltage" does not fall in 0.8V to 1.3V so that the "fake voltage" will just applied to the GPIO pin just like a real "logical high" signal.

User avatar
rpdom
Posts: 17029
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Stupid question about GPIO floating state

Fri Dec 20, 2019 12:12 pm

mannok wrote:
Fri Dec 20, 2019 11:41 am
My confusion is... according to what you mentioned "RF interference can induce very high voltages, way over 3V3". A pull-down resistor in this case still cannot overcome this "wrong" signal. Since this "fake high voltage" does not fall in 0.8V to 1.3V so that the "fake voltage" will just applied to the GPIO pin just like a real "logical high" signal.
Why not? The high voltages from RF will have a very weak current. The resistors can easily pull that down to 0V.
Unreadable squiggle

mannok
Posts: 63
Joined: Sun Jan 11, 2015 11:19 am

Re: Stupid question about GPIO floating state

Fri Dec 20, 2019 12:26 pm

rpdom wrote:
Fri Dec 20, 2019 12:12 pm
mannok wrote:
Fri Dec 20, 2019 11:41 am
My confusion is... according to what you mentioned "RF interference can induce very high voltages, way over 3V3". A pull-down resistor in this case still cannot overcome this "wrong" signal. Since this "fake high voltage" does not fall in 0.8V to 1.3V so that the "fake voltage" will just applied to the GPIO pin just like a real "logical high" signal.
Why not? The high voltages from RF will have a very weak current. The resistors can easily pull that down to 0V.
But according to ohms law, when the resistance is constant, how can a very high voltage induce a very weak current?

User avatar
rpdom
Posts: 17029
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Stupid question about GPIO floating state

Fri Dec 20, 2019 12:53 pm

mannok wrote:
Fri Dec 20, 2019 12:26 pm
But according to ohms law, when the resistance is constant, how can a very high voltage induce a very weak current?
Have you taken into account the resistance of the air?
Unreadable squiggle

User avatar
davidcoton
Posts: 4909
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: Stupid question about GPIO floating state

Fri Dec 20, 2019 1:48 pm

mannok wrote:
Fri Dec 20, 2019 11:41 am
My confusion is... according to what you mentioned "RF interference can induce very high voltages, way over 3V3". A pull-down resistor in this case still cannot overcome this "wrong" signal. Since this "fake high voltage" does not fall in 0.8V to 1.3V so that the "fake voltage" will just applied to the GPIO pin just like a real "logical high" signal.
  1. There is nothing "fake" about the high voltage. It is very real, if unwanted.
  2. The voltage, once clamped to the correct range, can indeed be low, high, or in the indeterminate range. Even in the middle range, the logic output must be low or high, it's just that you cannot tell which by knowing the input voltage.
  3. The interfering voltage has a high "source impedance", so cannot deliver a high current. Thus, the pull resistor will not drop much voltage, but will still do the job of keeping the input in a determinate state. The voltage is notionally dropped across the source impedance.
  4. Static discharges can have a high impulse current, but it doesn't just long. I remember in about 1980 a colleague trying out a static interference tester, which had a carbon probe to limit the current. Our equipment was fine until he removed the probe and applied high voltage directly, thus instantly frying our prototype....
Signature retired

mannok
Posts: 63
Joined: Sun Jan 11, 2015 11:19 am

Re: Stupid question about GPIO floating state

Sat Dec 21, 2019 12:25 am

I am stucking at a point. Let consider the following figure which I captured from https://www.youtube.com/watch?v=00NTVf1dwPU&t=333s:

Image

When the switch is closed, the current flows like that:

Image

At this point I still understand. However, as davidcoton mentioned before, RF interference can induce very high voltage, let say 5V. The voltage is applied to the point where the red arrow pointed to:

Image

In such ocassion, how can the pull-down resistor fix this unwanted RF interference signal? Since it looks no different with a real 5V input source.


hippy
Posts: 7459
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Stupid question about GPIO floating state

Sat Dec 21, 2019 10:02 am

mannok wrote:
Sat Dec 21, 2019 12:25 am
let say 5V. The voltage is applied to the point where the red arrow pointed to: ... In such ocassion, how can the pull-down resistor fix this unwanted RF interference signal? Since it looks no different with a real 5V input source.
If 5V is being induced at that point then the pull-down cannot fix the problem.

The situation, for want of better words to describe it, is you have some RF source which transmits through some resistance ( air, walls etc ) before reaching that point. That resistance travelled through combined with the pull-down will create a voltage divider which will reduce the voltage which appears on that pin.

The pull-down is hopefully low enough that it reduces the induced RF to below a level which will affect the output, so induced RF has no affect.

If the RF source is strong enough, or the pull-down not low enough, then that induced RF will affect the output.

To be perfectly immune from RF the pull-down would need to be reduced to Zero Ohm, but that's not possible because even short lengths of wire have some resistance. If the induced RF is strong enough it will pull the input up enough to affect the output.

In those cases one would have to enclose the equipment in an RF-blocking or reducing case or enclosure so it cannot reach the input. Effectively increasing the resistance the RF travels through so it is kept to a level by the potential divider created with the pull-down which does not affect the output.

In most cases though RF will not not strong enough to produce the kinds of input voltages which affect the output.

Code: Select all

                           -|----.----------- 3V3
      \|/         \|/       |   .|.
       |    ___    |        |   |_|
       |---|___|---|        |    |     |\
"RF" --'           `---.----|----^-.---| >---
            Big       .|.   |     .|.  |/
                      |_|   |     |_|
                       |    |      |
                      -^----|------^--------- 0V

User avatar
Burngate
Posts: 6290
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Stupid question about GPIO floating state

Sat Dec 21, 2019 11:12 am

mannok wrote:
Sat Dec 21, 2019 12:25 am
I am stucking at a point. Let consider the following figure ...

At this point I still understand. However, as davidcoton mentioned before, RF interference can induce very high voltage, let say 5V. ...

In such ocassion, how can the pull-down resistor fix this unwanted RF interference signal? Since it looks no different with a real 5V input source.
My take on all this:
The input of a MOS gate or a Pi's GPIO is essentially a capacitor; to change it from low to high or high to low requires that capacitor to be charged or discharged, and that requires energy to move electrons from or to it.

If you're doing it deliberately, you have plenty of energy available, be it from a small battery or from Sizewell B - the capacitance is small, so the amount of energy is miniscule by comparison. Plenty of electrons being moved around, so a few here or there is no problem.

But if it's EMI or a local lightning strike that's going to cause the problem, that energy has to be picked up by the wiring, etc.
The electrons have to be moved from the input capacitance to somewhere else. A changing magnetic field could move them to the other end of the wire if it's long enough and there's enough capacitance between it and your desktop, or a static electric field could do the same job.

But it still takes energy, and you don't have that available unless you're in a noisy environment - noise being lots of chaotic energy.
A pull resistor is there to dissipate that energy as it arrives, before it can cause a problem.

mannok
Posts: 63
Joined: Sun Jan 11, 2015 11:19 am

Re: Stupid question about GPIO floating state

Sat Dec 21, 2019 7:04 pm

hippy wrote:
Sat Dec 21, 2019 10:02 am
mannok wrote:
Sat Dec 21, 2019 12:25 am
let say 5V. The voltage is applied to the point where the red arrow pointed to: ... In such ocassion, how can the pull-down resistor fix this unwanted RF interference signal? Since it looks no different with a real 5V input source.
If 5V is being induced at that point then the pull-down cannot fix the problem.

The situation, for want of better words to describe it, is you have some RF source which transmits through some resistance ( air, walls etc ) before reaching that point. That resistance travelled through combined with the pull-down will create a voltage divider which will reduce the voltage which appears on that pin.

The pull-down is hopefully low enough that it reduces the induced RF to below a level which will affect the output, so induced RF has no affect.

If the RF source is strong enough, or the pull-down not low enough, then that induced RF will affect the output.

To be perfectly immune from RF the pull-down would need to be reduced to Zero Ohm, but that's not possible because even short lengths of wire have some resistance. If the induced RF is strong enough it will pull the input up enough to affect the output.

In those cases one would have to enclose the equipment in an RF-blocking or reducing case or enclosure so it cannot reach the input. Effectively increasing the resistance the RF travels through so it is kept to a level by the potential divider created with the pull-down which does not affect the output.

In most cases though RF will not not strong enough to produce the kinds of input voltages which affect the output.

Code: Select all

                           -|----.----------- 3V3
      \|/         \|/       |   .|.
       |    ___    |        |   |_|
       |---|___|---|        |    |     |\
"RF" --'           `---.----|----^-.---| >---
            Big       .|.   |     .|.  |/
                      |_|   |     |_|
                       |    |      |
                      -^----|------^--------- 0V
Hi hippy, thank you for these explanation. Yes this make sense...

To sum up what you mean... Can I imagine as once RF arrived to our circuit, it usually has passed through some external resistors like walls, air, etc. To include these external resistors into our circuit, They are way too high when comparing with our pull-down resistor. That means our pull-down resistor should drop less voltage (same for GPIO according to KVL).

mannok
Posts: 63
Joined: Sun Jan 11, 2015 11:19 am

Re: Stupid question about GPIO floating state

Sat Dec 21, 2019 7:21 pm

Burngate wrote:
Sat Dec 21, 2019 11:12 am
mannok wrote:
Sat Dec 21, 2019 12:25 am
I am stucking at a point. Let consider the following figure ...

At this point I still understand. However, as davidcoton mentioned before, RF interference can induce very high voltage, let say 5V. ...

In such ocassion, how can the pull-down resistor fix this unwanted RF interference signal? Since it looks no different with a real 5V input source.
My take on all this:
The input of a MOS gate or a Pi's GPIO is essentially a capacitor; to change it from low to high or high to low requires that capacitor to be charged or discharged, and that requires energy to move electrons from or to it.

If you're doing it deliberately, you have plenty of energy available, be it from a small battery or from Sizewell B - the capacitance is small, so the amount of energy is miniscule by comparison. Plenty of electrons being moved around, so a few here or there is no problem.

But if it's EMI or a local lightning strike that's going to cause the problem, that energy has to be picked up by the wiring, etc.
The electrons have to be moved from the input capacitance to somewhere else. A changing magnetic field could move them to the other end of the wire if it's long enough and there's enough capacitance between it and your desktop, or a static electric field could do the same job.

But it still takes energy, and you don't have that available unless you're in a noisy environment - noise being lots of chaotic energy.
A pull resistor is there to dissipate that energy as it arrives, before it can cause a problem.
Hi Burngate, do you mean that RF interference usually contain less energy so that it cannot charge up GPIO pin's capacitor in order to change the affect the read signal?

User avatar
Burngate
Posts: 6290
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Stupid question about GPIO floating state

Sun Dec 22, 2019 10:45 am

Most of the time, most places, yes probably. Depends on your environment.
Also not just radio frequency - low frequency as well.

In the changing magnetic field from your Hoover, a longer wire will pick up more energy, so move more electrons, as long as there's somewhere for them to go.
And it'll let more electrons get close to your cat's fur as it walks by.

A few years ago, the sun belched a mass of ionised gas straight towards the Earth.
When it arrived, it had little effect on anybody's i-pod, because they're too small. The US grid, however, is rather larger, and it picked up enough energy to shut itself down for a few days.

mannok
Posts: 63
Joined: Sun Jan 11, 2015 11:19 am

Re: Stupid question about GPIO floating state

Tue Dec 24, 2019 8:36 am

Burngate wrote:
Sun Dec 22, 2019 10:45 am
Most of the time, most places, yes probably. Depends on your environment.
Also not just radio frequency - low frequency as well.

In the changing magnetic field from your Hoover, a longer wire will pick up more energy, so move more electrons, as long as there's somewhere for them to go.
And it'll let more electrons get close to your cat's fur as it walks by.

A few years ago, the sun belched a mass of ionised gas straight towards the Earth.
When it arrived, it had little effect on anybody's i-pod, because they're too small. The US grid, however, is rather larger, and it picked up enough energy to shut itself down for a few days.
Wow... I see... thank you!

hippy
Posts: 7459
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Stupid question about GPIO floating state

Tue Dec 24, 2019 10:53 am

mannok wrote:
Sat Dec 21, 2019 7:04 pm
Hi hippy, thank you for these explanation. Yes this make sense...

To sum up what you mean... Can I imagine as once RF arrived to our circuit, it usually has passed through some external resistors like walls, air, etc. To include these external resistors into our circuit, They are way too high when comparing with our pull-down resistor. That means our pull-down resistor should drop less voltage (same for GPIO according to KVL).
Yes, I think we are on the same page. The ' big resistor' from the RF source, combined with the low value resistor pull-down will minimise the RF getting into the circuit, will have less voltage across it.

boyoh
Posts: 1468
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Stupid question about GPIO floating state

Wed Dec 25, 2019 5:43 pm

You are given the option of setting the GPIO
To a impedance level that the processor can
Respond to. In its high impedance state floating
It will not sink or source a working level signal
This being a logic level 0 low or 1 high , So you
MUST set it to a working impedance level by
Setting the internal resistance 50k or using a
External resister of 10k . If you want it to respond
To a logic 1 high you connect it to the 0v rail
If you want it to respond to a logic 0 low you
Connect it to the 3.3v rail
Regards BoyOh
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

Return to “Beginners”