Pages

Sunday, November 7, 2010

Opamp Configurations - Schmitt Trigger

This opamp configuration is derived from the simple comparator circuit: set up a reference at the non inverting and use the inverting as signal input. There is one main difference: this circuit uses feedback to move the reference point when the signal passes it.

The feedback goes from output to the non inverting input via a resistor.

This circuit's initial conditions are somewhat random, depending on noise when turned on and other similar things. For simplicity, we'll assume that the output starts full positive.

At turn on, the output is at positive, and the reference es set up using a voltage divider. With the output initially at positive, you can think of it as in parallel with the top resistor of the divider for practical purposes. If both resistors are equal, then the equivalent resistor is half the value; you can further simplify things at this point by making both top and feedback resistors twice the value of the second divider resistor, setting the reference at 0v (assuming the second resistor is connected to the negative rail).

The reference is now set at 0v, with the input starting lower than that, the output remains positive. When the input goes just a bit higher than the reference, the output will swing to full negative by action of the high internal gain.

With the output now negative, the output resistor is now virtually connected to the negative rail, so the parallel combination is now on the lower resistor. Using the parallel resistor formula, you can get the equivalent resistor.
    Rt = R1R2/(R1+R2)
With R2 twice that of R1, we get
    Rt = 2R^2/(3R) => Rt = 2R/3
With these values now we can calculate the voltage at the reference
    Vref = (Vcc+Vee)Rt / (2R + Rt)
where 2R is the top resistor of twice the value of the original lower resistor. Substituting Rt.
    Vref = ((Vcc+Vee)2R/3) / (2R + 2R/3)
Some algebraic manupulation.
    Vref = (Vcc+Vee)2R / 3(2R + 2R/3)
    Vref = (Vcc+Vee)2R / (6R + 2R)
    Vref = (Vcc+Vee)2R / 8R
    Vref = (1/4)(Vcc+Vee)
This Vref is by measuring from the non inverting terminal to Vee, we need to change this to be from the non inverting to ground; we know that ground is at the half position between  Vcc and Vee, so the 1/4 is actually 1/2 of Vee.

As you can see, Vref as moved towards the negative supply, so if any noise at the point where the signal crosses the initial reference drives it momentarily down, the output will not swing again at that point because the new reference is lower than what a typical noise will make the signal move.

When the signal goes down all the way to 1/2 of Vee, then the output will swing to positive, driving the reference voltage up along with it, so the switching action only occurs once even if the signal wiggles near the transition point.

This property is called hysteresis, and is useful in many applications where noise becomes a problem, specially in digital systems where excessive switching from noise can mess up the logic.

Opamp Configurations - Window comparator

The simple comparator circuit has one inherent problem: it can only tell us if one of the input voltages is higher than the other.

But what if you needed a circuit that tells us if a signal is within a range of values? you would need a circuit that tells you if the signal is higher than a minimum and if it also is lower than the maximum. The problem itself hints at the solution.

For a window comparator, we need one simple comparator set up just like the previous circuit: use the non inverting as reference and the inverting input as the signal entry. This comparator will set the maximum; if the signal goes higher than the reference the output will go negative, signaling an out of range (if we consider positive to be in range).

Another comparator is set by switching the reference and signal inputs, connecting the reference to the inverting input and the signal to the non inverting. If the signal is lower than the reference, the output will go negative, again indicating an out of range; this comparator sets the minimum.

When both opamp outputs go positive, it means that the signal is below the maximum and above the minimum, in other words, the signal is within the window of voltages you have defined.

There's one thing to consider with this configuration, when the signal is out of range, one of the opamps will go full negative (virtual connection to negative supply) and the other will be full positive (virtual connection to positive supply). This causes a short circuit condition that needs to be avoided as it could cause damage to the circuit or the supplies.

One way to protect from this cnndition is use diodes configured as the logic AND gate. This simply means to connect two diodes at the opamp outputs, connect both their anodes together and to the positive supply via a high value resistor.

What this does is that only when both opamps are at full positive (diodes' conduction blocked, basically disconnecting the opamps from the rest of the circuit) will the output be positive, held by the high value resistor.

When either opamp goes negative, the diode connected to it will be forward biased, basically connecting the output to ground; the other opamp is blocked from connecting to the output by the reverse biased diode (positive opamp output connected to cathode, negative to anode) and no short circuit condition occurs.

Opamp Configurations - Comparator circuit

One of the main reasons for using opamps as active devices in circuits is that their internal gain is so high, that even if we reduce it to a tiny fraction, it will still be enough for practical purposes. This particular configuration depends on the very high gain of the opamp to swing the output to one of the extremes; the sign of which tells us which input is more positive than the other.

By connecting the non inverting input to a voltage source, we are setting the reference point of the comparator. Remember that since there's no feedback, and because internally the opamp is just a very high gain difference amplifier, the output will be the non inverting input voltage minus the inverting input voltage, multiplied by the internal gain (in the 100k's).

This means that a difference of just millivolts will drive the output into saturation; if the difference is positive it will swing to full positive, limited by the supply. If the difference is negative, it will swing to full negative, again limited only by the supply.

On most amplifier circuits it is not advisable to drive the opamp into saturation because it clips the signal from going any further on both ends, but in this case we are not so much interested in the signal itself but on the relationship between the signal and a reference, so this circuit serves its purpose.

Opamp Configurations - Differentiator

The inverse function to integration is differentiation, in other words finding the derivative, which the opamp can also perform. The derivative is defined as the rate at which the function changes.

By using an input capacitor instead of a resistor, we can accomplish the same thing. If you remember, a capacitor stores charges in its plates, when one of them starts accumulating charges, the same charges will be pushed out from the other plate, as if current was flowing through the capacitor despite the intrinsic insulating layer.

The capacitor's charges start building up and creating a voltage across itself in opposition to the charging voltage, thus slowing down the incoming charges, slowing down the charging process in general. When enough charges have accumulated, the charges inside the capacitor completely push away the charges coming from the source, no more charges enter the capacitor, and because of this no more charges are pushed out on the other side of the capacitor, so no more apparent flow of current across the capacitor.

When used as input for a signal, if the signal does not change (like a DC input), the capacitor will have an initial apparent current through it as the voltage across it builds up due to incoming charges, and since the input of the amplifier tries to not draw any current, it will create a voltage at its output so that the current through the feedback resistor is the same as the apparent current through the capacitor.

Since the capacitor charges very quickly due to the voltage applied to it and the fact that there's no current limiting component like a resistor, the apparent current through the capacitor falls very quickly as the voltage across it in opposition rises as quickly; the falling current is also causes the opamp to drive the output voltage less, since there's less current to compensate for.

Applying a DC input to the differentiator thus creates a spike in input as well as in output as the capacitor's initial charge is developed, and then goes back to 0v as there's no more apparent current to compensate for; Similar to the operation of finding a constant's derivative, which is always 0.

The fact that there's an initial spike can be mathematically modeled as a period in which there's a function that rises at a very high rate (which actually happens, the voltage doesn't just jump from 0v to the DC input voltage, it rises very rapidly towards it), so its rate of change is very high for a brief period of time; hence the spike.

As the input voltage stabilizes, its rate of change slows down very rapidly as well, going towards zero when fully stabilized; this is reflected in the opamp's output by the fact that as the voltage stabilizes, the output spike goes down very rapidly towards zero and stays there.

Now instead of applying a constant input, you can replace it with a constantly changing input.

If the input is increasing at a constant rate, there will be a constant apparent flow of current through the capacitor, since the voltage buildup across the capacitor is compensated by the increase in input signal. Since there's a constant apparent flow of current through the capacitor, the opamp compensated by setting the output voltage at a level that will make the feedback resistor draw the same amount of current, so that the opamp input does not draw it.

Since the amount of apparent current is constant, a constant output voltage is enough to keep the feedback resistor drawing the current, and the opamp keeps a constant output at the output.

This mode is very similar to using a resistor with constant dc as the input.

The same is true for a constantly decreasing input voltage; the output will just be of reversed polarity. To compare with the mathematical definition of the derivative of a linear variable, the derivative will be a constant.

This can be expanded to other functions, one of the most widely used being the sine function. Since the mathematical derivative of the sin(x) function is cos(x), which is a shifted version of sin(x) by 90 degrees, when you input a sine input at the differentiator amplifier, the output will be the same function shifted 90 degrees, in essence, a cosine function.

Opamp Configurations - Integrator

If you replace the feedback resistor with a capacitor, you get an integrating amplifier.

In math, an integration operation is basically the area under a curve. If we have a voltage vs time graph, and the voltage remains constant, the integral of that will be the voltage times the time it stays at that level. As you can see, the longer the time the voltage remains constant, the higher the integral will be.

Back to our integrator, as the input voltage is applied to the inverting input via an input resistor that creates an input current. The Opamp will try to compensate the current by creating a voltage across the feedback element enough to make a current flow equal to that at the input to conform to the current rule: the inputs draw virtually no current.

In the simple inverting amplifier, the feedback resistor developed a constant current at a constant voltage at the output with respect to the inverting input, tied to ground. This time however, the feedback element is a capacitor; an element that can store charge, charge that eventually develops a voltage across it as it gets more and more charged.

If we apply a constant voltage at the input, a current flows through the input resistor. This current the opamp tries to compensate by creating a voltage at the capacitor to induce a current equal to that of the input. If the capacitor is initially completely discharged, the voltage across it is 0v, and its "resistance" is infinite since it is effectively insulating both sides so no current flows.

The gain is initially infinite, since Rfb/Rin tends to infinity by action of Rfb being infinity. This makes the output voltage go down quickly in a small amount of time (remember that the opamp is acting in an inverting configuration). As the capacitor starts charging, the charges entering the out plate of the capacitor push the charges on the other side, effectively creating a current across the capacitor, enough to counteract the input current.

As the charges build up inside the capacitor, a voltage develops across it in opposition of the output voltage, making it seem as if less voltage is applied to it, slowing down the amount of charges getting into the capacitor.

Less new charges going into the capacitor causes less charges being pushed out at the other plate. The Opamp tries to compensate by further lowering the voltage.

As you can see, the charges keep building up and the opamp is always trying to compensate by lowering the output voltage. At one point, the opamp will not be able to lower the output voltage, at which point it is said to be saturated.

The rate of charge of the capacitor depends on the current that is applied to it, and the current depends on the voltage and resistor at the input by ohms law I = V/R. The higher the voltage, the faster the capacitor charges and the output going lower, and the lower the input resistor the more current flows, charging the capacitor faster and resulting in the same faster lower output.

This action is the same as in the integration operation: the higher the value of the graph the higher the integral will be in the same amount of time.

Also if the input goes negative, the capacitor starts discharging and the output will go higher to compensate. If at any point the input goes to 0, the current through the input resistor will be zero, and the opamp will compensate by setting the output voltage at the same level as the capacitor voltage, in order to stop it from being charged or discharged.

Similar to what happens in an integration: if the graph crosses 0 and stays there, the integral will be the sum of areas up until that point and stay there for as long as the graph stays at zero. Also, if the graph goes lower than 0 then the integral will go lower because the area will be negative relative to 0.

Opamp Configurations - Summing Amplifier

Let's go back to the inverting amplifier. In its original form, we had one input resistance, one feedback resistance and one input voltage; but what happens if we have two or more inputs?

The math goes like this:
    Vrin1 = Vin1 - Vinv
The inverting terminal is at the same potential as the non inverting, which is tied to ground, so:
    Vrin1 = Vin1
Then separate Vrin into current times voltage, according to ohm's law:
    IinRin1 = Vin1 => Iin1 = Vin1/Rin1
But then again, we have more than one input, so for any Nth input, we have
    IinRinNth = VinNth => IinNth = VinNth/RinNth
And the voltage at the feedback resistor, same as before
    Vfb = Vinv - Vout
Separate by ohm's law
    IfbRfb = Vinv - Vout
    Ifb = (Vinv - Vout)/Rfb
Since the inputs try to draw no current, the current through the feedback resistor must be equal to the sum of the currents through each input resistor, by kirchoff's laws.
    Ifb = Iin1 + Iin2 + ... + IinNth
In terms of the voltages and resistances
    (Vinv - Vout)/Rfb = Vin1/Rin1 + Vin2/Rin2 + ... + VinNth/RinNth
Let's simplify to just two inputs, this can be expanded to more if needed; the equation holds true for more inputs.
    (Vinv - Vout)/Rfb = Vin1/Rin1 + Vin2/Rin2
Since we are interested in the output voltage, the equation is solved for it
    Vinv - Vout = (Vin1/Rin1 + Vin2/Rin2) Rfb
    - Vout = (Vin1/Rin1 + Vin2/Rin2) Rfb - Vinv
    (-1)(- Vout) = [-1][(Vin1/Rin1 + Vin2/Rin2) Rfb - Vinv]
    Vout = -(Vin1/Rin1 + Vin2/Rin2) Rfb + Vinv
    Vout = Vinv - (Vin1/Rin1 + Vin2/Rin2) Rfb
The voltage at the inverting input will be the same as the voltage at the non inverting, which is tied to ground, so this becomes
    Vout = - (Vin1/Rin1 + Vin2/Rin2) Rfb
If we assume equal resistors
    Vout = - (Vin1/R + Vin2/R) R
    Vout = - (Vin1 + Vin2) (R/R)
    Vout = - (Vin1 + Vin2) (1)
    Vout = - (Vin1 + Vin2)
Notice how the output is the inverse of the sum of the voltages. This happens because we are using an inverting amplifier base, so as expected the output is inverted. Also note that the ratio of input and feedback resistors also set the gain by multiplying the sum by the ratio of resistances; if all input resistances are the same the gain is controlled by the feedback resistor.

Another variation of this circuit is using different input resistors for each input voltage, thus creating a weighted sum, useful in some very simple digital to analog conversion circuits.

Opamp Configurations - Difference Amplifier

Difference Amplifier

So far you've learned about how to make an opamp add an inverted (negative) voltage to a reference, and to add a positive voltage by setting the reference.

Since the opamp has two inputs, one inverting and one non inverting, it should be possible to use both at the same time to add them to one another, and since one will be inverted, the effect will be a difference of voltages.

This one is a bit trickier to derive equations for, since, as you already know, the voltage that will be applied to the non inverting input will also appear at the inverting input via the opamp trying to compensate.

Since we are using resistor ratios in the voltage divider to set the voltage at the non inverting input, the voltage at the inverting one will be in terms of those resistors as well, otherwise the equations are derived the same as for the inverting amplifier.

Lets start with the inverting amplifier equations
    Vrin = Vin - Vinv
    IinRin = Vin - Vinv => Iin = (Vin - Vinv)/Rin
Same as last time, except Vinv is non zero, set by the voltage divider. Applying the current rule:
    Iin = Ifb, Ifb is the feedback current.
    Ifb = (Vinv - Vout)/Rfb
Vinv is not tied to ground, so it can't be simplified more at this point. We also have
    Iin = Ifb => (Vin - Vinv)/Rin = (Vinv - Vout)/Rfb
Expressed in terms of Vout, this becomes
    (Vin - Vinv) (Rfb/Rin) = Vinv - Vout
    (Vin - Vinv) (Rfb/Rin) - Vinv = - Vout
Multiply both sides by -1
    (-1)[(Vin - Vinv) (Rfb/Rin) - Vinv] = (-1)(- Vout)
    - (Vin - Vinv) (Rfb/Rin) + Vinv = Vout
    Vinv - (Vin - Vinv) (Rfb/Rin) = Vout
Now, since Vinv is in terms of the non inverting voltage, we have
    Vninv = Vin2 R2 / (R1+R2)
And
    Vinv  = Vninv => Vinv = Vin2 R2 / (R1+R2)
So we can rewrite our Vout equation now in terms of both input voltages
    Vinv - (Vin - Vinv) (Rfb/Rin) = Vout
    [Vin2 R2 / (R1+R2)] - (Vin - [Vin2 R2 / (R1+R2)]) [Rfb/Rin] = Vout
This seems complicated enough as it is, so from here we are going to simplify by making some assumptions. Lets make all resistors equal.
    R = R1 = R2 = Rfb = Rin
The equation then becomes
    [Vin2 R/2R] - (Vin - [Vin2 R/2R] [R/R] = Vout
    Vin2 (1/2) - (Vin - [Vin2 (1/2)] [ 1/1 ] = Vout
    Vin2 (1/2) - (Vin - [Vin2 (1/2)] = Vout
    Vin2 (1/2) - (Vin - [Vin2 (1/2)] = Vout
    Vin2 (1/2) - Vin + Vin2 (1/2) = Vout
    Vin2 - Vin = Vout
As you can see, with our assumption of equal resistors, the output will be equal to the difference of voltages applied, the applied at the non inverting minus the one applied at the inverting. In practice if you use the same ratios of resistors, the relation holds. You could also use equal ratios (not precisely 1:1) to set the gain; if you use different ratios you will get a weighted difference.