In a previous post about KiCad we briefly discussed all parts of the software for designing a PCB. What we did not mentioned is that KiCad is also able to do electronics simulations. KiCad is using the ngspice engine for simulation. This is an open source SPICE simulation engine. This engine is capable of simulating analog and digital circuits. SPICE has been the standard for many decades for electronic simulation. Note that the simulation is done using version 5.1.8 (stable release, Nov 5, 2020).
When using the Windows version of KiCad, the ngspice engine is already installed. There is no need to install ngspice separately (we only use Windows, so we do not know if it is also included with other operating systems).
Draw a circuit
When you want to simulate you need to create a circuit first. This is done in the schematics editor of KiCad. Open KiCad and start a new project. Launch the schematics editor. KiCad has a special library for simulation symbols. This library is named ‘pspice’. In this library are some basic symbols for simulation only. They should not be used for your PCB design. Using those symbols we create our circuit. Our circuit looks like this:
This represents a small signal amplifier with a gain of about 2 times. We use mostly basic symbols. We use two voltage sources. V1 is used as DC source for powering the circuit and is set to 9V. V2 is used as AC source for generating a sinewave with a frequency of 1kHz and a amplitude of 1V. To setup the voltage sources, right click on the voltage source and select properties. At the bottom of the properties dialog window is a button ‘Edit Spice Model…’. Click that button. For V1 we only need to setup the DC voltage as shown in the following image:
For V2 we need to setup the AC magnitude and the sinusoidal parameters as shown in the following image:
We also give all the nets some logical names (VCC, VIN, VB, VC, VE and VOUT) using net labels. This way it is easier to identify the signals in the simulator. Finally we have to setup the model for the transistor. We use a standard BC547C for the transistor. This model is not included in KiCad. We used Google to search for a model and found one very easy within a minute. We created a text file and put the model into the text file:
It is convenient to give the file the extension ‘.lib’. KiCad filters by default on those extensions. You can store multiple models in a single file or put every model in a separate file. After creating the library file, go to the properties of the transistor and click the button ‘Edit Spice Model…’. Then in de dialog select the model from the library file:
First select the library file, then select the model. Click ‘OK’ when finished.
Now we are ready to start simulating. In the schematic editor, choose from the menu ‘Tools – Simulator’. This opens the simulator window:
First click the settings button. In the settings button you can choose which simulation to run. We start with a transient. From the settings window we select the ‘Transient’ tab and enter the following values:
Our signal frequency is 1kHz (period = 1ms). With a final time of 5ms, we will see 5 periods. The time step is 1us meaning we have about 5000 steps. This will be accurate enough. The initial time defaults to 0, thus we do not need to enter a value there. We click ‘OK’ when finished. A plot window is added to the simulator window. This will be the plot area for the simulator results. Now click the ‘Run/Stop Simulation’ button. In the text field the result of the simulation is shown:
There are no errors reported. We can see the initial transient values for all the nets. For example the voltage on the base of Q1 (/vb) is about 2.4V. The voltage on the collector of Q1 (/vc) is about 5.2V. This way we can check the DC biasing of the amplifier. Now let’s look at the signals. There are two ways to add signals. First using the ‘Add Signals’ button. Secondly using the ‘Probe’ button. When clicking the ‘Add Signals’ button, we can select a signal from a list. When clicking the ‘Probe’ button, we can simply select a signal by selecting a net in the schematics. We will add the Vin and Vout from the circuit. The result looks like this:
The red signal is the input signal (VIN). We set it up to have an amplitude of 1V. The green signal is the output signal (VOUT). This has an amplitude of about 2V. This matches the gain of 2 times. What we also see is that the signal is inverted (180 degree phase shift). This is a characteristic of this amplifier. All is working as expected.
Now lets do an AC analysis. We click the settings button again. From the settings window we select the ‘AC’ tab and enter the following values:
We take 100 points. This is per decade. We set the start frequency to 1Hz and the end to 1MHz. Click ‘OK’ when finished. We see a second plot added to the simulator. Press the ‘Run/Stop Simulation’ button. The text field shows the results similar to the transient. If no errors are reported, signals can be added in the same way as with the transient analysis. We add the output signal (VOUT):
As we can see the output signal is 6dBV (red signal). Because we set the input signal to 0dBV, the gain is 6dB (2 times). The green signal is the phase shift.
Changing values is easy. Just go to the schematics and change a value. Then return to the simulator, select the plot you wish to update and press the ‘Run/Stop Simulation’ button. The signals in the plot will be updated.
As we can see KiCad is very useful for simulating a circuit. Although we have not yet simulated any complex circuits, we think this will be not a problem since the simulation is based on SPICE. The symbols in the library are limited and no models are available by default. This means users have to build up their own library of simulation symbols and SPICE models. The big advantage is that you do not need separate software and learn another interface if you want to do a simulation.
We hope this post can inspire you to simulate circuits with KiCad.
Downloads:KiCad design files of the simulation project (74 downloads)
Disclaimer: these downloads are provided as is and we cannot guarantee that it is free of bugs. We can not be held liable for any damage caused by using these files.