Zaby1990
Zaby1990

Reputation: 31

ngspice difficulties to read a model of a diode

I'm new to SPICE and because I like to use opensource software, I tried ngspice. I have a simple circuit with some resistors, one capacitor and one diode. My code in the .cir-file looks like this:

Simulation of pushbutton for wake and wifi request

* Models  
  .include 1N4148.txt

* Netlist  
  V1 vcc GND 3.3
  C1 vcc gpio14 5u
  R1 vcc gpio14 10k
  R2 gpio14 Din 220R
  D1 Din Dout 1N4148
  V2 Dout GND 3.3 dc 0 pulse (0 3.3 1u 1u 1u 1 1)

* analysis  
  .control
  tran 50u 200m

plot vcc rst

.endc
.end

The model of the diode I found in the internet look like that (in txt-file 1N4148):

******************************************
*1N4148  
*VRRM = 100V  
*IFRM = 450 mA   
*trr  = 4ns  
*  
*Package: SOD 27  
*  
*Package Pin 1 : Cathode  
*Package Pin 2 : Anode  
*  
*Simulator: PSPICE  
*  
******************************************  
*
.SUBCKT 1N4148 1 2   
*
* The resistor R1 does not reflect   
* a physical device. Instead it  
* improves modeling in the reverse  
* mode of operation.  
*  
R1 1 2 5.827E+9   
D1 1 2 1N4148  
*
.MODEL 1N4148 D   
+ IS = 4.352E-9   
+ N = 1.906  
+ BV = 110  
+ IBV = 0.0001  
+ RS = 0.6458  
+ CJO = 7.048E-13  
+ VJ = 0.869   
+ M = 0.03  
+ FC = 0.5  
+ TT = 3.48E-9   
.ENDS

The output in ngspice is:

Note: Compatibility modes selected: ps a

warning, can't find model 'd' from line
    d1 din dout 1n4148 d

Circuit: simulation of bushbutton for wake and wifi request

Error on line 11 or its substitute:
  d1 din dout 1n4148 d
could not find a valid modelname
    Simulation interrupted due to error!

I don't get how to implement the included model right and frankly, I can't find a good tutorial in text or video. So maybe there is something wrong in my netlist or in my model or in my init-file (* user provided init file \n set ngbehavior=psa).

I really like to get a hint for my problem or a good tutorial with describes the combination of model definition and netlist definition. (maybe my english isn't good enough but also the user manual didn't help me)

For better understanding I tried to use different model names an type and tried to used them in front of the Diode-line like
Diod Din Dout 1N4148 or D1 Din Dout D and so on. I tried a lot of combinations....

Upvotes: 0

Views: 797

Answers (1)

Holger
Holger

Reputation: 11

Your diode model is a sub circuit model, which starts with the .subckt token and ends with the .ends token.

Subcircuit model are instantiated by an X line (see Ngspice manual, chapter 2.5).

So the diode line would read

XD 1 2 1N4148

where 1 is the anode, 2 is the cathode (opposite to the package pin number, indeed very confusing in the model file).

Other 1N4148 diode models from the web use a .model line like

.model 1N4148 D (...)

Only these models from a .model line are instantiated by

D1 1 2 1N4148

Upvotes: 1

Related Questions