[SOLVED] DC sweep command bug

Hello,
I encountered the following problem : I want to do a DC analysis of a MOSFET, so I need to sweep across the gate voltage and across the drain voltage at the same time. I can set the voltage for one of them in eeschema and use the GUI to do the DC analysis, no problem. However, when I use both sources to sweep using the GUI


I get an error from ngspice
Fatal error: DCtrCurv: source / resistor 0 not in circuit
doAnalyses: no such device

I found a workaround by writing the command directly into the schematic :
.dc Vsignal 0 24 1m Vsupply 0 24 4

And it works ! The only issue remaining is the results that are not displayed properly.

As you can see, each curve is linked to the next one as if it was one giant curve instead of multiple ones. Does anyone have the same issue and found a way to split the curves ?

Thank you

There is a bug in the plotting procedure if plotting a series of curves.

Even if you just ignore the linear backtracing lines, the output curves don’t resemble a MOSFET. There must be another bug, maybe in your measuring circuit.

What does the netlist look like?

Thank you for the reply. The curve on the graph is the Drain voltage.

Here is the netlist

.title KiCad schematic
.include “/home/olivier/Documents/électronique/Bass_Preamp/Kicad/SPICE/BS170.lib”
Vsupply VDD GND dc 24 ac 0 0
Vsignal Signal_In GND dc 0 ac 1 0 sin(0 100m 1k 0 0)
R1 VDD /Drain 24k
XQ1 /Drain Signal_In GND BS170
.save @vsupply[i]
.save @vsignal[i]
.save @r1[i]
.save V(/Drain)
.save V(GND)
.save V(Signal_In)
.save V(VDD)
.dc Vsignal 0 24 1m Vsupply 0 24 4
.end

And the BS170 model (the width and length were specified in the original file but not recognized by ngspice)

.SUBCKT BS170 1 2 3
Cgs 2 3 12.3E-12
Cgd1 2 4 27.4E-12
Cgd2 1 4 6E-12
M1 1 2 3 3 MOST1
M2 4 2 1 3 MOST2
D1 3 1 Dbody
*.MODEL MOST1 NMOS(Level=3 Kp=20.78u W=9.7m L=2u Rs=20m Vto=2 Rd=1.186)
*.MODEL MOST2 NMOS(VTO=-4.73 Kp=20.78u W=9.7m L=2u Rs=20m)
.MODEL MOST1 NMOS(Level=3 Kp=20.78u Rs=20m Vto=2 Rd=1.186)
.MODEL MOST2 NMOS(VTO=-4.73 Kp=20.78u Rs=20m)
.MODEL Dbody D(Is=125f N=1.023 Rs=1.281 Ikf=18.01 Cjo=46.3p M=.3423 Vj=.4519 Bv=60 Ibv=10u Tt=161.6n)
.ENDS

And my Kicad version

Application: kicad
Version: 5.0.2-bee76a0~70~ubuntu18.04.1, release build
Libraries:
wxWidgets 3.0.4
libcurl/7.58.0 OpenSSL/1.1.0g zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
Platform: Linux 4.15.0-50-generic x86_64, 64 bit, Little endian, wxGTK
Build Info:
wxWidgets: 3.0.4 (wchar_t,wx containers,compatible with 2.8) GTK+ 2.24
Boost: 1.65.1
OpenCASCADE Community Edition: 6.9.1
Curl: 7.58.0
Compiler: GCC 7.3.0 with C++ ABI 1011

Build settings:
USE_WX_GRAPHICS_CONTEXT=OFF
USE_WX_OVERLAY=OFF
KICAD_SCRIPTING=ON
KICAD_SCRIPTING_MODULES=ON
KICAD_SCRIPTING_WXPYTHON=OFF
KICAD_SCRIPTING_ACTION_MENU=ON
BUILD_GITHUB_PLUGIN=ON
KICAD_USE_OCE=ON
KICAD_USE_OCC=OFF
KICAD_SPICE=ON

To get W and L, you have to update to ngspice-30. Otherwise the resulting currents are much too low.

To get an output characteristics Id=f(Vds) with Vgs as parameter, comparable to what the data sheet says, you should add something like

.dc Vsupply 0 24 100m Vsignal 0 10 2

and reduce R1 to 1u, so it does not impede current flow.

I will report the plotting bug to the KiCAD bug tracker.

1 Like

An intermediate remedy to the W, L issue might be to modify the model a bit: Move the W, L statements from the .model line to the transistor instance line within the subcircuit:

.SUBCKT BS170 1 2 3
Cgs 2 3 12.3E-12
Cgd1 2 4 27.4E-12
Cgd2 1 4 6E-12
M1 1 2 3 3 MOST1 W=9.7m L=2u 
M2 4 2 1 3 MOST2 W=9.7m L=2u 
D1 3 1 Dbody
.MODEL MOST1 NMOS(Level=3 Kp=20.78u Rs=20m Vto=2 Rd=1.186)
.MODEL MOST2 NMOS(VTO=-4.73 Kp=20.78u Rs=20m)
.MODEL Dbody D(Is=125f N=1.023 Rs=1.281 Ikf=18.01 Cjo=46.3p M=.3423 Vj=.4519 Bv=60 Ibv=10u Tt=161.6n)
.ENDS

Thank you for your help !
I added the W and L parameters to the transistor and it works. For now I will work without the multiple plot output until the bug is fixed.
Thanks

The bug report is here: https://bugs.launchpad.net/kicad/+bug/1830478

The bug has been fixed, see the most recent nightlies.

1 Like

Awesome! Thanks for the heads up, man.