Error when running SPICE simulation (ngspice-38) of KiCad 6.0.11 with a MCP6N11

I try to run this simple circuit (mcp6n11.kicad_sch, mcp6n11-symbol.lib, mcp6n11_RevD.lib):


I downloaded the SPICE model from the official MCP site.
If I run the simulator with PSpice then I get the following errors:

Note: Compatibility modes selected: ps
Circuit: KiCad schematic
Netlist line no. 0:
Closing "}" not found.
Netlist line no. 0:
Closing "}" not found.
Please check your input netlist.
Error: ngspice.dll cannot recover and awaits to be detached
******
** ngspice-38 shared library
** Creation Date: Thu Jan 26 00:03:36 UTC 2023
******
Note: No compatibility mode selected!
Circuit: *
Warning: No job (tran, ac, op etc.) defined:
run simulation not started

If I run with HSpice, then I get these errors:

Note: Compatibility modes selected: hs
warning, model type mismatch in line
s_s1 3 4 1 2 _s1
Circuit: KiCad schematic
Error: unknown subckt: xu2.x_u4_u38 xu2.vdd_vss xu2.u4_12 xu2.analog_buffer xu2.params: gain=0.5
Warning: No job (tran, ac, op etc.) defined:
run simulation not started

If I run without compatibility mode or with LtSpice, I get these errors:

Note: No compatibility mode selected!
warning, model type mismatch in line
s_s1 3 4 1 2 _s1
Circuit: KiCad schematic
Error: no such function 'if'
Error: no such function 'if'
Error: no such function 'if'
Error: no such function 'if'
Error: no such function 'if'
Error: no such function 'if'
Error: no such function 'if'
Error: no such function 'if'
Error: no such function 'if'
PTerror: syntax error, parsing stopped at
& v(xu2.endly) >   5.0000000000e-01 ,   1.0000000000e+00 ,   0.0000000000e+00 )
Error on line 0 or its substitute:
b.xu2.x_u8.beout xu2.x_u8.eout_int1 0 v= if ( v(xu2.4) <   5.0000000000e-01 ,   1.0000000000e+00 ,   0.0000000000e+00 )
parameter value out of range or the wrong type
Error: circuit not parsed.

I use the following version of KiCad:

Application: KiCad Schematic Editor

Version: 6.0.11-2627ca5db0~126~ubuntu20.04.1, release build

Libraries:
	wxWidgets 3.0.4
	libcurl/7.68.0 OpenSSL/1.1.1f zlib/1.2.11 brotli/1.0.7 libidn2/2.2.0 libpsl/0.21.0 (+libidn2/2.2.0) libssh/0.9.3/openssl/zlib nghttp2/1.40.0 librtmp/2.3

Platform: Linux 5.15.0-67-generic x86_64, 64 bit, Little endian, wxGTK, ubuntu, x11

Build Info:
	Date: Feb  1 2023 20:48:15
	wxWidgets: 3.0.4 (wchar_t,wx containers,compatible with 2.8) GTK+ 3.24
	Boost: 1.71.0
	OCC: 7.5.2
	Curl: 7.87.0
	ngspice: 38
	Compiler: GCC 9.4.0 with C++ ABI 1013

Build settings:
	KICAD_USE_OCC=ON
	KICAD_SPICE=ON

I am lost and would be happy about any advice :slight_smile:

To begin with, V1 and V2 seem to be missing parameters.

The symbol pinout order does not match the definition within the simulation model. The name of the subcircuit does not match the name of the symbol either.

.SUBCKT MCP6N11 EN/CAL VDD VFG VIM VIP VOUT VREF VSS

How to make it “match” or what’s the standards of match between the model and symbol?

In this case, in my opinion, a symbol should be created where the order of the pins matches the definition given in the simulation model. This symbol must be called the same as the simulation model indicates.

The officially supported method is to use an “alternate node sequence”, as is described in KiCad Eeschema as GUI for ngspice, tutorial for setting up the simulation.

@ML9104 Can you explain why you think that V1 and V2 are unknown? I build the circuit from scratch again, changed the alternate node sequence (see image below) and exported the spice netlist:

.title KiCad schematic
.include "/home/KiCad/libs/MCP6N11_RevD.lib"
V1 +5V GND dc 5
R3 Net-_R2-Pad2_ GND R
V3 Net-_U2-Pad3_ GND sin(0 2.5 200k)
V2 -5V GND dc -5
R2 Net-_R2-Pad1_ Net-_R2-Pad2_ R
XU2 +5V +5V Net-_R2-Pad2_ GND Net-_U2-Pad3_ Net-_R2-Pad1_ GND -5V MCP6N11
.param gmin=100
.end

@astroelectronica I did the alternate node sequence change already when I asked for help in my first post. I think it is correct, isn’t it?


I still have the same errors like before, is there anything else I can do to fix these errors?
@holger Do you know which netlist is used as input for ngspice38? Could it be that ngspice38 is not compatible with the netlist exported by kicad 6.0.11?

Hard to say now, as you’ve changed the schematic to 5 V.
But normally, I’d expect a value of (dc 3) attached to the VSOURCE symbol.

There are now two bugs reported by ngspice.
The first is about line
r3 net-_r2-pad2 gnd r
What is r given for resistor R3? If no value is given, ngspice expect a model named r.
The next is the previous bug about a missing closing ‘}’. This indeed is not a helpful error message in that it asks for line number 0. These are internally generated, parsed lines (e.g. from an expanded subcircuit) I will check to improve the message. It may be a model bug. I will have a look.

Could you please post an updated project? The link of your first post seems to be unaccessable now.

@holger here is the complete project. I added the resistor values, unfortunately the error with the } still exists.

BTW: Thanks for your effort and commitment to the community. Had already read several valuable posts of yours.

There is a feature in the model which is not parsed correctly by ngspice.
A simple remedy is changing line 326 in MCP6N11_RevD.lib from
R74 0 70 1 TC={-45.00U * 1/Limit(GMIN,33,1)}
to
R74 0 70 1 TC1={-45.00U * 1/Limit(GMIN,33,1)}
(TC to TC1).

Please also have a look at the data sheet: MCP6N11 is a single power supply device with a maximum of 5.5 V. So ± 5V is much too much.

1 Like

Thank you so much. It works! I am going to change the supply rails :slight_smile:
The MCP6N11 Spice Model is also part of https://ngspice.sourceforge.io/model-parameters/MicroCap-LIBRARY.7z and is located in mc.lib. Maybe I am not the last one who gets help in this thread.

A fix to allow expressions in TC statements has been uploaded to ngspice git branch pre-master. It will finally appear in ngspice-40.

1 Like

@holger Cool, very nice, then I am going to build ngspice from sources :slight_smile: Thanks a lot!