From 13e2f43c7c710293b21d9eddaa18e2415c119489 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Mon, 30 Jan 2023 11:54:26 +0100 Subject: [PATCH] add more documentation on parametric subcircuits --- doc/xschem_man/parameters.html | 2 +- doc/xschem_man/subckt_with_parameters.html | 148 ++++++++++++++++++++ doc/xschem_man/subckt_with_parameters01.png | Bin 0 -> 31814 bytes doc/xschem_man/subckt_with_parameters02.png | Bin 0 -> 38179 bytes doc/xschem_man/subckt_with_parameters03.png | Bin 0 -> 34303 bytes doc/xschem_man/xschem_man.html | 1 + 6 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 doc/xschem_man/subckt_with_parameters.html create mode 100644 doc/xschem_man/subckt_with_parameters01.png create mode 100644 doc/xschem_man/subckt_with_parameters02.png create mode 100644 doc/xschem_man/subckt_with_parameters03.png diff --git a/doc/xschem_man/parameters.html b/doc/xschem_man/parameters.html index 97a7a020..3517c9cc 100644 --- a/doc/xschem_man/parameters.html +++ b/doc/xschem_man/parameters.html @@ -17,7 +17,7 @@ p{padding: 15px 30px 10px;} UP - +

COMPONENT PARAMETERS


diff --git a/doc/xschem_man/subckt_with_parameters.html b/doc/xschem_man/subckt_with_parameters.html new file mode 100644 index 00000000..efa083e2 --- /dev/null +++ b/doc/xschem_man/subckt_with_parameters.html @@ -0,0 +1,148 @@ + + + +CREATING A PARAMETRIC SUBCIRCUIT + + + + + + + +

+ + +UP + + +

CREATING A PARAMETRIC SUBCIRCUIT


+

+ Let's suppose we want to design an OPAMP macromodel taking the following parameters: +

+ +

+ The image below shows the circuit. A 'B' voltage-type source with an hyperbolic tangent + function is used because it has continuous derivative and a realistic shape. +

+ +

+ after drawig the schematic a symbol is created. The easiest way is to press the 'a' key in the + schematic to automatically create the symbol, then descend into the symbol and do some artwork to + reshape it to represent an opamp.
+ After reshaping the symbol edit its global attributes and add handling of subcircuit parameters + in the format and template attributes as shown below: +

+ +

+ the symbol has the following global attributes: +

+
+type=subcircuit
+format="@name @pinlist @symname OFFSET=@OFFSET AMPLITUDE=@AMPLITUDE GAIN=@GAIN ROUT=@ROUT COUT=@COUT"
+template="name=x1 OFFSET=0 AMPLITUDE=5 GAIN=100 ROUT=1000 COUT=1p"
+ 
+

+ The format string defines how the instantiation will look in the spice netlist, + The following is the resulting spice netlist line and how it is generated from the format string: +

+
+    x1 REFD DRIVED IN comp_ngspice OFFSET=5 AMPLITUDE=10 GAIN=100 ROUT=1000 COUT=1p
+    -- -------------- ------------ -------- ------------ -------- --------- -------
+    |        |             |         |           |          |         |         |
+    |        |             |         |           |          |         |     COUT=@COUT
+    |        |             |         |           |          |     ROUT=@ROUT
+    |        |             |         |           |      GAIN=@GAIN
+    |        |             |         |           |
+    |        |             |         |  AMPLITUDE=@AMPLITUDE
+    |        |             |         |
+    |        |             |   OFFSET=@OFFSET
+    |        |        @symname
+    |        |
+    |      @pinlist
+  @name
+ 
+

+ The template string defines initial values for these parameters when you first instantiate this + component: +

+
+  template="name=x1 OFFSET=0 AMPLITUDE=5 GAIN=100 ROUT=1000 COUT=1p"
+ 
+ +

+ As you can see in above image the placed component has instance parameters set to the same values + listed in the template string. You may then change these values according yo your needs. + The values set in the instance affect that specific component instance behavior. Multiple instances + can be placed, each with it's own set of parameter values. + As you can see the @param values in the format string are replaced with the actual value set in + the instance attributes. +

+

+ When a netlist is generated the following lines are generated regarding this comp_ngspice symbol: +

+
+* sch_path: /home/schippes/xschem-repo/trunk/xschem_library/examples/classD_amp.sch
+...
+... other components ....
+...
+x1 REFD DRIVED IN comp_ngspice OFFSET=5 AMPLITUDE=10 GAIN=100 ROUT=1000 COUT=1
+...
+...
+*  expanding   symbol:  comp_ngspice.sym # of pins=3
+** sym_path: /home/schippes/xschem-repo/trunk/xschem_library/ngspice/comp_ngspice.sym
+** sch_path: /home/schippes/xschem-repo/trunk/xschem_library/ngspice/comp_ngspice.sch
+.subckt comp_ngspice PLUS OUT MINUS  OFFSET=0 AMPLITUDE=5 GAIN=100 ROUT=1000 COUT=1p
+*.ipin PLUS
+*.ipin MINUS
+*.opin OUT
+B1 IOUT 0 V = {OFFSET + AMPLITUDE/2*(tanh(V(IPLUS,IMINUS)*GAIN*2/AMPLITUDE))}
+R1 OUT IOUT ROUT m=1
+C3 OUT 0 COUT m=1
+V1 IPLUS PLUS 0
+.save i(v1)
+V2 IMINUS MINUS 0
+.save i(v2)
+.ends
+...
+...
+.end
+ 
+

+ You see the .subckt line contains the subcircuit parameters and their values: + The values present in the .subckt line are overridden by instance attribute values + if given. +

+
+.subckt comp_ngspice PLUS OUT MINUS  OFFSET=0 AMPLITUDE=5 GAIN=100 ROUT=1000 COUT=1p
+        ------------ --------------  -----------------------------------------------
+             |             |                              |
+             |             |                              |
+             |             |               parameters from template attributes:
+             |             |                              |
+             |             |                      _______________________________________________
+             |             |    template="name=x1 OFFSET=0 AMPLITUDE=5 GAIN=100 ROUT=1000 COUT=1p"
+             |         port list
+        symbol name
+ 
+
+
+ +
+
+ + +