Strange way of using KiCAD

Hi everyone, I’d like to share an idea for using KiCad in a somewhat unconventional way.

While I was preparing for an exam, I needed a way to create clean and good-looking drawings of various control systems, block diagrams, and electrical schematics. Unfortunately, I don’t know of any free software that is really well suited for drawing this kind of material. Of course, you can try using https://www.photopea.com/ or, in the worst case, GIMP or Paint, but drawing every line and every vector manually in those tools takes a lot of time.

At some point, I had the idea: why not use the KiCad Schematic Editor instead?
Its graphical capabilities are actually quite powerful and flexible.

Using it, I managed to create a set of custom symbols, and in the end I got some pretty decent-looking diagrams. The coolest part is that everything is vector-based, so the drawings keep their quality at any scale.

While working on these diagrams, I also came up with a few ideas on how KiCad’s functionality could be extended.

It would be really nice if the text editor allowed writing formulas using a syntax similar to Typst (open source) or LaTeX, with those formulas being rendered in the same “mathematical” style. Ideally, by pressing a simulation button, these diagrams could then be simulated in a way similar to PLECS. However, I doubt that there are open-source simulators as fast as NGSpice that are specifically designed for simulating control systems.

The second idea is probably unrealistic, but the first one might actually be doable. I’m considering forking the KiCad source code and trying to implement such a formula parser myself - who knows, maybe it could work.

simulations.pdf (641.9 KB)

simulations.kicad_sch (506.8 KB)

4 Likes

Inkscape (vector graphic editor) can be better for it, I think. Except few simply tries I have no experience with it, but it certainly allows to make a symbol of something and then duplicate it.

When trying Inkscape (may be 15 years ago) I failed at this that after reading its manual (with many examples) I was able to draw a line and then modify its color, but spending a hour or more on it I was not able to find a way to set color of line before I start drawing it (may be something was lacking in the version I had or I just got selective blindness those time). At the end I said that I will not be using software if I can’t do something so simple.

When I moved to KiCad I had to use Inkscape to prepare PCB pictures I needed based on plotted from KiCad svg files.

I was making my KiCad libraries in 2017. Except symbol libraries for electronic components I have one library containing block symbols to be used in drawings like yours. I named it ‘Z’ to be at the end of library list.

As ngspice is integrated, why not consider it for simulation?

A starting point may be Simulation with XSPICE code models.
And here is the translation of an algorithm into ngspice: X-Y plot Lorenz attractor using A models , again with code models.

Each of your graphical items has to become a valid Eeschema symbol.
Each symbol will require a ngspice model for simulation.

New models may be generated in various ways, see Ngspice, the open source Spice circuit simulator - Special features, for example:

Models may use existing models with new parameters.

Models may be made as subcircuits, using ngspice devices, as behavioural models with controlled sources (ngspice manual chapter 5), or using transistors as if integrated.

Models may be made as code models, which is C code and applying some given macros, compiled as shared libraries (see Ngspice, the open source Spice circuit simulator - XSPICE HowTo, my favourite).

Models may be written in Verilog A and compiled for ngspice with OpenVAF.

Models may be written in Verilog or VHDL and compiled as shared libraries for linking for ngspice.

Personally, I would recommend making a list of symbols and models required for system simulation and then decide how to generate the models.

Parsing equations in Eeschema: What is the goal of doing that?

1 Like

When doing simulations of control systems, you often want to directly modify formula’s in a block. Just like you are changing resistor and capacitor values in an electronic simulation.

But there already is (Open Source) software that can do this. Below a screenshot of an PID controller from Scilab

Yes, but the problem here is limited amount of manpower from the developers. For a long time (many years) there have been around 1500 open issues (many are feature requests) for KiCad on gitlab. On average, 263 issues got closed each month last year, but new issues are created almost as fast.

Issue Analytics · KiCad / KiCad Source Code / kicad · GitLab

Paulvdh, I have understood this a little differently: The OP has said: It would be nice, and I will start some work on it.

Concerning the Scilab example:
Indeed there is a ngspice code model called “S-Domain Transfer Function” (ngspice manual chapter 8.2.18), which allows to create these “Laplace”-building blocks seen in the Scilab PID example. Currently this model has to be accessed by naming the coefficients, and it has not been tested doing this via Eeschema.

1 Like

So that proves it. Asking nicely can get you a long way :slight_smile:

I guess this would be fairly easy to implement in KiCad / ngSpice. The value field of a resistor (capacitor etc) is already both visible, editable and used by the simulator, and I’ve also seen formula’s entered in symbol fields that are used by the simulator.

I just did a little test by creating a “block” schematic symbol.

In the symbol properties, I added two fields to this symbol. One for the Numerator, and one for the Denominator. This is all standard KiCad stuff. Both the Numerator and Denominator can be edited just like any other normal custom field. I guess that adding a model so these values are used in an ngSpice simulation is also pretty straight forward, but that is still a bit voodoo to me.

Using two fields for a separate Numerator and Denominator will cover most of the cases used in controllers, and I like the simplicity of doing it this way of using standard KiCad constructs.

One thing that is “missing” is that in KiCad, symbols are fixed size, while in software that is made for such diagrams, the boxes normally scale with the size of the formula.

More complicated blocks can be made by using the Hierarchical sheet system in KiCad. If this all works in KiCad, then I would rather do such diagrams in KiCad myself, then go though the learning curve of another program.

I am sorry, my formulation has been ambiguous. Here’s the correct one:

The OP has said: It would be nice, and he will start some work on it.

1 Like