Using KiCAD to simulate your op amp circuits

Hey gang,

I thought I’d put this here to help others that may run into the same thing, but basically in case you didn’t know, KiCAD comes with ngspice built in now (was it since v5?) and you can use it to simulate your circuits and see feedback.

I won’t go into how this all works, but what I wanted to share was a little hack required to use the Texas Instruments pspice file that was generated it seems in the 1980s to work with this functionality.

If you’ve tried to do this before, you’ll know that this spice library provided by them doesn’t play well, and won’t work because the pins don’t align with the TL072 symbol so the power pins won’t work.

The secret is to do a few things:

  1. Put your downloaded Texas Instruments spice library in the root folder of your KiCAD project (the file should be “TL072.301”)
  2. Create a new file called “TL072-dual.lib” and put the following inside it (using a plain text editor):
  • A dual opamp ngspice model
  • file name: TL072-dual.lib
    .subckt TL072c 1out 1in- 1in+ vcc- 2in+ 2in- 2out vcc+
    .include TL072.301
    XU1A 1in+ 1in- vcc+ vcc- 1out TL072
    XU1B 2in+ 2in- vcc+ vcc- 2out TL072
    .ends
  1. If you’re using Linux like I am, there is an errant character at the end of the original texas instruments TL072.301 file, it’s the very last character. Delete this and save it.

  2. Now you should be able to in KiCAD place one of the 3 elements for the built in TL072 object and then go to the properties of it, then in the properties window press the “edit spice model” button

  3. Go to the model tab and press the “select file” button, choose your “TL072-dual.lib” file

  4. now you should be able to choose “TL072c” in the model drop down box, and for type, choose subcircuit

  5. You must do this for all 3 elements for the TL072 (the two op amps and the power input)

  6. The simulator should now work as long as the rest of your components are created properly

Remember that for ngspice, you must specify the values of your components with “meg” for mega, “k” (that’s lower case k) for kilo and “u” for micro. I think that it can run conversions for you on the fly, but I found this to be flakey.

It can be touchy if unhappy with slightly cryptic messages, but I created a copy of my schematic, modified it as needed to make it work and tested it. If you haven’t done this before, you may want to do a couple of youtube tutorials as there are oddities with making a simulation happy (especially with power sources and ground sources etc).

Have fun!

6 Likes