How to Measure Negative Voltage with an ADC.
As you know, many modern microcontrollers have a built-in multi-channel ADC; as a rule, there is physically only one ADC , and the multiple channels are provided by multiplexing. The voltage range the ADC can work with is determined by the reference voltage levels (+VREF and -VREF), which must not go beyond the microcontroller's supply range. The microcontroller's supply voltage range can be from 0 to 3.3 or from 0 to 5 volts. From this it's clear that the ADC can't measure negative voltages, which is sometimes necessary.
There are several ways to measure negative voltages with an ADC; in all the examples we'll assume that -VREF = 0 and +VREF = 5 volts.
We need to measure only negative voltages, for example from -5 to 0.
In this case you can use an inverting amplifier built on an operational amplifier (op-amp) with a gain of -1.

When -1 volt arrives at the circuit input, +1 volt will go to the ADC input. If the signal we want to measure needs to be amplified, it's enough to change the values of resistors R1 and R2.
We need to measure only negative voltages, for example from -15 to 0.
In this case you can use a summing amplifier built on an op-amp

The values of resistors R1 and R2 are calculated as follows: when Vin = -15 volts, the total voltage drop across resistors R1 and R2 is 20 volts. In this case the non-inverting input of the op-amp should be at 0 volts, so it becomes clear that 5 volts will drop across R1 and 15 volts across R2, which means the resistor values must be in the ratio R2/R1 = 3/1. On the other hand, since the resistors are connected in series and the same current flows through them, we can write the formula.

Moving on: since the circuit has negative feedback, the voltages at the non-inverting and inverting inputs must be equal. When Vin = 0, the op-amp output will be 5 volts (in this case zero at the input is the maximum value, so the output must be the maximum value, 5 volts). At the same time, the non-inverting input of the op-amp will be at 3.75 volts, and the same 3.75 will be at the inverting input. Since the op-amp output is 5 volts and the inverting input is 3.75, it's easy to calculate the ratio of R3 to R4 (an ordinary voltage divider).

Assuming that R1 and R4 are 10K, we get
R1 = 10K
R2 = 30K
R3 = 30K
R4 = 10K
We need to measure a voltage that can vary from -10 to 10 volts.
This is very easy: we need to create an offset so that when -10 volts is applied to the circuit input, the ADC input is at 0 volts; then, when 10 volts is applied, the ADC input will be at 5 volts.
This can be implemented in several ways:
The resistor values are calculated very simply: when we apply -10 volts to the left terminal of R2, its right terminal should be at 0 volts; in this case no current flows through R3, since there is no potential difference across its ends.
The current through R2 is

The current through R1 is

Since resistors R1 and R2 are connected in series, the currents through them are equal.

Let's assume R2 is 10K; then R1 is 5K.
All that's left is to calculate R3: for this, apply 10 volts to the left terminal of R2; the right terminal should then be at 5 volts, and in this case no current flows through R1.
The current through R2 equals the current through R3, so we get

we get
R1 = 5K
R2 = 10K
R3 = 10K
The drawback of the resistor circuit is that R2 limits the current flowing into the ADC input, and any noise in the power supply will get into the ADC input. I'd like to draw attention to the fact that an ADC has a parameter called input impedance, which, as a rule, depends on the sampling rate; below is a table showing how the input impedance depends on the ADC conversion period for STM32

the signal source impedance must be lower than this value, and the series resistor R2 clearly doesn't help. In simple terms, in a short period of time the ADC must receive enough charge to work with, and a resistor connected in series with the input prevents this.
This drawback can be fixed by building a circuit with low output impedance, i.e. one that can deliver a large current.

And again an op-amp summing amplifier will help us. How the resistor values are calculated is described above, but the essence is the same: take the two extreme values of the incoming voltage; at the minimum the op-amp output should be zero, and at the maximum it should be 5 volts (don't forget that -VREF = 0 and +VREF = 5 volts). If you need to measure both positive and negative voltages, it's convenient to use half the reference voltage, i.e. 2.5 volts, as the offset.
Here is what I got in Micro-Cap; you can enlarge the picture by clicking on it.

The op-amp circuit has a low output impedance, i.e. it can deliver a large current, and it can be recalculated to measure other voltages, for example ±2.5 volts.
In the next article we'll look at a few more ways to measure negative voltage with an ADC.
There are several ways to measure negative voltages with an ADC; in all the examples we'll assume that -VREF = 0 and +VREF = 5 volts.
We need to measure only negative voltages, for example from -5 to 0.
In this case you can use an inverting amplifier built on an operational amplifier (op-amp) with a gain of -1.

When -1 volt arrives at the circuit input, +1 volt will go to the ADC input. If the signal we want to measure needs to be amplified, it's enough to change the values of resistors R1 and R2.
We need to measure only negative voltages, for example from -15 to 0.
In this case you can use a summing amplifier built on an op-amp

The values of resistors R1 and R2 are calculated as follows: when Vin = -15 volts, the total voltage drop across resistors R1 and R2 is 20 volts. In this case the non-inverting input of the op-amp should be at 0 volts, so it becomes clear that 5 volts will drop across R1 and 15 volts across R2, which means the resistor values must be in the ratio R2/R1 = 3/1. On the other hand, since the resistors are connected in series and the same current flows through them, we can write the formula.

Moving on: since the circuit has negative feedback, the voltages at the non-inverting and inverting inputs must be equal. When Vin = 0, the op-amp output will be 5 volts (in this case zero at the input is the maximum value, so the output must be the maximum value, 5 volts). At the same time, the non-inverting input of the op-amp will be at 3.75 volts, and the same 3.75 will be at the inverting input. Since the op-amp output is 5 volts and the inverting input is 3.75, it's easy to calculate the ratio of R3 to R4 (an ordinary voltage divider).

Assuming that R1 and R4 are 10K, we get
R1 = 10K
R2 = 30K
R3 = 30K
R4 = 10K
We need to measure a voltage that can vary from -10 to 10 volts.
This is very easy: we need to create an offset so that when -10 volts is applied to the circuit input, the ADC input is at 0 volts; then, when 10 volts is applied, the ADC input will be at 5 volts.
This can be implemented in several ways:
- with resistors
The resistor values are calculated very simply: when we apply -10 volts to the left terminal of R2, its right terminal should be at 0 volts; in this case no current flows through R3, since there is no potential difference across its ends.
The current through R2 is

The current through R1 is

Since resistors R1 and R2 are connected in series, the currents through them are equal.

Let's assume R2 is 10K; then R1 is 5K.
All that's left is to calculate R3: for this, apply 10 volts to the left terminal of R2; the right terminal should then be at 5 volts, and in this case no current flows through R1.
The current through R2 equals the current through R3, so we get

we get
R1 = 5K
R2 = 10K
R3 = 10K
The drawback of the resistor circuit is that R2 limits the current flowing into the ADC input, and any noise in the power supply will get into the ADC input. I'd like to draw attention to the fact that an ADC has a parameter called input impedance, which, as a rule, depends on the sampling rate; below is a table showing how the input impedance depends on the ADC conversion period for STM32

the signal source impedance must be lower than this value, and the series resistor R2 clearly doesn't help. In simple terms, in a short period of time the ADC must receive enough charge to work with, and a resistor connected in series with the input prevents this.
This drawback can be fixed by building a circuit with low output impedance, i.e. one that can deliver a large current.
- an op-amp summing amplifier

And again an op-amp summing amplifier will help us. How the resistor values are calculated is described above, but the essence is the same: take the two extreme values of the incoming voltage; at the minimum the op-amp output should be zero, and at the maximum it should be 5 volts (don't forget that -VREF = 0 and +VREF = 5 volts). If you need to measure both positive and negative voltages, it's convenient to use half the reference voltage, i.e. 2.5 volts, as the offset.
Here is what I got in Micro-Cap; you can enlarge the picture by clicking on it.

The op-amp circuit has a low output impedance, i.e. it can deliver a large current, and it can be recalculated to measure other voltages, for example ±2.5 volts.
In the next article we'll look at a few more ways to measure negative voltage with an ADC.
