Electrical – How does an MCU pin detect a voltage

currentmicrocontrollerohms-lawresistancevoltage

If I have an MCU pin connected in between 2 resistors (a voltage divider) how does the MCU pin actually detect the voltage? I am using an ATMega328 and reading the voltage from the divider by an ADC enabled pin.

I believe my understanding is broken but here is what I'm thinking…

  • the pin is floating but is set for input (has internal pull-up enabled)
  • the top resistor in the divider takes some voltage (voltage drop)
  • now, the wire that connects the middle of the voltage divider to the pin has a potential of x volts (it could potentially push by x volts)
  • BUT, no current will flow through the connecting wire to the pin as the pin isn't at ground (there is nothing to "pull" the current towards it)
  • if no current flows to the pin, how is voltage detected? If the current is 0 then according to Ohm's Law voltage would be 0 too

Best Answer

the pin is floating but is set for input (has internal pull-up enabled)

is a paradox. Either it's floating, or it's pulled up. These things are opposites. "Pull-up" means there is a resistor that connects the pin to a fixed voltage; floating means that the pin is not connected to either ground or any non-zero voltage.

For ADC pins, pull-up doesn't make sense – you don't want to measure your supply voltage, you want to measure an external voltage!

Hence, there's no resistor voltage divider.

So, let's have a look at the datasheet, p.310:

It says there, the input resistance of the ADC is 100MOhm.

So, yes: Practically no current will flow into the ADC. That's a good thing, too, because if current flows into the the ADC, then that would change the voltage on the input, thus destroying the measurability of the signal of interest.

So, the question is: How does the actual measurement take place?

Now, that is a different question, and depends on the architecture of the integrated ADC. In case of your ATMega328, you're dealing with a successive approximation ADC. Which means, that via means of an analog circuit, the voltage at the moment you measure is "buffered", saved to a capacitor, and then, a DAC's output value is changed successively until it matches the stored voltage (very rough overview). I'd like to point you to the internet on successive approximation ADCs.