Op-amp basics: calculating with the virtual short
An op-amp with feedback moves its output until the two input voltages are equal. That one line is enough to calculate inverting and non-inverting amplifiers.
Two rules
An ideal op-amp with feedback:
- No current flows into the input terminals
- The voltages at the two input terminals become equal (the virtual short)
Non-inverting amplifier
With the input on the + terminal, R2 from the output to the − terminal and R1 from the − terminal to ground:
Vout = Vin × (1 + R2/R1)
R1 = 1 kΩ, R2 = 9 kΩ → a gain of 10. The input impedance is very high, so it takes a sensor signal without loading it. With R2 at 0 it becomes a voltage follower (buffer) with a gain of 1.
Inverting amplifier
Vout = -Vin × (R2/R1). The sign is inverted and the input impedance is R1.
Limits of a real op-amp
| Specification | Meaning | Effect |
|---|---|---|
| Rail-to-rail input/output | Can it work right up to the supply rails? | Important in single-supply 3.3 V circuits |
| Offset voltage | The error with zero input | Multiplied by the gain when amplifying small signals |
| GBW | Gain × bandwidth | At a gain of 100 the bandwidth is GBW/100 |
| Slew rate | The fastest the output can change | Following fast PWM current waveforms |
Remember just two rules
An op-amp circuit with negative feedback is calculated with two rules.
- No current flows into the inputs.
- The output moves until the two inputs are at the same voltage. (the virtual short)
Three basic circuits
| Circuit | Gain | Input resistance | Use |
|---|---|---|---|
| Buffer (voltage follower) | 1 | Very high | After a divider, in front of an ADC |
| Non-inverting amplifier | 1 + Rf / Rg | Very high | Enlarging sensor signals |
| Inverting amplifier | −Rf / Rin | Rin | Summing signals, flipping the sign |
In a non-inverting amplifier, Rf = 90 kΩ, Rg = 10 kΩ gives a gain of 10. A 0.1 V signal becomes 1.0 V.
Example: measuring current with a shunt
5 A through a 10 mΩ shunt produces 50 mV. To measure it with a 3.3 V ADC, a gain of about 50 is right.
gain 50 → 2.5 V at 5 A
1 ADC LSB (0.8 mV) → 0.8 mV / 50 / 0.01 Ω = 1.6 mA resolution
If you need to measure current in both directions, raise the middle of the output to 1.65 V and read anything above it as forward and anything below as reverse.
RoadmapSee where this note sits in Electronic Circuits→What to check on a single supply
Most MCU circuits have only a single 3.3 V supply. Look at two things.
- Input range: does it work with the input down near 0 V? With the shunt on the ground side, the input is almost 0 V.
- Output range: does the output reach close to 0 V and to the supply voltage? An ordinary op-amp falls more than 1 V short at both ends.
A rail-to-rail input/output op-amp meets both conditions. Even then the output only goes down to a few tens of mV above 0 V, so values near 0 A may not be accurate.
Values to look for in the datasheet
| Item | Meaning | Effect |
|---|---|---|
| Input offset voltage | The error even with equal inputs | Appears at the output multiplied by the gain |
| Gain-bandwidth product (GBW) | Gain × usable frequency | GBW 1 MHz at a gain of 50 is good to about 20 kHz |
| Slew rate | The fastest the output can change | Fast step signals become slanted |
| Input bias current | Current leaking into the inputs | An error when it meets large resistors |
Amplify by 50 with an op-amp whose offset is 1 mV and 50 mV rides on the output. In current terms that is 100 mA, so for current measurement choose a low-offset part, or measure the value at 0 A at start-up and subtract it.
Why it should not be used as a comparator
Use an op-amp to compare two voltages without feedback and the output takes time to come out of saturation, and it chatters when the inputs are close. Where a fast decision is needed, such as overcurrent protection, use a dedicated comparator and give it hysteresis so it does not chatter at the threshold.
Problems that come up in practice
- No decoupling capacitor next to the power pin, causing oscillation
- A large capacitor directly on the output, causing oscillation (isolate it with a small series resistor)
- The amplified signal hits the supply rail and clips (recalculate gain and input range)
- Unused op-amp inputs left floating (wire it as a buffer tied to a mid-rail voltage)