Simulation directives

I’m having difficulty using directives placed in schematic editor to work properly. It seems the text directive is always placee at the beginning of the netlist. Im my case I am trying to display compute time after the simulation run. I am using the text below. Unfortunately because this is placed at the beginning of the netlist instead of after the .tran statement, it always reports “0” seconds. Is there a way to get the netlister to put the text control at the end of the netlist?

.control
RUSAGE TRANTIME
.endc

The result has nothing to do with the position of the .control section in the netlist. Due to the approach with multiple threads the simulation command and the .control section commands are executed in parallel (in different threads), independent from their position.

You have to tell the .control section to process its commands after the simulation has finished. This is done by

.control
set controlswait
RUSAGE TRANTIME
.endc

Thank you. That worked great. As you can tell I just started using the simulation feature in KiCad. I am so far very impressed. I am an EE with 40+ years experience and have used many simulators including spice, Hspice, pspice, and circuitLab. The KiCad interface is the best so far. I especially love the schematic editor. very intuitive and fast. I am now trying to figure out how to sweep parameters and get the graph to show the curves. Thanks again.

About 1998 at some fair I got PSpice demo version (restricted to 30 nets I think). I used it from time to time. 30 nets was enough for me.
I use spice very rarely. I decided to use KiCad, as after moving from Win7 to Win10 I’m not sure if my PSpice will run here and to not have to learn PSpice hotkeys each time.
I don’t agree with you. I think KiCad is improved fast but didn’t reached this old PSpice user interface level yet.
Using PSpice everything I needed was set by menu (I have never need to add any text directive).
Voltage/current sources parameters were set also not as text at schematic but as editable symbol parameters.
I used KiCad Spice only few days - may be I simply didn’t discovered all possibilities.
What I remember from PSpice that I didn’t found in KiCad:

  1. To set initial conditions for transient simulation (I used for example to simulate Surge gun) there were special symbols (like KiCad PWR_FLAG but with value to set). To do it in KiCad you have to write directive and as I have never in my live used any Spice directives I simply have a problem with it as even don’t know their names. It is better if you can do everything using menu and graphic than to write commands manually.
  2. I was able to switch on/off showing at schematic all calculated operational point voltages and/or currents. From my point of view it was very useful. You change one value, run simulation and have all at schematic. I don’t know if it is possible in KiCad, but I didn’t found it.
  3. At chart you could press some key to shift cursor to next local maximum.
    I remember when I was reading from PSpice amplitudes of odd harmonics up to may be 25. It was my way to measure (too long to describe) real L paralel capacitance that was fraction of one pF. This are sharp tips and positioning cursor manually is not trivial. With PSpice I just got each max by pressing one key.
    If such function is in KiCad than I also didn’t found it yet?
  4. I was able to have two chart sets (one over another). For example one with amplitudes and one with phases. For me it is easier to see them separately. I was able also divide such way voltage charts and current charts what also in some situations is what I prefer then having them together.
    I didn’t found the way to get it in KiCad.
  5. I was able to select (for fft) if y axis is linear or logarithmic. I used it to see/feel relation of harmonic values to base signal (not in dB but in real values).
  6. At output charts with one button I was able to switch between time chart and fft chart. I didn’t tried fft in KiCad yet so have no comparison.

As I didn’t used PSpice for last 8+ years and I used KiCad Spice only few days my comparison is certainly not objective.

Those are great comments. I have to say that most of my experience with simulation environments has been with Caedence and Hspice. I started my career with this tool set. The schematic editor isn’t bad but early in my career you had to always control the simulation with a text input file, including all sources and simulation directives. Hence, I feel very comfortable with this method. Since I can include text controls directly in KiCad schematic editor, it allows me to use all the features of the simulator. Further, I can always create a text control file and attach it to a custom component with no connections, this is usually called a “test bench” in my industry. I should mention that I work in the IC industry and work heavily with all types of circuits, including analog. I find KiCad very intuitive. I agree there is a lot of room for improvement with addition GUI interface support, but at least I can use all the features of the simulator. For comparison, in CircuitLab, there is no way to place initial voltages on nodes to aid in DC starting conditions. This is especially helpful with high gain amplifier circuits. I have not had much time to really analyze all the capabilities of KiCad, so I can’t comment on your other points. Since that is the case, I suppose I exaggerated my initial post. I was just to pleased to find that KiCad was able to handle my current state variable filter and mixer correctly. Also, my exposure to PSpice is also limited, but at the time I tried it years ago, It seemed adequate, but I remember I wasn’t overwhelmed with the environment. I will keep testing KiCad and explore areas for improvement. Thanks for you detailed post, which was more thought out than my original comments. To repeat, I was reacting to my initial impression. :slight_smile:

1 Like

I also found a difficulty of using directive to run simulation on serval difference pspice tool (ngpsipce, and TLSpice etc.) What I found were that each tool have difference control, or not every spice simulation accept the control block. So when I use directive, I often have to include, and exclude back and for depend on the tools. Are there way to made this easier?

  1. The include, and exclude from simulation text graphically look the same. If they look difference that you also help I think.
  2. If directive some how generate two difference netlist files base of the “directive text”. So I could run simulation on ngspice with netlist 1, and LTSpice with netlist2.

Any help?

I see “run” command in the ngspice manual. So this is not what I though that trigger the simulation and all the thing, and wait for it done ?

No, command ‘run’ is not used in Eeschema/ngspice.

After the circuit has been loaded, Eeschema internally issues the command ‘bg_run’, which is specific to the ngspice shared library (libngspice.so or ngspice.dll). The simulation is started in a second thread. Commands from the .control section would be started immediately in the primaray thread, when the simulation probably has not yet finished. So one needs to issue the ‘set controlswait’ command in the beginning of the .control section, to have it wait until simulation has finished.

This topic was automatically closed after 90 days. New replies are no longer allowed.