element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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
  • About Us
  • 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 28985 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?
Parents
  • shabaz
    shabaz over 1 year ago

    I thought I had a neat workflow to solve the problem of not being able to simulate the entire project:

    The idea was to use the parent (root) sheet for everything non-simulateable, and have child sheets that would be simulated in isolation if desired. No errors/warnings for the entire project when running ERC:

    image

    However, closing the project, and opening just one sheet in isolation (i.e. by right-clicking on the file (technically a copy of the file, since I didn't want to corrupt the original) and selecting Open With->KiCad Schematic Editor 8.0) causes this weird error when running the ERC:

    image

    And that weird ERC error of "wires not connected to anything" of course means that the simulation result will be very incorrect.

    I don't know what's causing it. Maybe it's simply unsupported to try opening sheets outside of a project and expecting things to work.

    I've raised a bug report.

    • 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 managed to do this type of exercise without ERC error:

    My labels are hierarchical labels.

    image

    On the main sheet, I right-clicked on the hierarchical sheet and selected Import Sheet Pin

    image 

    I imported all - gave them a reasonable location on the sheet. Inputs left, outputs right. Voltages top, grounds bottom.

    I then right-clicked on all pins, selected Pin Helpers -> No connect

    This allows that the sub-sheet passes the ERC.

    Later, I will connect the pins to main sheet nets.

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

    I'm doing something a bit unexpected unfortunately, which is to try to find a workflow where individual sheets can be simulated, without simulating the entire circuit (because some parts of the circuit may be unsimulatable, or might preferred to be simulated in isolation).

    Today, there are maybe a couple of ways that work for such a situation:

    (1) Create a separate project for the bits that are desired to be simulated. Downside is that it won't be in sync with the main project.

    (2) Select the circuitry that shouldn't be simulated, and right-click and there's an option to exclude it from the simulation (it's buried in one of the sub-menus, but it is there), but the downside to this is that it would get awkward fast to have to toggle such things when you want to test a different bit of circuitry.

    What I'd hoped could have worked, doesn't : ( I'd hoped to simply close the project, and then open a single sheet outside of the project (i.e. by right-clicking on the sheet file and selecting Open With.. and then choosing KiCad Schematic Editor. The project certainly opens like that, but won't simulate because the component reference designators (e.g. R1, R2..) go nuts. Apparently, the reference designators rely on the entire project being opened. And the error that then occurs when simulating is "wires not connected to anything". There's no solution to that currently, which breaks the ability to simulate a sheet in isolation : (

    So my project is a bit stuck, I can continue and simulate by creating a new project, but to me that removes a lot of the attractiveness of using the simulator, because then one may as well create the schematic to be simulated in any simulator, e.g. LTspice. I had hoped to just have the single source of schematics, and simulate the sheets that need simulating. I don't really have a good solution any more : (

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

    Could "(2) Select the circuitry that shouldn't be simulated, and right-click and there's an option to exclude it from the simulation" be done in a script?

    It may be complex, but at least it would be repeatable ...

    Wild thinking:

    - script would collect the part that needs to be simulated (list A). Example: all of sheet "X"

    - script would make a list of all components (list B)

    - script then removes all items in A from B. And then exclude B ...

    (obviously a brain dump without scripting knowledge :) )

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

    That is an excellent idea! I've used the KiCad Python capability once or twice, very useful for getting out of holes. I'll check to see if I can get the list of components sheet number, and then see if the exclude from simulation attribute can be set from Python.

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

    That is an excellent idea! I've used the KiCad Python capability once or twice, very useful for getting out of holes. I'll check to see if I can get the list of components sheet number, and then see if the exclude from simulation attribute can be set from Python.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
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