TikZ for Circuits


Circuitikz provides a set of macros to type­set elec­tronic net­works. It is based on pgf and TikZ packages. Here is the syntax for basic circuits to typeset using circuitikz in LaTeX tikzpicture environment .

Despite of the beautiful pictures CircuiTikz(TikZ) generate, it is not a popular typesetting tool for circuits due to difficulty in coding them. Here I made an attempt by coding the small building blocks in a way to reuse them in building bigger circuits. I illustrated the approach followed in the following examples.

For every circuit/subcircuit, I tried to maintain uniformity in coding style. The main steps in coding a subcircuit are outlined here

  1. Define height and width of the figure using \figHt and \figWd variables
  2. Create grid while typesetting. Once done remove grid
  3. Assign the coordinates for the reference points
  4. Instantiate the components(R,L,C,MOS,BJT,etc.,)
  5. Interconnect the components
  6. Name the components, nodes, nets, etc.,
  7. Draw VDD and GND connections

To make a circuit using several subcircuits,

  1. Change the coordinates of the reference points
  2. Change the component names if required in each subcircuit to meet your circuit requirements
  3. Change VDD and GND connections in each circuit
  4. Make top level connection between different subcircuits
  5. Finally draw VDD and GND lines

For example I created a Two stage CMOS opamp from current mirror and differential pair subcircuits, where I exactly followed the above approach. I took around 15min to hook an opamp from the sub-circuits.

Current Mirror

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
\begin{tikzpicture}
%--------start graphics code --------
%Figure dimensions
\def\figHt{6};
\def\figWd{2};
%Grid for intial drawing.
%Comment next three lines once typesetting finished
\draw[step=0.5,very thin, black!20] (-0.5,-0.5) grid (\figWd,\figHt);
\foreach \x in {0,...,\figWd} {\node [anchor=north] at (\x,-0.5) {\x};}
\foreach \y in {0,...,\figHt} {\node [anchor=east] at (-0.5,\y) {\y};}
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%% NMOS current mirror %%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Assign coordinates for reference nodes
\coordinate (ref_node1) at (0.5,0);
\coordinate (ref_node1T) at ($(ref_node1)+(0,\figHt)$); 
%Instantiation of components
\draw (ref_node1) node[nmos,anchor=source,xscale=-1] (Mt1){};
\draw (ref_node1T) to [I] (Mt1.drain);
%Inter-connections
\draw (Mt1.drain) node[circ] -| (Mt1.gate);
% Numbering the components
\draw (Mt1.base) node[left]{$M_{t1}$};
%Ground and Vdd lines
\draw (Mt1.source) node[ground]{}; 
%--------end graphics code ----------
\end{tikzpicture}

Rendered by QuickLaTeX.com

 

PMOS and NMOS current mirrors

Wilson current mirror(NMOS)

Differential pair with NMOS input stage

Differential pair with PMOS input stage

LC Oscillator(NMOS)

CMOS Telescopic Amplifier

Two stage CMOS Op-amp