# Measuring negative voltage Apr 2016

The task to be tackled here is measuring voltage ranging from +N to -N Volt with an ADC input which needs to be kept in the range 0 to 3.3V.

There are numerous resources all over the web which solve this puzzle. The
focus here is to help you get some *intuition*, and not just to come up
with a solution and its “explanation”.

If this is new for you: hang in there. You’ll be surprised how logical electronics can be…

Negative voltages are everywhere - just flip the two leads of a power supply or
battery, and you’re there. That’s because “positive” and “negative” are relative
concepts, i.e. a voltage is always *between* two points. It has become common
to call one of those points “ground” - *even when it’s not actually connected to
“earth” using a conductive rod into the real ground!*

Many circuits we use are in fact floating, with no real earth connection whatsoever. Most power supplies and bricks / wall warts tend to be isolated from real
ground, even when the AC mains receptacle includes a true ground pin. It’s much
safer that way - when two circuits float, there won’t be a significant current when you
happen to touch both of them (actually, there is a *minute* leakage
current, which can create a slight tingle or make a metal surface feel “funny”
- but that’s totally harmless, and several orders of magnitude below the levels
which require attention).

This all changes the moment we connect equipment together via conducting wires:
from then on, we’ve established a path for electrons to flow, and everything
else starts to have a defined voltage relative to *both* connected devices.

When we use USB to power a small µC board, the USB’s power source defines a
ground level as far as all the signals go and the power it supplies. We can’t
plug in a second USB cable and touch its ground line to anything on the µC
**other** than the *same* ground level, without causing a short, and possibly
even damaging stuff.

*Ground is a great convenience, it’s the basis for power transfers and for
communication.*

Once we do have a ground, it’s quite possible for some signals or power lines
to be lower than that level, and these are then called “negative”. Note that
this is still just relative *to that ground level* we used as reference.
There’s nothing different about negative voltages, they’re just *lower!*

Back to the ADC. It doesn’t like voltages below ground, i.e. under 0V - relative
to *its* ground.

But to measure negative voltages, we can use a trick. This requires two resistors in series:

Our unknown voltage is `Vin`

, and the bottom is our common ground. If we measure
the voltage at `Vout`

(relative to that same ground), we get a smaller value.
Welcome to the voltage divider.
There is *nothing* magical about this essential building block in electronics -
here’s how it works:

- Vin causes a current to flow
*through*Z1 and then Z2 - that current is the same in both (where else could it go? see Kirchhoff’s current law)
- now assume that Z1 and Z2 are two resistors with the same value
- Ohm’s law then tells us that the voltage over Z1 and Z2 must be the same
- we know Vin, so the voltage over Z1 must be
^{1}⁄_{2}Vin, and over Z2 is must also be^{1}⁄_{2}Vin - Vout is the same as the voltage over Z2, hence Vout =
^{1}⁄_{2}Vin

We have divided the voltage Vin by two … *for any Vin* and for *any* (identical) Z1 and Z2
values.

One more example: assume Z1 is 900 Ω and Z2 is 100 Ω. The total series
resistance is therefore 1000Ω. As before, the current through Z1 also goes
through Z2, since (again) it has nowhere else to go. If `Vin`

is 1V, then the
current will be 1 mA (Ohm’s law, better get used to it!). But 1 mA over 900Ω
creates a voltage drop of 0.9V, while 1 mA over 100Ω creates a voltage drop of
0.1V.

Sure enough, the total voltage drop is 1V, same as we’re feeding to `Vin`

. But
`Vout`

is now 0.1V, one tenth of Vin - this is a 10:1 divider! Not just for 1V
in, **any** `Vin`

will end up as 1/10th on `Vout`

.

The general formula is: `Vout = (Z2/(Z1+Z2)) * Vin`

- and if you’ve been
following along, this should now be 100% obvious to you. This isn’t a dry
formula, it needs to *match* your intution!

Voltage dividers are everywhere. You will now be able to recognise them with your eyes closed.

Note that we can measure voltages well over 3.3V with this: connect the input
voltage to a suitably-dimensioned voltage divider, and connect the ADC’s input
to `Vout`

.

But what about *negative* voltages? Almost there. We just need to play a little
trick with ground levels. Instead of connecting the voltage divider’s lower end
to ground, we connect it to 3.3V:

This is still a voltage divider. It merely works the other way around:

- with
`Vin`

at 3.3V, it’s the same as the top of Z2, so all the points along the path are 3.3V - when
`Vin`

is*negative*3.3V, and Z1 and Z2 are the*same*value, then the top of Z2 is +3.3V, while the bottom of Z1 is –3.3V: you can probably intuit that`Vout`

will be midway, i.e. 0V - and if
`Vin`

is 0V, i.e. ground, then Vout will be midway 0 and 3.3V, i.e. 1.65V

What happens, is that Vin can only pull Vout down from 3.3V, and it takes 6.6V
*down* to pull Vout 3.3V under the top of this 2:1 voltage divider. Since a
`Vin`

of –3.3V is 6.6V down relative to +3.3V, and since `Vout`

then drops 3.3V
down, i.e. at half the rate it’ll end up being exactly 0V.

So the above circuit transforms a +3.3V .. –3.3V voltage swing into a +3.3V ..
0V voltage swing. *We can now deal with negative voltages at Vin, even though
the ADC’s input can’t!*

There are some fairly serious drawbacks with this circuit, but that’s for the next article…