Try to clarify the mechanism of parameter substitution and add
an example of substituting an XSPICE vector parameter.
This commit is contained in:
parent
e130371410
commit
cf812da363
|
|
@ -0,0 +1,33 @@
|
|||
.TITLE SUBCKT VECTOR PARAM TEST
|
||||
* Example of passing a vector parameter to a sub-circuit.
|
||||
* Modified from https://sourceforge.net/p/ngspice/feature-requests/55/
|
||||
|
||||
* An AND gate impmented as a LUT in a subcircuit.
|
||||
|
||||
.param default_vec="[1e-12 2e-12]"
|
||||
*--vector parameter--
|
||||
.subckt testcir in0 in1 outlut testpar = {default_vec}
|
||||
|
||||
A_genlut [in0 in1] [outlut] genlut
|
||||
.model genlut d_genlut (
|
||||
+ input_delay = {testpar}
|
||||
+ table_values = "0001")
|
||||
|
||||
.ends testcir
|
||||
|
||||
V_Vss vss 0 DC 3.3
|
||||
V_pulse sine 0 DC 0 SIN(0 1 1000)
|
||||
|
||||
.param actual_vec="[1.3e-3 2e-3]"
|
||||
*--vector parameter--
|
||||
X_subckt no1 dss node3 testcir testpar={actual_vec}
|
||||
|
||||
A_ADC [sine vss] [no1 dss] ADC
|
||||
.model ADC adc_bridge(in_low=0.7 in_high=0.71)
|
||||
|
||||
.control
|
||||
tran 20u 4m
|
||||
plot sine node3
|
||||
.endc
|
||||
|
||||
.end
|
||||
|
|
@ -20,6 +20,11 @@ extern const struct nupa_type S_nupa_string;
|
|||
extern const struct nupa_type S_nupa_subckt;
|
||||
extern const struct nupa_type S_nupa_unknown;
|
||||
|
||||
/* Length of "numparam____ ..." string to be inserted and replaced. */
|
||||
|
||||
#define ACT_CHARACTS 25
|
||||
#define MARKER "numparm__________"
|
||||
|
||||
#define NUPA_REAL (&S_nupa_real)
|
||||
#define NUPA_STRING (&S_nupa_string)
|
||||
#define NUPA_SUBCKT (&S_nupa_subckt)
|
||||
|
|
|
|||
|
|
@ -121,8 +121,9 @@ stripbraces(DSTRINGPTR dstr_p)
|
|||
|
||||
cadd(&tstr, ' ');
|
||||
{
|
||||
char buf[25+1];
|
||||
sprintf(buf, "numparm__________%08lx", ++placeholder);
|
||||
char buf[ACT_CHARACTS + 1];
|
||||
|
||||
sprintf(buf, MARKER "%08lx", ++placeholder);
|
||||
sadd(&tstr, buf);
|
||||
}
|
||||
cadd(&tstr, ' ');
|
||||
|
|
|
|||
|
|
@ -23,8 +23,6 @@
|
|||
|
||||
extern long dynsubst; /* see inpcom.c */
|
||||
|
||||
#define ACT_CHARACTS 25 /* actual string length to be inserted and replaced */
|
||||
|
||||
#define S_init 0
|
||||
#define S_atom 1
|
||||
#define S_binop 2
|
||||
|
|
@ -1165,7 +1163,7 @@ static char *string_expr(dico_t *dico, DSTRINGPTR qstr_p,
|
|||
|
||||
/* stupid, produce a string representation of a given double
|
||||
* to be spliced back into the circuit deck
|
||||
* we want *exactly* 25 chars, we have
|
||||
* we want *exactly* 25 (ACT_CHARACTS) chars, we have
|
||||
* sign, leading digit, '.', 'e', sign, upto 3 digits exponent
|
||||
* ==> 8 chars, thus we have 17 left for precision
|
||||
* don't print a leading '+', something choked
|
||||
|
|
@ -1214,10 +1212,10 @@ insertnumber(dico_t *dico, char **lp, DSTRINGPTR ustr_p)
|
|||
long id = 0;
|
||||
int n;
|
||||
|
||||
char *p = strstr(s, "numparm__________");
|
||||
char *p = strstr(s, MARKER);
|
||||
|
||||
if (p &&
|
||||
(1 == sscanf(p, "numparm__________%8lx%n", &id, &n)) &&
|
||||
(1 == sscanf(p, MARKER "%8lx%n", &id, &n)) &&
|
||||
(n == ACT_CHARACTS) &&
|
||||
(id > 0) && (id < dynsubst + 1)) {
|
||||
/* Found a target for substitution. */
|
||||
|
|
|
|||
Loading…
Reference in New Issue