# Analog Computation

Younger hobbyists who want to do arithmetic in an electronics application may think that a microcontroller is the only way to do it. I present something far more old-school.

If you can represent the scalar terms of an arithmetic expression as voltages and/or resistances, then many operations can be performed with op amps (which is, incidentally, what the “op” part means). Several of the major features are described above.

- The word “amp”, for
**amplifier**, refers to the fact that the device amplifies, or enlarges, an input signal by a factor called**gain**which is represented by the letter`A`^{[1]}When`A`is fixed, the amplifier serves to multiply the input signal by`A`. By default,`A`is ideally infinite^{[2]}, but can be set to a fixed value using resistors. - Division (not pictured) can be performed using a resistor divider network. No op amp is required, though using one might be desirable to avoid loading effects.
- “Subtract then multiply by
`A`> 0″: An op amp’s natural mode (in my opinion, anyway) is the**differential amplifier**. Two voltages are input;`V`is subtracted from_{2}`V`, and then the difference is multiplied by_{1}`A`, which is based on the ratios of resistors used. All other linear modes pictured can be described in terms of this one: - “Multiply by
`A`>= 1″: If you take the divider off of`V`and replace it with_{2}`V`, it’s equivalent to setting_{in}`V`to_{2}`V`(1 +_{in}`R`/_{in}`R`). Then, just set_{F}`V`to 0. The result is_{1}`A`(`V`–_{2}`V`) = (_{1}`R`/_{F}`R`)_{in}`V`(1 +_{in}`R`/_{in}`R`) =_{F}`V`(1 +_{in}`R`/_{F}`R`)._{in} - “Multiply by
`A`< 0″: Let`V`= 0,_{2}`V`=_{1}`V`. The result is_{in}`A`(`V`–_{2}`V`) = (_{1}`R`/_{F}`R`)(0 –_{in}`V`) =_{in}`V`(-_{in}`R`/_{F}`R`)._{in} - “Add then multiply by
`A`< 0″: Exactly the same as the previous case, except that the input is from a resistor divider network. If`V`and_{1}`V`are fed to the same point through equal resistances as shown, it’s equivalent to a single input of_{2}`V`= (_{X}`V`+_{1}`V`)/2 through a resistance of_{2}`R`=_{X}`R`/2. With the other input at 0, the result is_{in}`A`(0 –`V`) = (_{X}`R`/_{F}`R`)(-_{X}`V`) = -(2_{X}`R`/_{F}`R`)((_{in}`V`+_{1}`V`)/2) = -(_{2}`R`/_{F}`R`)(_{in}`V`+_{1}`V`)._{2} - “Logarithmic” and “Exponential”: An NPN transistor with a grounded base can be placed either at the feedback or the input to implement a logarithmic or exponential output, respectively. The coefficients of the expression are not well defined, since they vary from instance to instance, but if the transistors used are closely matched and thermally linked (for example, in a single-chip transistor array) then with some tuning their outputs will be consistent. A log transform can be used to easily multiply (by adding logarithms) or divide (by subtracting logarithms) two voltages.
- Comparison (not pictured): As discussed here previously, a comparator is a sort of op amp specialized to output only logical high/low depending on whether the value at the non-inverting input is higher than the value of the inverting input, outputting high and low, respectively. In a pinch, an op amp will do the same thing in the
**open-loop**configuration—direct inputs and no feedback, resulting in the extremely high gain mentioned earlier. If the non-inverting input is even slightly different than the inverting input, that small difference is amplified so immensely that the output will be either the highest possible or the lowest possible, meaning around the positive and negative supply voltages, respectively. Use of an actual comparator is preferred though, since it is better tuned for digital use.