I have a component simulation model that is specified in Verilog-A, which I would like to include into a simulation in KiCad. Is that supported?
In the user manual of ngspice (I am no expert) I see this should be possible. However, in the “simulation model editor” of KiCad it does not seem to be a supported format:
Of course this does not mean that it cannot be done!
May I suggest the following approach:
Firstly confirm that your Verilog-A model can be compiled by OpenVAF (https://openvaf.semimod.de/) into a shared library (MS Windows, Linux are o.k., macOS is not supported). You may call it mydevice.osdi for example. The compilation success is inevitable for the following actions!
An Eeschema symbol for the new device is required.
n1 n2 … are the device nodes
instp1 instp2 … are the device instance parameters, as defined by the VA model code.
mpar1 mpar2 … are the device model parameters, as defined by the VA model code.
Put the subcircuit into a file and attach it to the symbol in the usual way.
Create a file named .spiceinit (leading dot required!). Its location depends on the OS (see ngspice manual 12.6 for ngspice-43 or 16.6 for older versions). Write the code to load the newly created shared library into this file: osdi <path>/mydevice.osdi
Hopefully that’s it! I have not tested this approach, but it sounds reasonable.
Thank you for your guidance, @holger , it is very much appreciated. Unfortunately OpenVAF is not compiling my model, it crashes without any meaningful error message. I opened an issue in their GitHub.
I will see if I find another solution, or just try to translate the Verilog-A model into a Spice model (which I don’t know if it is possible, I am not very much into these technologies).
Replacing the offending ‘,’ by ‘:’, this one is left:
$ ./openvaf-compile-va-10_.sh
error: function 'rdist_normal' is currently not supported by OpenVAF
--> \\?\D:\Spice_general\OpenVAF\10_4231_D37H1DN48\rram_v_1_0_0_mod.va:146:20
|
146 | gap_random_ddt = $rdist_normal(rand_seed, 0, 1) * deltaGap / (1 + exp((T_crit - T_cur)
/T_smth));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsupported function
|
= This function is part of the Verilog-A standard but currently not implemented by OpenVAF
If this function is important to your application, create an issue:
https://github.com/pascalkuthe/openvaf/issues/new
error: could not compile `rram_v_1_0_0_mod.va` due to 1 previous errors
done
Indeed I fixed all the syntax errors, and the $rdist_normal I just removed it completely, i.e. replaced $rdist_normal(...) by 0. After that I just get OpenVAF encountered a problem and has crashed! and no more information (more details in the GitHub issue).
About the memristor models for ngspice, thanks a lot! I was already experimenting with them a few days ago and for sure will use them as a starting point.
@holger may I ask you a question about your memristor model? In line 28 of memristor.sp you added a DC voltage source with 0 V in between the current source and the capacitor, instead of a cable. Why? Is this related to some computational reason? I tried removing it and I saw a small change in the behavior.