Work with parameters
Parameters are symbolic variables used in circuit element expressions. There are five ways of assigning values or expressions to these parameters:
Using built-in parameter definitions
In the netlist using the SPICE ‘.PARAM’ directive
In python using the
circuit.defPar()
methodIn python using the
pardefs
argument in an instructionIn python using the
specs2circuit()
function
SLiCAP built-in parameters
SLiCAP has a number of predefined parameters. These parameters include default CMOS18 EKV model parameters.
SLiCAP library files
Notice, a SLiCAP library it like a circuit definition. The first line after any line starting with
*
is considered the title of the library. The last line must read.end
Circuit parameters
SLiCAP output displayed on this manual page, is generated with the script: parameters.py
, imported by Manual.py
.
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3
4"""
5parameters.py: SLiCAP scripts for the HTML help file
6"""
7import SLiCAP as sl
8
9###############################################################################
10# work with parameters
11###############################################################################
We will use a simple RC network to demonstrate how to use parameters.
13# Define a circuit
14RC_cir = sl.makeCircuit("kicad/myFirstRCnetwork/myFirstRCnetwork.kicad_sch")
Get all circuit parameters
A listing of all circuit parameters can be obtained as follows:
16# Print the contents of the dictionary with circuit parameter definitions:
17if len(RC_cir.parDefs.keys()):
18 print("\nParameters with definitions:\n")
19 for key in RC_cir.parDefs.keys():
20 print(key, RC_cir.parDefs[key])
21else:
22 print("\nFound no parameter definitions")
23
24# Print the contents of the list with parameters that have no definition:
25if len(RC_cir.params):
26 print("\nParameters that have no definition:\n")
27 for param in RC_cir.params:
28 print(param)
29else:
30 print("\nFound no parameters without definition")
This yields:
Parameters with definitions:
R 1000
C 1/(2*pi*R*f_c)
f_c 1000
Parameters that have no definition:
V_s
Assign a value or an expression to a parameter
The method circuit.defPar() can be used to assign a value or an expression to a parameter.
32# Define parameters
33RC_cir.defPar('R', 'tau/C') # Define R = tau/C
34RC_cir.defPar('C', '10n') # Define C = 10 nF
35RC_cir.defPar('tau', '1u') # Define tau = 1 us
36print(RC_cir.parDefs)
This yields:
{R: tau/C, C: 1/100000000, f_c: 1000, tau: 1/1000000}
Assign values or expressions to multiple parameters
The method circuit.defPars() can be used to assign definitions to multiple parameters.
38# Define multiple parameters
39RC_cir.defPars({'R': 'tau/C', 'C': '10n', 'tau': '1/f_c'})
40print(RC_cir.parDefs)
This yields:
{R: tau/C, C: 1/100000000, f_c: 1000, tau: 1/f_c}
Delete a parameter definition
You can delete a parameter definition using the method circuit.delPar() . This method does not delete the circuit parameter itself, it only clears its definition so that it can be used as a symbolic variable.
42# Delete a parameter definition
43RC_cir.delPar('f_c') # Delete the definition of f_c
44
45# Print the contents of the dictionary with circuit parameter definitions:
46if len(RC_cir.parDefs.keys()):
47 print("\nParameters with definitions:\n")
48 for key in RC_cir.parDefs.keys():
49 print(key, RC_cir.parDefs[key])
50else:
51 print("\nFound no parameter definitions")
52
53# Print the contents of the list with parameters that have no definition:
54if len(RC_cir.params):
55 print("\nParameters that have no definition:\n")
56 for param in RC_cir.params:
57 print(param)
58else:
59 print("\nFound no parameters without definition")
This yields:
Parameters with definitions:
R tau/C
C 1/100000000
tau 1/f_c
Parameters that have no definition:
f_c
V_s
Obtain the value of a parameter
The method circuit.getParValue() returns the definition or the evaluated value of a parameter.
If the keyword argument substitute
is True (default), all circuit parameter definitions are recursively substituted until a final value or expression is obtained (see fullSubs)
If the keyword argument numeric
is True (default is False), functions and constants are numerically evaluated in floating point numbers.
61# Obtain the value of a parameter
62RC_cir.defPar('R', '1/2/pi/f_c/C') # Define the value of R
63RC_cir.defPar('C', '10n') # Define the value of C
64RC_cir.defPar('f_c', '1M') # Define the value of tau
65
66R_defined = RC_cir.getParValue('R', substitute=False, numeric=False)
67R_evaluated = RC_cir.getParValue('R', substitute=True, numeric=False)
68R_defined_numeric = RC_cir.getParValue('R', substitute=False, numeric=True)
69R_evaluated_numeric = RC_cir.getParValue('R', substitute=True, numeric=True)
70
71print('\nR_defined :', R_defined)
72print('R_evaluated :', R_evaluated)
73print('R_defined_numeric :', R_defined_numeric)
74print('R_evaluated_numeric :', R_evaluated_numeric)
This yields:
R_defined : 1/(2*pi*C*f_c)
R_evaluated : 50/pi
R_defined_numeric : 0.159154943091895/(C*f_c)
R_evaluated_numeric : 15.9154943091895
Obtain the values of multiple parameters
With a list of parameter names as argument, the method circuit.getParValue() returns a dictionary with key-value pairs. The keys are the names of the parameters and the values their defenition or evaluation of it.
If the keyword argument substitute
is True (default), for each parameter, all circuit parameter definitions are recursively substituted until a final value or expression is obtained (see fullSubs)
If the keyword argument numeric
is True (default is False), functions and constants are numerically evaluated in floating point numbers.
76# Obtain the values of multiple parameters
77print(RC_cir.getParValue(['R','C'], substitute=False, numeric=False))
78print(RC_cir.getParValue(['R','C'], substitute=False, numeric=True))
79print(RC_cir.getParValue(['R','C'], substitute=True, numeric=False))
80print(RC_cir.getParValue(['R','C'], substitute=True, numeric=True))
This yields:
{R: 1/(2*pi*C*f_c), C: 1/100000000}
{R: 0.159154943091895/(C*f_c), C: 1.00000000000000e-8}
{R: 50/pi, C: 1/100000000}
{R: 15.9154943091895, C: 1.00000000000000e-8}
Display tables with parameters on HTML pages or in LaTeX documents
With the aid of the report module Create reports, tables with circuit parameter definitions and tables with undefined circuit parameters can be displayed on HTML pages or in LaTeX documents.
Below the script for generating table rst snippets for this help file.
82# Generate RST snippets of tables with parameters for the Help file
83rst = sl.RSTformatter()
84
85rst.parDefs(RC_cir,
86 caption="RC circuit parameter definitions").save("table-RC_pardefs")
87rst.params(RC_cir,
88 caption="RC circuit undefined parameters").save("table-RC_params")
Below, both tables for the RC circuit.
Name |
Symbolic |
Numeric |
---|---|---|
\(R\) |
\(\frac{0.5}{\pi C f_{c}}\) |
\(15.92\) |
\(C\) |
\(1.0 \cdot 10^{-8}\) |
\(1.0 \cdot 10^{-8}\) |
\(\tau\) |
\(\frac{1}{f_{c}}\) |
\(1.0 \cdot 10^{-6}\) |
\(f_{c}\) |
\(1.0 \cdot 10^{6}\) |
\(1.0 \cdot 10^{6}\) |
Name |
---|
\(V_{s}\) |