The analog input parameters for GPIO pins

arao23
Posts: 30
Joined: Tue Dec 13, 2016 4:44 pm

The analog input parameters for GPIO pins

Postby arao23 » Sun Jan 01, 2017 10:05 pm

Do they measure voltage or current? And what is the specification?

I read somewhere that the maximum current through each pin is 12 mA (with 6 mA optimum). Can I apply 0 to 6 mA signal to a GPIO pin and read it?

Or can it read just voltage? What are the voltage specs?

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: The analog input parameters for GPIO pins

Postby kolban » Sun Jan 01, 2017 10:31 pm

I are a dummy on electronics ... but this is how I think of electricity. Imagine a plastic soda bottle without a lid pointing up. The soda bottle is full of water. Now imagine the bottom of the soda bottle is special. It is a "plunger" like contraption. Think of it like a syringe where when you press the plunger, you are decreasing the volume of the bottle by pushing the plunger upwards.

Can you picture that model?

Ok ... now ... voltage is like the amount of pressure you are applying on the plunger. If you don't apply any pressure, nothing will happen. Now imagine that you apply a constant pressure on the plunger ... what do you think will happen? The answer (in my mind) is that water will start to come out the open top of the bottle. The water in this story is the electricity (a flow of electrons). The rate at which the water is coming out of the bottle is what we call "current" and the amount of pressure you are applying to the plunger is the "voltage" in our analogy. If you apply a small force to the plunger, then only a small amount of water (per second) will come out ... while if you apply a lot of pressure, a lot of water will come out (per second). As you might imagine, there is a ratio between the pressure (voltage) and water per second (current). In this story there is also another factor ... the width of the neck of the bottle. If the opening of our soda bottle is small, then the amount of water coming out per second will be less (for the same plunger pressure) as for a wider bottle opening with the same pressure. The size of the bottle opening provides a "resistance" to the water coming out.

In our Analog to Digital conversion at the ESP32, what we are measuring is voltage (the pressure being applied to the plunger) and not any current. Think of the ESP32 as having its thumb over the top of the bottle as you change the pressure on the plunger. No actual water is coming out ... so no current is flowing ... but we can still measure the pressure present.

A "signal" is the measurement of voltage and not of current flowing.

This broad story helps me to understand and it may be horribly flawed ... but it seems to match my models and experience and it may be of use to others. As for the specs ... I'm afraid I don't know off the top of my head. It will either be the reference input voltage (eg. 3.3V) or it will be a fixed value like 1V. Obviously it is important to know the answer ... and hopefully smarter folks can follow up.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

arao23
Posts: 30
Joined: Tue Dec 13, 2016 4:44 pm

Re: The analog input parameters for GPIO pins

Postby arao23 » Sun Jan 01, 2017 11:58 pm

Hi kolban, thank you very much for your detailed answer! Okay, I get it now. I'm a software engineer, so this stuff is pretty much all self-taught for me. I love the analogy to Ohm's law ;)

After a bit of scouring through the git repo, I found the specs. Looks like we can set the analog attenuation with adc1_config_channel_atten(), but the range is pretty narrow, looks like with ADC_ATTEN_11db, the max is around 3.2v.

freeman
Posts: 4
Joined: Thu Nov 17, 2016 1:11 am

Re: The analog input parameters for GPIO pins

Postby freeman » Thu Jan 05, 2017 4:31 pm

Far from flawed, quite a bit of work has been done on the relationship between eletronic theory and the study of hydrodynamics (sub discipline of fluid mechanics).

Arao, here's a quick tutorial in support of Kolban's post. I use a similar analogy using the water system to water the lawn! Maybe it can help you and others...

Voltage (Volts) is the potential to do work, even though work is not done. When off, the water faucet has "pressure", but no flow (work).The symbol E is the math representation of this potential. (V, V+, V-, Vin, Vout all represent E)

Current (Amps), using the math symbol A, is the actual work being done and represents the exchange (flow) of electrons in a certain direction and in a material where its atoms easily give up electrons. Having water flow when the faucet is turned on is the analogy to current.

Resistance (Ohms), is the opposition (resistance) to do work (A). It uses material that doesn't want to give up electrons as easily. Once water flows, the friction and size of the water pipe is the analogy. (Big wire moves more electrons than small wire. Big wire feeding the house, smaller wire to each house circuit.)

Ohm's law E=IR where E in volts, I in amps, R in Ohms, is the relationship between potential to do work, the work being done, and the resistance to do work. If E goes up, I or R must go up. R is often fixed (resistor), so in that instance I has to go up. In power supplies E doesn't change (much), so if R goes down (bigger water pipe, less resistance), I has to go up. (also R=E/I, I=E/R)

For further study if you desire...

Analog (AC) signals vary over time and require an additional consideration when it comes to resistance and it's called "impedance" or "reactance" (also in OHMs). Reactance describes how resistance to electron flow (R) occurs in analog circuits and with how fast E and I change (frequency). Using the water system analogy, how fast water flows in one direction, then another. Coils (inductors - L symbol for inductance) oppose changes in current (A) and capacitors (C symbol for capacitance) oppose changes in voltage (E). Interestingly because of this, the highest voltage of the analog signal may not be when (in time) the current reaches it's highest value. This is commonly used in RF (radio frequency) design. Checkout ELI and ICE in your searches on electronic theory.

arao23
Posts: 30
Joined: Tue Dec 13, 2016 4:44 pm

Re: The analog input parameters for GPIO pins

Postby arao23 » Sun Jan 08, 2017 6:48 am

Great info there. Thanks freeman :)

Who is online

Users browsing this forum: No registered users and 82 guests