element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Open Source Hardware
  • Technologies
  • More
Open Source Hardware
Blog KiCad 8: Working with Circuit Simulations!
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Open Source Hardware to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: shabaz
  • Date Created: 5 Sep 2024 1:24 AM Date Created
  • Views 27949 views
  • Likes 14 likes
  • Comments 25 comments
  • kicad 7
  • kicad 6
  • kicad 8
  • kicad
  • simulation
  • measurement amplifier
  • OPA1633
  • spice
Related
Recommended

KiCad 8: Working with Circuit Simulations!

shabaz
shabaz
5 Sep 2024

Table of Contents

  • Introduction
  • Create the Schematic
  • Adding SPICE models
  • Adding Simulation Voltages
  • Running a Simulation
  • Plotting Frequency Response
  • Simulating Parts of a Circuit (Excluding some Components)
  • Summary

Introduction

The recent releases of KiCad support built-in SPICE simulation.

I was busy working on a schematic to ultimately convert into a printed circuit board for a new measurement amplifier version 4 (here is version 3), but while I was at it, I wished to simulate it. It was possible to steer the schematic toward that purpose very easily!

This blog post shows how to (at least minimally) get going with simulation.

If you want to play along, you can download a zip file containing the KiCad project discussed here and try it out! I’m using KiCad 8.0. The end result will be converted into a real circuit, so any contributions will be welcome.

If you're totally new to KiCad, you may want to view a YouTube 50-minute KiCad course.

Create the Schematic

The schematic for simulation is created just as if you were creating a schematic for PCB design. You use the same component symbols. Nothing is different. Here’s my circuit (it’s actually more of a sub-circuit because I have not completed it! This is just the gain stage sub-circuit for a larger project, which will be a measurement amplifier):

image

As you can see, it looks like any other schematic. I used regular component symbols. A key thing is to label your inputs and outputs (press the L key to add labels). It will work without labels, but adding labels will make the signals easier to locate in the end simulation results.

Adding SPICE models

The resistors and capacitors in the above circuit have built-in ideal component SPICE models, and they can be ignored (generally!). However, the circuit contains two OPA1633 op-amps and two coaxial connectors (J1 and J2). The simulation needs to know what to do with these components.

The connectors are easy to deal with. Open the connector symbol in the KiCad Symbol Editor, and then click on File->Symbol Properties. In the pop-up window that appears, click on Simulation Model at the bottom of the window. I chose a built-in SPICE model, namely that of a capacitor, and set it to 1e-14 Farads, i.e., 0.01 pF. That’s it!

image

Next, the OPA1633 needs a SPICE model. I went to the manufacturer's website (Texas Instruments, and looked for a SPICE file. I didn’t find it, so I resorted to downloading whatever model they had, which was a Tina-TI schematic file (.tsc suffix). Within the Tina-TI software, it is possible to double-click on the op-amp symbol in the opened schematic and then click on Enter Macro. You’ll now see the SPICE model. Right-click and select all, and then copy it to the clipboard. Paste it into an empty file, and save it with the filename opa1633.lib in the folder C:\Users\myusername\Documents\KiCad\8.0\simulation (modify that path to suit your system).

image

Next, open the symbol in the Symbol Editor in KiCad (there isn’t an OPA1633 symbol in KiCad by default, but I’m assuming you already know how to create new symbols since that’s core to general schematic entry; it is covered in the 50-minute KiCad training video mentioned earlier), and then, as before, click on File->Symbol Properties and then click on Simulation Model. This time, select SPICE model from file, and then click on the file icon and select the SPICE model lib file. In the Model row, click on the drop-down chevron and select OPA1633 (this is derived from the content in the SPICE model file). Don’t click on OK yet; keep the window open for the next part.

image

This next part is the trickiest bit. The aim is to tell the simulation software how to map the nodes in the SPICE model, to the pin numbers in the graphical symbol. Click on Pin Assignments. Take a look at the SPICE model text, and look for the .subckt OPA1633 line. The SPICE model connection names are listed there. You need to map those names (under Model Pin in the table) to the connection names in the graphical symbol (incidentally, the numbers against each name in the Model Pin list can be ignored; that's the sequence number for the entries on the .subckt OPA1633 line). Once that’s done, click on OK.

image

Adding Simulation Voltages

The schematic requires simulated voltages for power supplies and for stimulus. These are added into the schematic using the normal add component dialog (i.e. press ‘A’ to add a component), and using the Simulation_SPICE library.

I used the component called VDC to simulate the DC power supply. My circuit needs two power rails, so there are two VDC components, set to 7V. You’ll also need a GND component from that same library, you can see in the screenshot below how I attached it to my 0V rail.

image

The circuit is an amplifier, and I wanted to test with a sine wave. That requires a VSIN component.

You’ll need to set the amplitude and frequency. This is achieved by editing a string as shown below. This is a bit clunky (because it has its roots in SPICE, but deserves a proper menu). Anyway, as you can see, I’ve set an amplitude of 0.1 V, and a frequency of 1 kHz.

image

Now you’re ready to simulate!

Running a Simulation

From the Schematic Editor, click on Inspect->Simulator. Next, click on Simulation->New Analysis Tab (or just press the triangular Run icon). A New Simulation window appears. The most common/basic simulation is probably Transient Analysis, TRAN, which shows an output that looks like an oscilloscope view. The screenshot below shows how it is configured. I decided that I wanted SPICE to compute an output every microsecond, for a total of 10 msec.

image

When you click on OK, the simulation will run, and a blank chart area will appear. Signals will be listed on the right. Locate in the list, the signal names corresponding to the labels that were in the schematic (I called them IN1 and IN2), they should be near the top of the list, and click in the adjacent boxes to enable the plotted output!

image

To improve the display, click on View->Dark Mode Plots to disable it, to make the background white (if it was originally black). Also, click on View->Show Legend to display a color key legend on the chart. The text is all quite tiny, I don’t know of a way to increase the size within KiCad.

I also don’t know of a way to enable cursors on the chart. Fortunately, it is possible to save the output in CSV format (click on File->Export Current Plot as CSV) and examine the data using other tools (such as Matlab or Python).

image

Plotting Frequency Response

The frequency response can be plotted by running a different simulation. As before, in the simulation window, click on Simulation->New Analysis Tab and this time choose AC instead of TRAN. Populate the boxes with sensible values (in the screenshot below, you can see that I was interested in the frequency response between 10 Hz and 10 MHz.

image

Click OK, and then click on the Run Simulation triangle. Then, select the signal of interest in the list on the right. A chart should appear!

image

Simulating Parts of a Circuit (Excluding some Components)

With KiCad 8, you can selectively disable some components from the simulation, by selecting a portion of circuit, then right-clicking and selecting Attributes->Exclude From Simulation.

Personally I think this is not easy to work with. A solution proposed here of sorts, is to split your circuit into separate sheets in a hierarchy, and ensure that the portions that you wish to simulate, and the portions that you do not wish to simulate, are on separate sheets. You could for instance have five sheets, where one sheet is never simulated, and the other four sheets are simulated independently.

Then, you need a way to set the Exclude from Simulation attribute on a per-sheet basis. This is currently not possible from KiCad, however there is a Python program called sim_select.py (idea by Jan Cumps ) that can do this. It will prompt the user which sheet is desired to be simulated, and it will set the attributes of all sheets accordingly.

image

Summary

Schematics ready for simulation are created within KiCad by assigning a SPICE model to components, and then adding voltage sources and stimulus signals from the Simulation_SPICE component library. You can find SPICE model files from electronic component manufacturer websites. Don’t forget to label your inputs/outputs.

When you bring up the Simulation window (using Inspect->Simulator), you can select a Transient Analysis, which is simplest to understand, and instruct it to compute currents and voltages at granular intervals, for a period of time. A chart of voltages can be easily plotted, that looks similar to what would be seen with an oscilloscope connected to a real circuit.

The KiCad project file can be downloaded if you wish to experiment with simulations. 

If you manage to run any interesting simulations, please share the results! The KiCad project zip file is for a real circuit I intend to make and needs improving (it needs an input buffer and an output buffer that converts from differential to single-ended output), plus configurable filtering, plus the ability to high-pass-filter the input to block DC optionally. If you do give it an attempt, or even if you don't, I would appreciate any suggestions/circuit additions.

Thanks for reading!

  • Sign in to reply

Top Comments

  • Jan Cumps
    Jan Cumps over 1 year ago in reply to shabaz +1
    I saw your comment: "delete it when laying out PCB" There's an option in the schematic editor to do that: Could this be useful to add simulation-only components, without the need to delete them?
  • shabaz
    shabaz over 1 year ago in reply to Jan Cumps

    Perfect. That will do it!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago in reply to shabaz

    I saw your comment: "delete it when laying out PCB"

    There's an option in the schematic editor to do that:

    image

    Could this be useful to add simulation-only components, without the need to delete them?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago in reply to shabaz

    The interesting aspect of that script is that the actual core that does the work is 11 lines of python. And the code to get the list of schematic files is 7 lines of code.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 1 year ago in reply to Jan Cumps

    Yay, that works _really_ well!

    Program is called sim_select.py and when run, it will list all the sheets in the current project folder, and let the user select the one that is desired to be simulated.

    Once that is done, if you run a simulation within KiCad (no need to close and reopen the project, just simply close the schematic editor before running sim_select.py) then only the selected sheet is simulated. I just tested with my 3-sheet project, which has a root sheet that is never simulated, and two daughter sheets that are simulated separately.

    Root sheet:

    image

    First child sheet:

    image

    Second child sheet:

    image

    Also, the sim_select.py program will automatically backup the schematics before it touches them. But please don't blame me if it goes rogue, I only have concepts of a test plan!

    Program execution screenshot (this is Windows, but I also tested on Linux):

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 1 year ago in reply to Jan Cumps

    After investigating, it seems the Python scripting is only for the PCB, not schematic. However, since the files are all in text format, it would be fairly straightforward to do this all in a separate Python program. 

    What the program would have to do is:

    (1) Accept a filename from the user, for the desired sheet that is to be simulated

    (2) Traverse every .kicad_sch file in the project folder, and search for the text "exclude_from_sim no" and replace with "exclude_from_sim yes", unless it is the file that was selected by the user, in which case do the opposite.

    Probably good for the program to backup all the files into a folder just in case.

    Anyway, this all seems very straightforward, and should solve the problem! I'll give it a shot.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube