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
  • battlecoder
    battlecoder over 1 year ago

    Thanks for the write-up!I think you just gave me something to play with this weekend Smiley

    Circuit simulation is a topic I've always been fascinated by, but it's normally been a separate process than the PCB design for me, and thus something I've not done a lot of. Love to see this integrated in KiCad!

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

    Thanks! I'm still learning how to make best use of the simulation capability within KiCad, I suspect it might end up useful for quick spot-checks, because the overhead is very low for enabling the simulations (simply add the SPICE models and any simulated voltages and stimulus). It probably curently won't replace other SPICE tools for more thorough simulations unfortunately, because it's still quite new. I think that may require waiting for a KiCad 9 or 10 or greater. 

    • 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've been looking at it too. My main takeaway was: "can be done, works, returns results"

    At this moment, I don't find advantages of doing it.

    • Not enough synergy between the simulation design and "for real" design
    • although drawing diagrams in KiCAD is way easier, the whole simulation cycle (and analysis) is easier when done in LTSpice

    It's cool though. And I hope the approach hits that sweet spot where there is actual reuse between the simulation schematics and the actual design. Wouldn't it be cool if we could select/highlight a part of a KiCAD schematic, and simulate it?

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

    "Wouldn't it be cool if we could select/highlight a part of a KiCAD schematic, and simulate it?"

    That would be very cool. Right now, I can't figure out an ideal way to blend the testing of portions of the circuit with the full circuit that will be produced. I stubbed out things like connectors since that was easy to do, but there will be plenty of other bits of circuitry that I don't want to be simulated.

    My plan for the current project is to copy-paste the smaller circuits into a single file but only simulate the smaller circuit files if needed. I will allow the files to get out-of-sync, i.e. it is up to the user (me) to modify the smaller circuit to retest if needed. I don't think such an approach will save any time, nor be a very 'best practice' thing, I hope the KiCad simulation workflow can improve one day.

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

    Another thing that would be extremely cool is that if it could simulate the PCB. It should *technically* be possible for KiCad to automatically insert resistors, capacitors and inductors in the SPICE network, based on traces length and width, proximity to other traces, etc.

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

    Maybe we can learn from test driven development? Have a mechanism to generate test stubs for parts that can't be simulated?

    In my company, we were struggling to create software mocks for a single function or class a decenia ago. These days we mock entire 3th party systems that we interface with.

    If we can start to mock a little dependency in an electronics circuit now, we may be able to mock a PSU, amplifier, filter bank in a simulation in 10 years too?

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

    I *think* there's a semi-workaround. Not a brilliant one though.

    I did an experiment, and believe the following workflow functions. 

    (1) Start a KiCad project, and then for any part that you _do_ wish to simulate in isolation, then create a sheet (i.e. Place->Add Sheet) and then cut-paste that portion of the circuit into there. Then whenever you wish to simulate that part, close your project, and there should be another .kicad_sch suffixed file in the project folder. Right-click on that file using the normal Windows Explorer (i.e. file explorer) and select Open With->KiCad Schematic Editor 8.0. 

    By doing that, you're essentially opening up the schematic sheet _outside_ of the project. Then you can simulate that schematic sheet.

    image

    I think this may be a reasonably practical way to simulate portions, but still no way to stub out sheets or provide a mock function for a sheet and then just simulate the whole project.

    This is the cleanest way I've found so far (and it's not very clean!). I wonder if there's any better way with the current KiCad. I'll raise it on the KiCad forum in case anyone there knows of a way too.

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

    I *think* there's a semi-workaround. Not a brilliant one though.

    I did an experiment, and believe the following workflow functions. 

    (1) Start a KiCad project, and then for any part that you _do_ wish to simulate in isolation, then create a sheet (i.e. Place->Add Sheet) and then cut-paste that portion of the circuit into there. Then whenever you wish to simulate that part, close your project, and there should be another .kicad_sch suffixed file in the project folder. Right-click on that file using the normal Windows Explorer (i.e. file explorer) and select Open With->KiCad Schematic Editor 8.0. 

    By doing that, you're essentially opening up the schematic sheet _outside_ of the project. Then you can simulate that schematic sheet.

    image

    I think this may be a reasonably practical way to simulate portions, but still no way to stub out sheets or provide a mock function for a sheet and then just simulate the whole project.

    This is the cleanest way I've found so far (and it's not very clean!). I wonder if there's any better way with the current KiCad. I'll raise it on the KiCad forum in case anyone there knows of a way too.

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

    it is a good start though. If KiCad would adapt that as the workflow, and allowed two-way synchronisation, this would be very useful.

    (edit: round-trip is the term I was looking for)

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

    One other idea that needs testing still, is maybe it could be worthwhile to have an extra layer in the hierarchy, for testing more than one sub-schematic connected together. i.e. three layers. So, the top-layer is not simulated (since that contains things that can't be simulated), then the next layer contains a single simulation of all lower layer circuits connected together (doesn't matter if there are islands of circuitry, you'd just need to probe the relevant island). Worth a shot anyway! 

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

    the design paradigm "round-trip vs layers",  is close to the software  OO inheritance vs injection/collaboration.

    Layers will be the best solution if you are looking at one angle. In this case simulation.

    I think (opinion alert) that once you have several things to resolve (simulation, RF behaviour, BOM optimisation, MISRA compliance*, ...) , round-trip is more scalable.

    * I added the MISRA part to up my argument :).

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

    I've had some feedback, it is here:

    https://forum.kicad.info/t/simulation-workflow-best-practise-for-a-complete-project/53856

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

    Just to see how practical or impractical it may become; here's what it looks like at the top layer, when that op-amp circuit to be simulated is pushed to a lower layer. All the connections labeled CAPxx are where additional capacitors will be switched in with relays, to have different filter cut-offs. I can't (or won't) simulate the relays, hence I need those connections broken out like this for the top layer to deal with. So far it's OK, but does need some mental planning to split out the things in this way (i.e. on a to-simulate or not-to-simulate basis) onto different sheets.

    image

    • 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