# Opamp bias currents

Ideal opamps have no current flowing into their inputs. This is not true for real world opamps. The input impedance for these is in the order of Mohm to Tohm (tera-ohms). The current flowing into the opamp will offset the voltages on it's inputs. Usually these currents are in the nA range but that depends on the temperature a lot. If your circuit is going haywire when it heats up and you don't have these biasing resistors, then this is probably the cause.

I didn't find a good derivation of the formulas for biasing resistors. All appnotes just give the ready answer. So here they are.

## Inverting amplifier

The above schematic shows the inverting opamp. In and Ip are current sources which symbolize the opamp bias currents. In this case any current flowing into the negative input (In) will offset the voltage on it. We will assume that the current In is the same as Ip (we model this opamp's input impedance as an impedance Rd between the input terminals). We have to find the value of R3 so that the current In = Ip will offset the positive input by the same value. This way the voltage difference between the terminals is net zero and the error caused by the bias currents is minimized.

Uwe == Uin is the input voltage, Uwy == Uout is the output voltage.

First we have to find the relation between the currents. From KCL:

```I1 + I2 = In  ->  I1 = In - I2
```

Now for the opamp output voltage:

```Uout = Ud * A  -> Ud = Uout/A
```

Then we find Ud, the voltage between the opamp inputs. For that we use the superposition principle. It's simple - for each voltage we treat all other sources as zero (Current sources give no currents, voltage sources are clamped to ground). We work out the formula for the value that interests us. Then we sum all the formulas. As an example let's calculate Ud.

First we zero all voltages except Uout, and find Ud:

```Ud = Uout * R2/(R1+R2)
```

Then, zero all sources except Uin and find Ud:

```Ud = Uin * R1/(R1+R2)
```

Then, zero all sources except In and find Ud:

```Ud = In * R1R2/(R1+R2)
```

Similarly for Ip

```Ud = - IpR3
```

This formula has a negative sign because the higher Ip, the smaller Ud.

Now we have to sum all these terms above:

```Ud = Uout * R2/(R1+R2) + Uin * R1/(R1+R2) + In * R1R2/(R1+R2) - IpR3
```

Substitute Ud and reorganize the equation:

```-Uout/A - Uout R2/(R1+R2) = Uin R1/(R1+R2) + In R1R2/(R1+R2) - IpR3
-Uout(1/A + R2/(R1+R2)) = Uin R1/(R1+R2) + In R1R2/(R1+R2) - IpR3
```

We want our opamp to output 0V when the input is 0V. Therefore we assume these values for Uin and Uout and see how the math works out:

```Uin = 0, Uout = 0  -> 0 = In R1R2/(R1+R2) - IpR3
```

At the beginning we assumed that In is practically the same as Ip. Therefore we can cancel them out

```In ~= Ip
R3 = R1R2/(R1+R2)
```

This is the value of R3 we are looking for.

## Noninverting amplifier

The non-inverting opamp is depicted on the schematic above. In a similar fashion we depict the bias currents as current sources to ground. The input impedance of the opamp is modeled as an impedance Rd.

In a similar way we start our derivation from the basic opamp equation:

```Uout = A * Ud  ->  Ud = Uout / A
Ud = Up - Un
```

Where Up is voltage at (+) and Um is voltage at (-). We can now express the voltage Un from the superposition principle, in that circuit there is only two sources: Uin and Ip. The Uin term is simply

```Up = Uin
```

This is because when considering the Uin term, we zero the Ip source. The Ip term is:

```Up = Ip*R3
```

Summing these two terms we arrive at Up expression:

```Up = Uin + IpR3
```

Now for the Un calculation. Here we also have just two sources, Uout and In:

```Un = Uout * R1/(R1+R2) + In * R1R2/(R1+R2)
```

Then we substitute Up and Un into Ud expression:

```Ud = Uout/A = Uin + IpR3 - Uout * R1/(R1+R2) - In * R1R2/(R1+R2)
```

We could reorder the expression to have Uout terms on the left hand side, but there is no need as we're going to get rid of them anyway the same way like for the inverting amplifier. We want to pick R3 so that the output voltage is zero when the input voltage is zero. Therefore we just assume that is the case and see how the math works out:

```Uin = 0,  Uout = 0
0 = IpR3 - In R1R2/(R1+R2)
IpR3 = In R1R2/(R1+R2)
```

Similarly to the previous case we assume that In ~= Ip, because that is how we model the opamp input impedance:

```R3 = R1R2/(R1+R2)
```

Which means that R3, again, should be the same as values of R1 and R2 in paralell.