Simulation: Anyone VHDL Blocks

Hello,
has anyone managed to integrate his VHDL Block into Kicad simulation?

Why i ask:
I would like to write a pwm unit in Kicad that outputs a variable with duty cycle. That PWM signal would than be used for a mosfet.

Is there any tutorial available?
Michael

There is a PWM available in KiCad/ngspice as a code model. It has been used in several of my examples at More simulation examples for KiCad/Eeschema/ngspice, for example in the Regulated boost converter or the Digital PWM amplifier.

ngspice supports direct simulation of digital Verilog blocks, which have been compiled with Verilator (see Ngspice, the open source Spice circuit simulator - Special features). This feature has not yet been used in conjunction with KiCad, but I don’t see any roadblocks.

1 Like

Holger, thank you for your great work on ngspice. With Kicad as UI it becomes really user friendly.

Is there any chance, that you could do a tutorial on verliog / c integration in kicad?
I would like verify my power supply topologies with ngspice.

The boost converter examples are nice for basic tests. But i would like to simulate later my real control loop, that i would write in the best possible case in c.
By the way, I woun’t mind to write the pwm duty cycle generator in c.

At the risk of being told to get my coat, would QUCS-S perhaps be a more suitable ngspice front end for this?

The PWM generator is written in C (code model using XSPICE macros, see ngspice / ngspice / [902a62] /src/xspice/icm/digital/d_pwm). The cmpp processor then creates a plain C file, which is compiled together with ngspice and saved in the shared library digital.cm.

The Verilog interface d_cosim and the C interface d_process support only digital data transfer.

You may write your complete system as code model blocks in ngspice (analog, digital, mixed signal). These may be put into subcircuit models (individually or already connected as a complex model), loaded by KiCad/ngspice to provide system simulation.

The only deficit of this approach that I am aware of is that code models (currently) do not support small signal noise simulation (which is difficult to use in a mixed signal environment anyway).

Holger, is there any tutorial how to do that on KiCAD?
Small signal noise is not relevant to me.

Creating code models is a ngspice task. When ready they may be transferred to KiCad. Unfortunately there is no detailed tutorial available.

You will need to have C programming experience and knowledge about your operating system.

My recommendation then is:

Establish compiling of standard ngspice-42 (see ngspice manual at Ngspice, the open source Spice circuit simulator - Documentation: manual and control flow , chapter 32).

Generate the new code model and add it to an existing code model library, e.g. xtradev. See ngspice manual chpater 26.3, and Ngspice, the open source Spice circuit simulator - XSPICE HowTo . The existing code models (we have already 70) may serve as examples.

Create a simple test bench (ngspice netlist) to check your development.

Replace the KiCad xtradev.cm with the newly generated extradev.cm which includes the new code model.

Create an Eeschema symbol.

Put the new code model into a ngspice subcircuit and attach it to the symbol.

Simulate the KiCad circuit.

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