# Work with parameters

Parameters are symbolic variables used in circuit element expressions. There are five ways of assigning values or expressions to these parameters:

1. Using built-in parameter definitions

2. In the netlist using the SPICE ‘.PARAM’ directive

3. In python using the `circuit.defPar()` method

4. In python using the `pardefs` argument in an instruction

5. In python using the `specs2circuit()` function

Important

Do NOT use parameter names of which parts can be interpreted as expressions or numbers!

- `"C_100p"`

- `"R_sin(x)"`

## SLiCAP built-in parameters

Global Parameters

Global parameters are defined in the file `SLiCAPmodels.lib` in the folder given by `ini.main_lib_path`. If global parameters are found in circuit element expressions or in circuit parameter definitions, SLiCAP automatically adds their global definition to the circuit parameter definitions.

     1"SLiCAPmodels"
     2
     3* Physical constants
     4********************
     5
     6.param
     7+ q             = 1.60217662e-19    ; Electron charge in [C]
     8+ c             = 2.99792458e+08    ; Speed of light in [m/s]
     9+ mu_0          = {4*pi*1e-7}       ; Permeability of vacuum in [H/m]
    10+ epsilon_SiO2  = 3.9               ; Relative permittivity of SiO2 [-]
    11+ k             = 1.38064852e-23    ; Boltzmann constant in [J/K]
    12+ epsilon_0     = {1/mu_0/c^2}      ; permittivity of vacuum in [F/m]
    13
    14* Temperature and thermal voltage
    15*********************************
    16
    17.param
    18+ T             = 300               ; Default value of the absolute temperature in [K]
    19+ U_T           = {k*T/q}           ; Thermal voltage [V]

CMOS18 EKV model parameters

Built-in CMOS18 EKV model parameter definitions are included in `SLiCAP.lib` in the folder given by `ini.main_lib_path`.

     1* CMOS18 technology parameters for EKV models (SI units)
     2* DEFAULT EQUATIONS AND PARAMETERS taken from Binkley:
     3* "Tradeoffs and Optimization in Analog CMOS Design"
     4* Table 3.2
     5* Overlap capacitances set to typical values
     6* Early voltage per unit of length set to typical value
     7********************************************************
     8
     9.param
    10+ TOX_N18        = 4.1n    ; oxide thickness [m]
    11+ Vth_N18        = 0.42    ; threshold voltage [V]
    12+ N_s_N18        = 1.35    ; substrate factor [-]
    13+ Theta_N18      = 0.28    ; vertical field mobility reduction coefficient [1/V]
    14+ E_CRIT_N18     = 5.6M    ; lateral field strength for velocity saturation [V/m]
    15+ u_0_N18        = 42.2m   ; zero field carrier mobility [m^2/V/s]
    16+ CGBO_N18       = 1p      ; gate-bulk overlap capacitance [F/m]
    17+ CGSO_N18       = 300p    ; gate-source and gate-drain overlap capacitance [F/m]
    18+ CJB0_N18       = 1m      ; source/bulk drain/bulk capacitance [F/m^2]
    19+ LDS_N18        = 180n    ; length of drain and source [m]
    20+ KF_N18         = 3.2e-27 ; flicker noise (1/f noise) coefficient, zero for f_ell=0 [C/m^2]
    21+ AF_N18         = 0.85    ; flicker noise exponent [-]
    22+ V_KF_N18       = 1       ; flicker noise voltage dependency factor [V]
    23+ VAL_N18        = 20M     ; Early voltage per unit of length [V/m]
    24+ DVTDIBL_N18    = -0.008  ; dVth/dVDS
    25+ DVTIDBLEXP_N18 = 3       ; exponent of dVth/dVDS
    26+ beta_N18       = 0.8     ; Short channel effect exponent
    27+ L_min_N18      = 180n    ; minimum channel length
    28+ C_OX_N18       = {epsilon_0 * epsilon_SiO2 / TOX_N18}; oxide capacitance per unit of area [F/m^2]
    29+ I_0_N18        = {2*N_s_N18*u_0_N18*C_OX_N18*U_T^2}  ; technology current [A]
    30
    31.param
    32+ TOX_P18        = 4.1n    ; oxide thickness [m]
    33+ Vth_P18        = -0.42   ; threshold voltage [V]
    34+ N_s_P18        = 1.35    ; substrate factor [-]
    35+ Theta_P18      = 0.35    ; vertical field mobility reduction factor [1/V]
    36+ E_CRIT_P18     = 14M     ; lateral field strength for velocity saturation [V/m]
    37+ u_0_P18        = 8.92m   ; zero field carrier mobility [m^2/V/s]
    38+ CGBO_P18       = 1p      ; gate-bulk overlap capacitance [F/m]
    39+ CGSO_P18       = 300p    ; gate-source and gate-drain overlap capacitance [F/m]
    40+ CJB0_P18       = 1m      ; source/bulk drain/bulk capacitance [F/m^2]
    41+ LDS_P18        = 180n    ; length of drain and source [m]
    42+ KF_P18         = 2.4e-27 ; flicker noise (1/f noise) coefficient, zero for f_ell=0 [C^2/m^2]
    43+ AF_P18         = 1.05    ; flicker noise exponent [-]
    44+ V_KF_P18       = 0.25    ; flicker noise voltage dependency factor [V]
    45+ VAL_P18        = 20M     ; Early voltage per unit of length [V/m]
    46+ DVTDIBL_P18    = 0.01    ; dVth/dVDS
    47+ DVTIDBLEXP_P18 = 3       ; exponent of dVth/dVDS
    48+ beta_P18       = 0.9     ; Short channel effect exponent
    49+ L_min_P18      = 180n    ; minimum channel length
    50+ C_OX_P18       = {epsilon_0 * epsilon_SiO2 / TOX_P18}; oxide capacitance per unit of area [F/m^2]
    51+ I_0_P18        = {2*N_s_P18*u_0_P18*C_OX_P18*U_T^2} ; technology current [A]

SLiCAP Library files

Notice, a SLiCAP library is like a SLiCAP circuit file:

1. The first line after any line starting with `*` is considered the title of the library.

2. 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.

Table 4 RC circuit parameter definitions
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}\)

Table 5 RC circuit undefined parameters
Name
\(V_{s}\)