# Draw a dc-dc boost converter in LaTeX using CircuitikZ

PV panel connected to a dc dc boost converter supplying a resistive load

Hi guys!

Today's tutorial is about drawing a photovoltaic system, which consists of a solar panel, a dc-dc boost converter and a load. We will use TikZ for the PV module and CircuiTikZ for the rest of the circuit.

At the end of this tutorial, you will be able to:

2. draw basic electrical components (as a node or along path);
3. change components size;
4. use short and open options, to draw different operation modes of the circuit.

Please check the post how to draw a dc-dc buck converter as it includes more details. Let's get into the details!

## 1. PV Module

Despite the fact that we can draw the photovoltaic (PV) module in TikZ, we will not consider it in this tutorial. For that, we would like to use an external image that represent the PV module.

### 1.1 Add an Image in TikZ

The previous post was about annotating an image in LaTeX and It is relevant to this part. So, to add an external image in TikZ, we use \includegraphics inside a \node command as follows:

\documentclass{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}

% PV module "node image"
\node
[draw,
thick,
outer sep=0pt]
(panel) at (0,0) {\includegraphics[width=2.5cm]{PV-module}};

\end{tikzpicture}

\end{document}


PV-module

The above LaTeX code creates a node (named panel) at the point with coordinates (0,0). The node content is an image with a width of 2.5cm which is added by the famous command \includegraphics[option]{imageName}.

The node has a set of options which are:

• $\verb|draw|$: This option allows us to draw the shape of the node which, by default, corresponds to a rectangle.
• $\verb|thick|$: The line stroke is chosen \verb|thick|thick which corresponds to a line width of 0.4pt.
• $\verb|outer sep=0pt|$: This option adds an invisible separation space between the rectangle and anchors of the node. The latter are used for positioning which will be discussed in the next subsection.

Remark: the white space between the image and the node border is named inner separation and can be controlled by the option $\verb|[inner sep=]|$

### 1.2 Node anchors

Each node shape has predefined anchors which can be accessed through the node name. For example, $\verb|(panel.east)|$ is the coordinates of the point located at the east of the image. $\verb|(panel.140)|$ represents the coordinates of the point with angle 140 degrees (from the center of the image and with respect to the horizontal line) and located at the border of the node. Check the following illustrations:

[outer sep=0pt]

[outer sep=5pt]

As you can remark, the main effect of the outer sep option is that all anchors are pushed to the outside with a given value (5pt in the previous image).

## 2. DC-DC boost converter in CircuiTikZ

Let's start from the point with coordinates (panel.53). We draw a straight line of 2cm length with a current arrow. Here is the LaTeX code:

 \draw (panel.53) to [short,i=$i_{pv}$] ++(2,0) coordinate(a1);


CircuiTikZ provides the option $\verb|to[short,i=i_{pv}]|$ which draws a straight line with an arrow at the middle used to highlight the current direction and its label. we saved the end point of the line using $\verb|coordinate(a1)|$, which will be used later to draw the vertical capacitor.

### 2.1 Draw an inductor

Then from the point (a1) we draw an inductor (with label L ) to a point 3.5cm far from (a1) using relative coordinates ++(3.5,0). The end point is saved using $\verb|coordinate(b1)|$ which will be used later to draw the vertical switch. Here is the corresponding code:

 \draw (a1) to[cute inductor,l=$L$] ++(3.5,0) coordinate(b1);


### 2.2 Draw a diode

From the point (b1), we draw a diode with 2.5cm length using the option $\verb|D*|$ and with label (D) using the option using the option $\verb|l=D|$. The end point is saved as (c1):

 \draw (b1) to[D*,l=$D$] ++(2.5,0) coordinate(c1);


### 2.3 Draw a line with a current arrow

This is already highlighted for the PV current $i_{pv}$. The line starts from (c1) and ends at a point, 2cm far from it, we name it (d1). We will use $\verb|to[short,i=i_{o}]|$ to draw the line with a current arrow:

 \draw (c1) to [short,i=$i_{o}$] ++(2,0) coordinate(d1);


Remark: To draw the top path of the circuit, we used the \draw command multiple times, for each step. However, this can be achieved using only one \draw command (check the final code below).

### 2.4 The bottom path

The bottom path of the circuit has only straight lines without any components. We will draw pieces of lines and save coordinates parallel to the previous ones (a2, b2, c2 and d2):

\draw (panel.-53) -- ++(2,0) coordinate(a2)
-- ++(3.5,0) coordinate(b2)
-- ++(2.5,0) coordinate(c2)
-- ++(2,0) coordinate(d2);


### 2.5 Input and output capacitors

We have two capacitors:

1. between the saved points (a1) and (a2)
2. between the saved points (c1) and (c2)
% Add input capacitor
\draw (a1) to[C,l=$C_{in}$,*-*] (a2);

\draw (c1) to[C,l_=$C_{out}$,*-*] (c2);


We added the option $*-*$ to draw filled circles that highlight the connection.

### 2.5 Draw a resistor

With the same manner as above, we draw the load (resistor in this case) between the points (d1) and (d2). Besides, we add the voltage label using $\verb|v_=v_o|$. Here is the corresponding line code:

% Add a resistor
\draw (d1) to[R, v_=$v_o$,l=$R$] (d2);


### 2.6 Coordinates calculation

All the previous components are drawn along a path. However, the switch is added as node. The node is in the middle between the points (b1) and (b2). Precisely, It corresponds to the point located at coordinates 0.5*(b1)+0.5*(b2). Fortunately, this can be done using the TikZ library calc as follows:

% Add switch
\node[nigfete] (switch) at ($0.5*(b1)+0.5*(b2)$){ Q} ;
\draw (b1) node{$\bullet$}-- (switch.D);
\draw (b2) node{$\bullet$} -- (switch.E);


The above code:

• adds the switch at the calculated coordinates. The node is named (switch) and we will use it to reach different predefined anchors of the component (check the next illustration);
• draws a line from the point (b1) to the anchor (switch.D);
• draws a line from the point (b2) to the anchor (switch.E);

## 3. Adding labels and Final code

Here is the final code of the PV panel connected with a DC-DC boost converter:

\documentclass[border=0.2cm]{standalone}
\usepackage{circuitikz}
\usetikzlibrary{calc} % coordinate calculation

\begin{document}

\begin{circuitikz}[american]
% Scale components
\ctikzset{
resistors/scale=0.7,
capacitors/scale=0.7,
diodes/scale=0.7,
}

% PV module label
\fill[fill=yellow!5] (-1.5,-2.5) rectangle (2.5,2.5)
node[midway,below=2.5cm,black]{{PV module}};

% Boost converter label
\fill [cyan!5] (2.7,-2.5) rectangle (9.8,2.5)
node[midway,below=2.5cm,black]{{DC/DC Boost Converter}};

\fill [green!5] (10,-2.5) rectangle (12,2.5)

% Add an image in TikZ
\node
[draw,
thick,
outer sep=0pt] (panel) at (0,0) {\includegraphics[width=2.5cm]{PV-module}};

% Top horizontal path (L,D)
\draw (panel.53) to [short,i=$i_{pv}$] ++(2,0) coordinate(a1)
to[cute inductor,l=$L$] ++(3.5,0) coordinate(b1)
to[D*,l=$D$] ++(2.5,0) coordinate(c1)
to [short,i=$i_{o}$] ++(2,0)coordinate(d1);

% Bottom horizontal path (L,D)
\draw (panel.-53) -- ++(2,0) coordinate(a2)
-- ++(3.5,0) coordinate(b2)
-- ++(2.5,0) coordinate(c2)
--++(2,0)coordinate(d2);

\draw (d1) to[R, v_=$v_o$,l=$R$] (d2);

\draw (a1) to[C,l=$C_{in}$,*-*] (a2);

\draw (c1) to[C,l_=$C_{out}$,*-*] (c2);

\node[nigfete] (switch) at ($0.5*(b1)+0.5*(b2)$){ Q} ;
\draw (b1) node[]{$\bullet$}-- (switch.D);
\draw (b2) node[]{$\bullet$} -- (switch.E);

% Panel connectors
\node[fill=black,right,inner sep=2pt] at (panel.53){};
\node[above right] at (panel.53){\small +};

\node[fill=black,right,inner sep=2pt] at (panel.-53){};
\node[below right, inner ysep=6pt] at (panel.-53){$-$};

\end{circuitikz}

\end{document}


• We have added 3 rectangles with different filling colors (yellow!5, cyan!5 and green!5);
• We have added a text node below each rectangle using the \node command;
• We have added small rectangles filled with black using also the \node command to represent the PV module connectors. The size of the rectangle is controlled by the $\verb|inner sep=2pt|$ option.

## 4. Operation modes of the converter

In a photovoltaic system, the boost converter, generally, is controlled to provide maximum power to the load. The controlled input is the state of the switch (Q). We distinguish two operation modes:

1. Mode 1: The switch Q is conduction (On) and the diode D is not conducting. The Circuit topology is shown below and here is the corresponding code:

#### LaTeX code of Mode 1

• The diode option $\verb|[D*,l=D]|$ is changed to $\verb|[open]|$;
• The switch line codes are commented and we added a straight line from the points (b1) and (b2) using the option $\verb|[short,i=i_L]|$.

Operation Mode 1

Operation Mode 2

2. Mode 2: The switch Q is not conduction (Off) and the diode D is conducting. The Circuit topology is shown above and here is the corresponding code:

#### LaTeX code of Mode 2

• The diode option $\verb|[D*,l=D]|$ is changed to $\verb|[short,i=i_L]|$;
• The line between the points (b1) and (b2) is removed by opening the circuit using the the option $\verb|[open]|$.