You are on page 1of 7

instructables

Simulating a KiCad Circuit

by Makerss

Drawing and designing circuits is an old process, as input.


old as the rst electronic components. It was easy
then. There was a limited number of components and As you have correctly guessed, it would be a
therefore a limited number of con gurations, in other nightmare to try to analyze these circuits by
words: circuits were simpler. Now, in the so-called calculation or by hand. Furthermore, some tolerances
information age, there is a myriad—A LO T — of and nuances would be lost or altered as they are
di erent components, and each electronic product speci c. This is where simulation comes in.
component has over a dozen models and each model Harnessing the power of modern technology and with
is manufactured by a handful of companies. Needless cutting-edge speeds, a circuit analysis that would
to say, each model and each company-speci c have taken teams of people working for hours is now
component di er from each other. They may have as simple as setting the
their biases, errors with di erent tolerances, di erent
max, and min operating conditions and of course may Supplies:
slightly change how the circuit responds and works.
-Kicad version 5.0 or later
To top it all o , circuits nowadays are highly complex;
consisting of up to dozens of components that
-Internet connection to download libraries
interact together to do di erent tasks based on the

Step 1: How Does the Magic Happen?

Simulating a KiCad Circuit: Page 1


Let’s preface this by saying that KiCad does not is just a middleman between you and the simulation
handle simulations. KiCad is merely a UI (User- program, which could be one of multiple software
interface). A comparable analogy would be that KiCad called “SPICE”.

SPICE is short for “Simulation Program with models” that replicate the properties and nuances of
Integrated Circuit Emphasis”. In KiCad’s case, KiCad 5.0 their real-life counterparts, and then package these
and later comes pre-packaged with a SPICE program models as downloadable libraries, so that drawing a
called ngspice. Ngspice has its quirks, hiccups and circuit would be as simple as downloading the
limitations but will be the software we will focus on. required libraries and assigning model to our
Ngspice uses “Components” to model circuit components. But that’s all talk, let’s get our hand dirty
behaviour. This means that aside from drawing the and see how this actually works.
circuit schematics we also must annotate and “assign”
models to individual components. To solve the
problem of multiple models of the same components,
ngspice decided to let each company make “spice

Step 2: Choosing a Circuit and Modelling Passive Components.

We chose a simple circuit that allows us to • 1 rheostat •


demonstrate how we can provide our own SPICE
values to components and how we can use 1 ground
components that vendors listed
M o d e llin g Re sist o rs o f a ll t ype s
First o , as we can see from the gure; there are 8 Ngspice “assigns models” to resistances, in other
components to this circuit. words: it recognizes them. So we don’t need to modify
• 2 resistor them, or tinker with libraries to make them. We also
notice that there is a rheostat and an LDR. In ngspice,
• 1 9v battery they can both be modelled as constant resistors that
we will modify their values as we need. In other words,
• 1 LDR if we need to “increase the light” or increase the
rheostat’s load, we will have to stop the simulation,
• 1 BC 547 npn transistor modify the load, and then rerun it.

• 1 LED

Simulating a KiCad Circuit: Page 2


Step 3: Modelling Voltage Sources& Grounds

Ngspice doesn’t recognize “standard” voltage sources; reference name for the voltage source, VoltageMain
those used by KiCad. It provides a library speci cally for example, and then we click “Edit Spice Model.” As
for the voltage sources and grounds shown above

To access the library, rst, we have to pick the “Choose Then we choose a value of dc 9v, and that is about it.
symbol” tab, and search for “spice” As shown in ( gure 3)

*As seen in ( gure 1), we have the “pspice” library and the Th e Gro un d
“simulation_spice” one. For voltage sources, we want to
scroll down to the simulation_spice library and choose a For the ground, we search for “spice” again and the
dc voltage source rst result is the 0V reference potential as shown in.
( gure 4). Unlike normal schematics, spice software
Afterward, we have to set its values for the simulator needs the ground as it calculates its voltages based
to understand, in this circuit we want a 9v dc source. on the 0v reference.
We click “E” on the voltage source and the following
menu opens, shown in ( gure 2). We choose a

Simulating a KiCad Circuit: Page 3


Step 4: Modelling the Transistor

As we can see from the circuit picture, the transistor used is a very speci c model, the “BC547”. As a general case,
almost all manufactured components will be found on their respective manufacturer’s website. Under their tool or
support tab, there will be “simulation models” featuring the model number and a relative spice model. In our case I
searched for “bc547” online and found that it was manufactured by a company called “On semiconductors”. I
searched for their website “https://www.onsemi.com/” and found the model by doing as follows:

I opened their “Tools and support” tab, underneath I, found a design resources tab. ( gure 1)
Underneath design resources they asked for the type of document, I chose “Simulation Models”
( gure 2)
I searched for the part by name: “BC547”. We want the library, so we choose “BC547 Lib Model” and
downloaded it. ( gure 3)
After downloading it, I put the lib le in my project directory. Now my project directory is shown in
the original KiCad window I opened, as seen in ( gure 4) . I clicked my way to that directory, pasted
the library le as shown and returned to nd it shown alongside my project’s les
After all that has been said and done, let’s draw the transistor symbol. I clicked using the “place
symbol” menu, and just searched for the name. You nd that almost all components exist in the
symbol menu as in ( gure 5).
Now, what remains is assigning the model to the symbol. We click “E” as always on the symbol, and
click on “Edit spice model”.
As we can see, the only tabs available are model, passive, and source. Since transistors are neither
source nor passive, we choose the model and choose to plug-in a library to ll. The menu rst opens
to the project’s directory, which we lucky have already put the library into it. We click on the lib le.

Great!! Now ngspice has identi ed the transistor as “BC547” and is almost ready to
operate. There is one tiny detail to be sorted rst. We have to enable alternate node
sequence and type “3 2 1”. The reason we have to do this step is that ngspice names the
3 transistor terminals in a manner opposite to how KiCad shows them. So, it may have 3
assigned to the collector while KiCad shows 3 as the emitter. To avoid confusion, we
recon gure Spice’s naming order, as shown in ( gure 7)
Anddddd that is it! This process is almost identical for all
vendor-supplies models. Once you wrap your head around this tutorial part, you can
use any type of electronic model and component with only a little research.
Simulating a KiCad Circuit: Page 4
Simulating a KiCad Circuit: Page 5
Step 5: Modeling LEDs

LEDs are a bit trickier in the fact that modeling them requires some knowledge about their parameters and curve-
tting. So, to model them I just looked up “LED ngspice”. I found multiple people posting their “LED models” and I
decided to go with this “ * Typ RED Ga As L ED: Vf=1. 7 V Vr=4 V I f=40 mA t rr=3uS . MODEL LED1 D (IS=93.2P
RS=42M N=3.73 BV=4 IBV=10U + CJO=2.97P VJ=.75 M=.333 TT=4.32U)?”

We will pick “LED ” from the symbol menu and paste this code into the empty space below the
libraries in “Edit spice model ”. We’re also going to switch on alternate node sequence and write “2 1 ”,
as shown in gure 1

Af t e r a dding s o m e na l t o uche s , like t he re s is t o rs a nd co nne ct ing t he w ire s , w e a re re a dy t o


s t a rt s im ula t ing !!

Step 6: Simulating

Sim ula t ing is co m ple x s o in t his t ut o ria l w e w ill e xpla in t he ba s ics a nd ho w y o u ca n g e t s t a rt e d.

First, we open the simulator from the tools tab in the upper ribbon ( gure 1)
Then we go to the simulation tab in the upper ribbon and click settings, from there we can specify
what kind of simulation we want to run, and its parameters. ( gure 2)

We want to run a transient simulation. There’s also DC and AC sweep available as simulation options. Dc sweep increments
the value of the Dc current and reports the changes in the circles while AC monitors the frequency response.

However, transient analysis simulates a circuit in real-time. It has 3 parameters, of which we are
going to use two. Time step is how often will the simulator record results, and the nal time is after
how many seconds will the recording stop. We input 1 millisecond and 5 milliseconds and then ok,

Simulating a KiCad Circuit: Page 6


and then we run the simulation ( gure 3)
As you can see, in the lower text display it showed us the voltage and current values across various
components. We could also graph these values by using the “add signals” button and then choosing
the voltage or current of a certain component. We can also probe after we start the simulation.
Probing allows us to monitor the voltage and current curves in a certain component directly by
clicking it. ( gure 4)

Step 7: Wrapping Up

Since this circuit was supposed to be made with an LDR and a resistor, we can alter both of these components resistance
and then rerun the circuit to determine the resistance values we would like for this light-controlled LED using a common-
emitter npn transistor as a switch circuit.

A n d d d t h e re st is up t o yo u : 3

Simulating a KiCad Circuit: Page 7

You might also like