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
  • \$\begingroup\$ Your question is unclear. What kind of pin? A pin connected internally to an ADC? or to a low-speed GPIO? Or to a high-speed serial link? Or to a reset line? \$\endgroup\$ – Marcus Müller Nov 21 '16 at 15:11
  • \$\begingroup\$ This will all depend on your pin's function, and on the microcontroller used. I'm afraid there's no way around reading your microcontroller's datasheet. \$\endgroup\$ – Marcus Müller Nov 21 '16 at 15:11
  • \$\begingroup\$ @MarcusMüller The pin would be one that is connected to an internal ADC. The MCU I use is an ATMega328. Sorry for being unclear but I'm very much a beginner \$\endgroup\$ – CS Student Nov 21 '16 at 15:16
  • \$\begingroup\$ That's OK, we all began somewhere. Thanks for the edit! I think this is a great question now! \$\endgroup\$ – Marcus Müller Nov 21 '16 at 15:18
  • 3
    \$\begingroup\$ So - are you really asking "how does an ADC work", or are you asking "how does an MCU interpret a voltage on a pin as a 1 or 0"? \$\endgroup\$ – brhans Nov 21 '16 at 15:29

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.

| improve this answer | |
  • \$\begingroup\$ Ah of course the ADC pin wouldn't be pulled up, that makes sense. So if the pin is floating but NOT at ground, how come a small current does flow? My understanding is that a current will flow from a higher potential to a lower potential but this may not be the case if the pin floats to a potential that is the same or more than the voltage being measured. I can see why a current would flow using Ohm's Law (we have a voltage and resistance of the ADC input) but I can't quite comprehend it in terms of flowing from a higher potential to a lower one. Thanks for the answer \$\endgroup\$ – CS Student Nov 21 '16 at 15:42
  • 1
    \$\begingroup\$ The pin is not floating. If it was floating then nothing is connected to it. If nothing is connected to it then you aren't trying to measure anything sensible and so shouldn't expect a sensible result. The pin is being driven to a defined voltage by the input source, a voltage divider in this case. To to outside world the ADC pin looks like a 100 Mohm resistor to ground. This will have a slight impact on the voltage being measured however this impact is small enough that it can normally be ignored, most of the time it will be less than the measurement noise level of the ADC. \$\endgroup\$ – Andrew Nov 21 '16 at 16:02
  • \$\begingroup\$ @Andrew Thanks Andrew that has cleared it up for me, I'm basically connecting a voltage source to a large resistor which is then connected to ground, therefore there is a potential difference between the source and ground allowing for a current to flow. The pin can't be floating as I've connected something to it! Thanks again!! \$\endgroup\$ – CS Student Nov 21 '16 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.