3

After being unable to get TI's CD4049UB PSpice model working in ngspice, I started using this 2-MOSFET CMOS circuit illustrated here to get my simulations at least close:

enter image description here

It has worked great for testing, but I'd prefer to fit that circuit's functionality into a library usable with KiCad's built-in 4049 component symbol (which has 7 units- the 6 inverters plus power), as illustrated for example here, with one inverter and the IC's power connections:

enter image description here

The problem is that I have no idea how to write the subcircuits required to fit this simple circuit, and no amount of reading docs and looking at examples makes it clearer to me. Particularly mysterious to me is how to get that 7th unit (power) in KiCad's 4049 symbol powering the 6 inverter instances in the IC.

Here's the complete netlist for a basic working example of my CMOS circuit:

.title KiCad schematic
M1 out in VCC VCC MPMOS
M2 out in 0 0 MNMOS
V1 VCC 0 9
V2 in 0 sin(4.5 4v 1k)
.model MNMOS NMOS level=8 version=3.3.3
.model MPMOS PMOS level=8 version=3.3.3
.tran 50u 10m
.end

Thanks in advance for any insight.

Gnaural
  • 161
  • 5
  • I don't have it near me now but I think you have to enter the symbol's properties and there you have an option to copy-paste a SPICE netlist. But don't quote me on that. – a concerned citizen Sep 13 '22 at 19:31

2 Answers2

2

After some tinkering, I was able to write some code that does everything asked for by putting the MOSFET pair in a nested subcircuit:

******************************************************************
* CD4094UB.lib
* Very simplified model of CD4049UB for use with ngspice & KiCad
* Written by Gnaural 20220817
*
* CD4049UB (in/out) pins: (3/2) (5/4) (7/6) (9/10) (11/12) (14/15) 
******************************************************************
.subckt CD4049 1 2 3 4 5 6 7 8 9 10 11 12 14 15
X1 3 2 1 8 INVERTER
X2 5 4 1 8 INVERTER
X3 7 6 1 8 INVERTER
X4 9 10 1 8 INVERTER
X5 11 12 1 8 INVERTER
X6 14 15 1 8 INVERTER
.ends CD4049

.subckt INVERTER in out VCC VSS
M1 out in VCC VCC MPMOS
M2 out in VSS VSS MNMOS
.model MNMOS NMOS level=8 version=3.3.3
.model MPMOS PMOS level=8 version=3.3.3
.ends INVERTER

I tested it with this circuit: enter image description here

It simulated as:

enter image description here

Gnaural
  • 161
  • 5
0

Running the inverter from CD4049UB.lib in ngspice is as easy as this:

CD4049 test
.include CD4049UB.lib
* Y A VCC AGND
Xinv out in VCC GND CD4049UB
VCC vcc 0 5
Vin in 0 dc 0 pulse  (0 5 1u 100n 100n 2u 4u)
.control
tran 0.1u 20u
plot in out
.endc
.end

In addition you have to add the line

set ngbehavior=psa

to the user initialization file .spiceinit to allow reading the PSPICE-compatible model file from TI.

Holger
  • 1