Create coupled inductors

below is the exscript from where I tried to create coupled inductors in skidl but couldn’t figure it out. Was able to create them in pyspice.

K | Coupled (Mutual) Inductors

PySpice/PySpice/Spice/; class CoupledInductor(AnyPinElement)

skidl/skidl/libs/; name=“K”

ngspice 3.2.11 Coupled (Mutual) Inductors:



  • need to get Dave’s help on using K inside skidl
  • the inductors must already exist for pyspice to work
net_1=Net('N1'); net_2=Net('N2') 
skidl_L1=L(ref='1', value=5, m=5, temp=5, dtemp=5, ic=5); skidl_L1['p', 'n']+=net_1, net_2 
skidl_L2=L(ref='2', value=5, m=5, temp=5, dtemp=5, ic=5); skidl_L2['p', 'n']+=net_1, net_2 
#need to find out how to use this 

No errors or warnings found during netlist generation.

.title L1 N1 N2 5 dtemp=5 ic=5 m=5 temp=5 L2 N1 N2 5 dtemp=5 ic=5 m=5 temp=5

#inductors need to exsist to then be coupled 
pyspice_circ.L('1', 'N1', 'N2', 5, m=5, temp=5, dtemp=5, ic=5) 
pyspice_circ.L('2', 'N1', 'N2', 5, m=5, temp=5, dtemp=5, ic=5) 
pyspice_circ.K('1', 'L1', 'L2', coupling_factor=5) 

.title L1 N1 N2 5 dtemp=5 ic=5 m=5 temp=5 L2 N1 N2 5 dtemp=5 ic=5 m=5 temp=5 K1 L1 L2 5

After more testing the following has been found.

  1. Any use of the kw defined in name=“K” kw’s: "kw": {"ind1": "ind1", "ind2": "ind2", "coupling": "coupling"} produces Value Error; ex K(coupling=2.5@u_H) yields ValueError: Unknown argument coupling=2.5

  2. using just a no argument (see issue from above) the generate_netlist yields a error; ex K(); generate_netlist() yields TypeError: can only concatenate str (not "NoneType") to str

Hi, Steve. I fixed the coupled inductors. Turns out PySpice uses different names for the function arguments than I thought. The fixes are in the development branch on GitHub. There is a new example of a transformer using the coupled inductors in the SPICE examples notebook.

1 Like