**Introduction**

In this course, we will dive into the fundamental concepts of adding and subtracting using operational amplifiers (OpAmps). These concepts serve as the building blocks of arithmetic operations, and their understanding is essential to comprehend more advanced electrical circuits. While we have covered voltage dividers, multipliers, and inverters, which involve mathematical operations such as multiplication and division, the focus of this course will be on the basic algebraic operations of addition and subtraction. We will demonstrate how OpAmps can be employed as effective tools for implementing these operations in electrical circuits.

**Addition**

In primary school you learned to add numbers before subtraction, and we will follow the same steps here. Addition first. We want a circuit that will be able to implement the following function:

$U_{out}=a \cdot U_1 + b \cdot U_2$To make things easier to understand, let’s first take a look at how we would implement just one part of this equation,

$U_{out}=a \cdot U_1 + b \cdot U_2$One circuit that matches this equation would be an inverting amplifier.

It implements the function

$U_{out}=-\frac{R_2}{R_1} \cdot U_1$Now let’s make a thought experiment. If we added another voltage source, U2, connected to the inverting input of OpAmp through a capacitor, and U2 was at zero volts… What would happen? Output voltage wouldn’t change since inverting input is a virtual ground. But if we set U1 to 0V and U2 to something different, implemented function would be

$U_{out}=-\frac{R_2}{R_3} \cdot U_2$Did you read the previous course on superposition? If you did, you must have already guessed what direction we’re heading. Superposition. Function

$U_{out}=a \cdot U_1 + b \cdot U_2$is a textbook example of a linear combination of multiple inputs, making it suitable for solving with superposition theorem.

We have acquired knowledge on how to add two voltage sources together using operational amplifiers (OpAmps). However, it should be noted that this principle can be extended to include any number of additional voltage sources. By connecting these voltage sources, each with their respective resistor, to the inverting node of the OpAmp, the resulting function will remain consistent with expectations. This demonstrates the versatility of OpAmps and their ability to add an indefinite number of voltages.

**Subtraction**

The concept of subtraction can be boiled down to the inversion of the second operand and addition of the two operands. To achieve this in an electrical circuit, a combination of inverting and noninverting amplifiers can be employed, much like in the case of addition. However, it is worth noting that using a dedicated inverting amplifier to invert one input voltage is not the most elegant approach. Instead, we can adopt a more sophisticated solution, which involves the use of the following technique:

The U2 branch of the circuit is relatively straightforward. When U1 is set to zero, the circuit behaves similarly to a standard inverting amplifier. However, when U2 is set to zero, the analysis becomes more complex. It is essential to remember that during normal operation, the inputs of the OpAmp are at the same voltage. As a result, we get the following two equations:

$U_+=U_1 \cdot \frac{R_4}{R_3+R_4}$$U_-=U_{OUT} \frac{R_1}{R_1+R_3}$When we combine them, we get:

$U_-=U_{OUT} \frac{R_1}{R_1+R_3}$The circuit functions as a nonstandard noninverting amplifier, and while it may deviate from the standard approach, the equations derived from its analysis are still valid. By selecting components such that R1 is equal to R2, and R3 is equal to R4, we can simplify the equation to the following form:

$U_{OUT} = \frac{R_3}{R_1}(U_1-U_2 )$The circuit above is commonly known as a differential amplifier.

**Conclusion**

By combining the concepts of inverting and noninverting amplifiers, we have successfully demonstrated the implementation of all basic arithmetic operations in analog circuits. This includes addition, subtraction, multiplication, and division. The latter can be achieved either by using resistors to divide by a constant or by multiplying with an inverse number to divide by an arbitrary value. Although there also exists a circuit for arbitrary division, we will not go into further detail on this topic. I hope that you found this course engaging and informative, and that you have gained valuable knowledge and skills from it.

Written by Luka Pogačnik Edited by Andraž Pirc

This teaching material was created by Red Pitaya & Zavod 404 in the scope of the Smart4All innovation project.