TikZBlog
Sharing is caring

How to draw a DC/DC Buck Converter in LaTeX using CircuiTikZ

  • dc-dc buck converter is a dc voltage converter used to transform an unregulated dc input into a lower controlled dc output. This transformation is achieved by the use of semiconductors devices that turn on and off at high switching frequency.

In this tutorial, we will learn how to draw a dc-dc buck converter in LaTeX using CircuiTikZ package.

The idea is to recreate the circuit diagram shown in Fig. 1, which is published recently in IEEE Xplore.

draw dc dc buck converter in TikZ

Buck converter circuit diagram (published in IEEE Xplore 2019)

What motivates me to use TikZ

Some of the drawbacks of adding an image directly into a LaTeX document are: 

  • The font is not the same as the rest of the document,
  • The font size is affected when the image is scaled,
  • If you would like to modify your illustration you have to go back to the used drawing tool, more distraction.

Well, we assume that the image in question is a good one, like mine 😈

For that, I prefer to use TikZ to draw my illustrations and benefit from its features such as precision, reusability and automation. And when it comes to drawing circuits in LaTeX, circuitikz is the best option.

My first illustration, December 2011.

CircuiTikZ, minimal code

The CircuiTikZ package can be loaded as follows:

 \documentclass[border=0.2cm]{standalone}

\usepackage{circuitikz}

\begin{document}

\begin{circuitikz}[american]
	% Put your code here!
\end{circuitikz}

\end{document}
  • The CircuiTikZ package is built based on PGF/TikZ, which means no need to load TikZ package twice as it is already loaded by CircuiTikZ.

The circuit code will be added inside the CircuiTikZ environment which is an alias for tikzpicture. As an option, we have chosen american style for the electrical components.

The Origin, a successful journey depends on it!  

Choosing the starting point of your illustration (the origin) is important as it makes positioning easy to deduce. Sometimes, to go faster, I draw my illustration down in a paper and add coordinates to it. The latter are adjusted later by trial and error method until I get a satisfactory result. Here is my hand drawn version of a dc-dc buck converter:

Buck converter hand drawn

Hand drawn version of a dc-dc buck converter

I have chosen the starting point at the bottom left of the circuit diagram. From there, I will draw a dc source then 👉 a switch 👉 an inductor 👉 a resistor 👉 a ground and go back to the starting point.

Along this path, I save coordinates to use them later to draw the diode and the capacitor (a1 and a2). Ready for details, Let's go!

DC/DC buck converter circuit diagram

Before going further with details and for curious minds, Here is the buck converter schematic drawn in LaTeX using the CircuiTikZ package

dc-dc buck converter circuitikz

DC-DC Buck converter drawn in LaTeX using CircuiTikZ package

And the corresponding code is: 

 \documentclass[border=0.2cm]{standalone}
\usepackage{circuitikz}

\begin{document}

\begin{circuitikz}[american]

% Change components size
\ctikzset{
	resistors/scale=0.7,
	capacitors/scale=0.7,
	diodes/scale=0.7,
	inductors/coils=6
}

% Add switch
\node[nigfete,rotate=90,label=S] (switch)at (1.7,3){} ;

% Draw DC source
\draw (0,0) to[battery1,invert,l=$v_{in}$] ++(0,3) -- (switch.D);

% Draw the inductor
\draw (switch.E) -- ++(1,0) coordinate(a1);

\draw (a1) to[cute inductor,l=L, i>^=$i_L$]
++(3,0) coordinate(a2);

% Draw the resistor
\draw (a2) -- ++(1.5,0) 
	to[R,l_=R,v^>=$\:v_o$,i">"_=$i_o$] ++(0,-3)
	to[short] ++(-1.5,0) coordinate(a3);

% draw the ground
\node[ground] at (a3) {};

% Close the circuit
\draw (a3) -- ++(-3,0) coordinate(a4);
\draw (a4) -- (0,0);

% Draw the capacitor
\draw (a3) to[C,invert,*-*,l=C,v<=$\:v_c$] (a2);

% Draw the diode
\draw (a4) to[D*,l_= D,*-*] (a1);

\end{circuitikz}

\end{document}
  • In CircuiTikZ, the electrical components are separated in two main categories:

    1. One that are bipoles and are placed along a path. In this example, it corresponds to resistor, diode, DC voltage source, inductor and capacitor.

    2. Components that have any number of poles or connections and are placed as nodes. In the buck converter case, it corresponds to the transistor and the ground elements.

Let's start drawing our circuit from scratch! 

Step 1: Add a transistor as a node

From the CircuiTikZ manual, the transistor type is named nigfete which can be added using node command at any coordinate. It has four predefined connectors as shown in the next illustration where we can link paths to it.

transistor circuitikz

Transistor anchors

In the circuit code, we have added the transistor as a node at the point with coordinates (1.7,3) and we named it (switch) to get access to its four connectors. This corresponds to line (17) of the code:

\node[nigfete,rotate=90,label=S] (switch)at (1.7,3){} ; 

By default, the transistor orientation is shown above and to get the right one, we have rotated it by 90 degrees using the option rotate=90. In addition, the switch has a label Swhich is set by the option label=S.

Step 2: Draw dc voltage source

From the CircuiTikZ manual, the dc voltage source corresponds to the element with the name battery1 which belongs to the first components category. Thus, it will be placed along a path. It is drawn from the origin to the point (0,3) and then linked to the transistor through its connector (switch.D):

\draw (0,0) to[battery1,invert,l=$v_{in}$] ++(0,3) -- (switch.D);

  • To flip a component in CircuiTikZ, we add the option invert to the component in question.
flip component in circuitikz

Inverting the DC voltage source polarity

The DC voltage source has the label v_{in}, which is defined by the option l=$v_{in}$. We can specify the label position (right or left of the electrical component) using l^=$v_{in}$ or l_=$v_{in}$.

Step 3: Draw an inductor

Now, we have to move from the right of the transistor (switch.E) by 1cm along the x-axis and save the coordinate using the command coordinate as follows:

\draw (switch.E) -- ++(1,0) coordinate(a1);

From the point (a1), we draw an inductor along the x-axis (3cm) and there we save the second point (a2):

\draw (a1) to[cute inductor,l=L,i>^=$i_L$] ++(3,0) coordinate(a2);

The inductor shape is obtained using the option (cute inductor). With the same manner as the DC voltage source, we have added the label to the inductor using the option l=L

Circuitikz inductor style

Inductor styles L vs cute inductor

Inductor current is draw at its input where direction and label position can be specified as follows:

current direction circuitikz

Current arrow and label positions (left to right direction). 

Current arrow and label positions (right to left direction). 

Step 4: Draw a resistor

From the point (a2), we draw a straight line along the x-axis and from there we draw a resistor (using the option resistor or simply  ) along the y-axis as follows:

\draw (a2) -- ++(1.5,0) to[R,l_=R,v^>=$v_o$,i>_=$i_o$] ++(0,-3) -- ++(-1.5,0) coordinate(a3);

Step 4: Add a ground

The ground is added as a node at the point named (a3)

\node[ground] at (a3) {};

ground circuitikz

Ground added as a node in two cases: with and without rotation

From the point (a3), we have drawn a straight line to the origin and we have saved the point (a4) to be used later to draw the diode:

\draw (a3) -- ++(-3,0) coordinate(a4);
\draw (a4) -- (0,0);

Step 5: Draw a capacitor and a diode

Now, we draw the diode between the points (a1) and (a4), and the capacitor between the points (a2) and (a3) :

\draw (a3) to[C,invert,*-*,l=C,v<=$\:v_c$] (a2);
\draw (a4) to[D*,l_= D,*-*] (a1);

  • We have added the option *-* to both components to highlight the connection points. For one side connection, you can use -* or *-. For small circles, you can use o instead of *
Capacitor circuitikz

Different Capacitor styles 

Step 6: Change components size

Components can be scaled using the command \ctikzset as follows:

\ctikzset{
resistors/scale=0.7,
capacitors/scale=0.7,
diodes/scale=0.7,
inductors/coils=6
}

dc-dc buck converter Not scaled in circuitikz

Without components scaling

dc-dc buck converter circuitikz

DC-DC buck converter drawn in LaTeX using CircuiTikZ

At this level, we have reached the end of this tutorial. Share with us your thoughts, reach us at admin@latexdraw.com, we will be happy to hear from you!

Leave a Comment:

2 comments
Add Your Reply