OK. Let me copy here what will be a new tutorial I added to the manual. You can find it on the circuitikz
page (in the PDF you'll also find a suggestion on how to re-use the shape).
Tutorial: A non-inverting op-amp amplifier
Let's now try to draw a non-inverting amplifier based on op-amps; the canonical implementation can be, for example, this one from ''electronics tutorials''.
Obviously, the style and form of drawing a circuit is often a matter of personal tastes and, maybe even more important, of the details you are focusing on; drawing a non-inverting amplifier will be different if you are drawing it to explain how it works or if you are simply using it in a more complex circuit, assuming its operation well known by the reader. Anyway, the final objective is to have a circuit like the one below, drawn so that it is easy to reuse.
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/ss6mW.png)
We have to start the drawing from a generic point. Given that the idea is to have a reusable block, instead of positioning the op-amp and build around it, we will start from the input ''pole'':
\begin{circuitikz}[]
\draw (0,0) node[above]{$v_i$} to[short, o-] ++(1,0)
node[op amp, noinv input up, anchor=+](OA){\texttt{OA1}}
;
\end{circuitikz}
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/gogex.png)
In this snippet, notice that the only absolute coordinate is the first one; that will enable us to ''copy and paste'' the circuit in several places, or create a macro for it. We position a text node above it, and then draw a wire with a pole to a relative (1,0)
coordinate: in other words, we move 1 unit to the right drawing a short-circuit, which is the same as a wire. The usage of to[short...]
simplifies the position of the pole, but notice that we could have also written:
\draw (0,0) node[above]{$v_i$} node[ocirc]{} -- ++(1,0) ...
with the same result.
The second step is to position the op-amp. We can check the manual and see the component's description:
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/jrRIp.png)
where we notice the type of the component (it is a node-type component, so we have to use
node
to position it) and the available ''anchors'': points we can use to position the shape or to connect to. Not all the anchors are explicitly printed in the description box; you should read further in the manual and you'll see a ''component anchors'' section with the relevant information.
Anyway, the op-amp must be connected with the +
anchor to our input wire, so we say anchor=+
in the option lists; this shifts the whole element so that the named anchor will lie at the current position of the path. Moreover, normally the shape has the inverting input on the bottom side, and we want it the other way around, so we use also noinv input up
in the keys defining the node. We could also have flipped the shape with yscale=-1
, but in this case, we should have considered the effects on anchors and on the text; see section mirroring and flipping in the manual.
Now we can draw the resistors; let's start with R1. We will draw it going down vertically from the -
anchor — we have named the node OA
so that will be OA.-
. We will need to connect the R2 also, so we do the following:
- draw a wire going down, and mark a point where we want the feedback resistor to connect;
- then draw R1 and finally
- draw the ground node.
\begin{circuitikz}[scale=0.8, transform shape]
\draw (0,0) node[above]{$v_i$} to[short, o-] ++(1,0)
node[op amp, noinv input up, anchor=+](OA){\texttt{OA1}}
(OA.-) -- ++(0,-1) coordinate(FB)
to[R=$R_1$] ++(0,-2) node[ground]{}
;
\end{circuitikz}
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/Uf12A.png)
We only miss the feedback resistor now. We will use orthogonal coordinates, writing:
\draw (FB) to[R=$R_2$] (FB -| OA.out) -- (OA.out);
The meaning is the following:
- move the current point to the coordinate named
FB
;
- put a resistor, with label R2, from here to...
- the coordinates which is on the horizontal of
FB
and on the vertical of OA.out
: the -|
coordinate operation is quite mnemonic;
- the continue drawing to
OA.out
.
You can use a separate \draw
command or just continue the path you were writing; the choice is just personal preference, but be warned that it can affect the drawing of poles (see section ''poles (also called nodes)'' in the manual about this if you notice strange things).
Finally, we add the output and a couple of poles:
\begin{circuitikz}[scale=0.8, transform shape]
\draw (0,0) node[above]{$v_i$} to[short, o-] ++(1,0)
node[op amp, noinv input up, anchor=+](OA){\texttt{OA1}}
(OA.-) -- ++(0,-1) coordinate(FB)
to[R=$R_1$] ++(0,-2) node[ground]{}
(FB) to[R=$R_2$, *-] (FB -| OA.out) -- (OA.out)
to [short, *-o] ++(1,0) node[above]{$v_o$}
;
\end{circuitikz}
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/GdXmP.png)
The last step to obtain the final look is to add a bit of styling. We want the op-amp filled with a light cyan color, and we prefer to have the label aligned with the left side of the device:
\ctikzset{amplifiers/fill=cyan!20, component text=left}
\begin{circuitikz}[scale=0.8, transform shape]
\draw (0,0) node[above]{$v_i$} to[short, o-] ++(1,0)
node[op amp, noinv input up, anchor=+](OA){\texttt{OA1}}
(OA.-) -- ++(0,-1) coordinate(FB)
to[R=$R_1$] ++(0,-2) node[ground]{}
(FB) to[R=$R_2$, *-] (FB -| OA.out) -- (OA.out)
to [short, *-o] ++(1,0) node[above]{$v_o$}
;
\end{circuitikz}
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/5lR5Z.png)
The \ctikzset
command choosing the style is better placed in the preamble, though. Style should be coherent for all the document body, so avoiding stating it for every circuit is normally the best strategy.
circuitikz
manual...