Search code examples
parameterspspice

How to parameterize model type for Hspice subcircuits?


I have the following Hspice code:

.SUBCKT inv_slvt in out vdd
Mpmos  out  in    vdd  pmos_slvt
Mnmos  out  in    0    nmos_slvt
.ENDS

.SUBCKT inv_lvt in out vdd
Mpmos  out  in    vdd  pmos_lvt
Mnmos  out  in    0    nmos_lvt
.ENDS

Is there a way I can reduce the code to a single subcircuit definition, by parameterizing the suffix (i.e. - "slvt" vs. "lvt") of the model types?


Solution

  • You cannot parameterize a part of a model name, parameter or parameter value. However, you can parameterize the entire name. So, in your case, you would have to parameterize a MOSFET name to be either pmos_slvt, nmos_slvt, pmos_lvt, or nmos_lvt. Here is how you would go about it:

    .global vdd! gnd!
    
    * Defining the default values for parameters nmodel and pmodel
    .SUBCKT inv in out pmodel=str('pmos_lvt') nmodel=str('nmos_lvt')
       Mpmos  vdd! in out vdd!  str(pmodel)
       Mnmos  gnd! in out gnd!  str(nmodel)
    .ENDS
    
    Vvdd vdd! 0 dc=3.3
    Vgnd gnd! 0 dc=0
    
    Xinv in out inv pmodel=str('pmos_slvt') nmodel=str('nmos_slvt')
    

    When dealing with strings, their values should be passed as str('value'). For example:

    .PARAM par1 = str('nmos_180')
    

    When you want to use the value of a parameter holding a string, then you would use str(parameter_name), as shown below:

    .MODEL str(par1) nmos ...
    

    As a side note, I'd like to mention that you did not use the MOSFETs instance properly. MOSFET devices in Spice have 4 terminals: drain, gate, source, and bulk. You must use all four of them when instantiating a MOSFET device. In this case, you can make use of global nodes since they are available inside subcircuits. Global nodes don't have to have a bang in their name, but it's a good practice to do in order to make them easily identifiable for a designer.