src/xspice/icm/sherlockmbv/limitsmbv

This commit is contained in:
Jim Holmes 2014-10-04 14:32:16 +02:00 committed by rlar
parent d2b62de4c8
commit eccc3bbd77
6 changed files with 182 additions and 1 deletions

View File

@ -7,7 +7,7 @@ include makedefs
# The codemodels to make
CMDIRS = spice2poly digital analog xtradev xtraevt
CMDIRS = spice2poly digital analog xtradev xtraevt sherlockmbv
all:

12
src/xspice/icm/sherlockmbv/.gitignore vendored Normal file
View File

@ -0,0 +1,12 @@
/spice2poly.cm
/cmextrn.h
/cminfo.h
/dlmain.c
/objects.inc
/udnextrn.h
/udninfo.h
/*/*.c
!/*/udnfunc.c

View File

@ -0,0 +1,94 @@
#include <math.h>
void cm_limitsmbv(ARGS) /* structure holding parms,
inputs, outputs, etc. */
{
double x; /* Input Variable */
double xtp; /* Transition threshold from linear to exponention (positive side) */
double xtm; /* Transition threshold from linear to exponention (positive side) */
double y; /* Output Variable */
double xtpi; /* xtp limited to positive range */
double xtmi; /* xtm limited to negative range */
double g; /* Linear slope passing through x,y=0,0 */
double a; /* Term for exponetial regions below xtm and above xtp */
double Xg; /* Relation for continuous derivatives at xtm and xtp */
double Xo; /* Offset of exponentional terms for continuos derivatives */
Mif_Complex_t dy_dx; /* Complex partial derivative dy/dx */
Mif_Complex_t dy_dxtp; /* Complex partial derivative dy/dxtp */
Mif_Complex_t dy_dxtm; /* Complex partial derivative dy/dxtm */
/*
* Linear to Exponention Transistion Management
*/
g = PARAM(g);
a = PARAM(a);
if ( g > 0.0 ) {
Xg = log( g / a ) / a;
Xo = exp( a * Xg );
}
else {
Xg = 0.0;
Xo = 1.0;
}
/*
* Access the inputs from the interface
*/
x = INPUT(x);
xtp = INPUT(xtp);
xtm = INPUT(xtm);
/*
* Sanity check on dynamic thresholds.
*/
xtpi = (xtp >= 0.0) ? xtp : 0.0;
xtmi = (xtm <= 0.0) ? xtm : 0.0;
/*
* Ideal Avalanche Characteristic
*/
if (x >= xtpi) {
y = g * xtpi+exp(a * (x - xtpi+Xg)) - Xo;
dy_dx.real = a*exp(a * (x - xtpi+Xg));
dy_dxtp.real = g - a*exp(a * (x - xtpi+Xg));
dy_dxtm.real = 0.0;
}
else if (x <= xtmi) {
y = -1.0 * (g * fabs(xtmi)+exp(a * (fabs(x) - fabs(xtmi)+Xg)) - Xo);
dy_dx.real = -1.0*a*exp(a * (fabs(x) - fabs(xtmi)+Xg));;
dy_dxtp.real = 0.0;
dy_dxtm.real = -1.0*(g - a*exp(a * (fabs(x) - fabs(xtmi)+Xg)));
}
else {
y = g * x;
dy_dx.real = g;
dy_dxtp.real = 0.0;
dy_dxtm.real = 0.0;
}
/*
* Zero out the imaginary parts.
*/
dy_dx.imag = 0.0;
dy_dxtp.imag = 0.0;
dy_dxtm.imag = 0.0;
if (ANALYSIS != MIF_AC) { /* DC & Transient Analyses */
OUTPUT(y) = y;
PARTIAL(y,x) = dy_dx.real;
PARTIAL(y,xtp) = dy_dxtp.real;
PARTIAL(y,xtm) = dy_dxtm.real;
}
else { /* AC Analysis */
AC_GAIN(y,x) = dy_dx;
AC_GAIN(y,xtp) = dy_dxtp;
AC_GAIN(y,xtm) = dy_dxtm;
}
}

View File

@ -0,0 +1,74 @@
/*
* SUMMARY
* This file contains the interface specification file for the
* analog limit code model.
*
*/
NAME_TABLE:
C_Function_Name: cm_limitsmbv
Spice_Model_Name: limitsmbv
Description: "limit block"
PORT_TABLE:
Port_Name: x
Description: "input"
Direction: in
Default_Type: v
Allowed_Types: [v,vd,i,id,vnam]
Vector: no
Vector_Bounds: -
Null_Allowed: no
PORT_TABLE:
Port_Name: xtp
Description: "positive threshold"
Direction: in
Default_Type: v
Allowed_Types: [v,vd,i,id,vnam]
Vector: no
Vector_Bounds: -
Null_Allowed: no
PORT_TABLE:
Port_Name: xtm
Description: "negative threshold"
Direction: in
Default_Type: v
Allowed_Types: [v,vd,i,id,vnam]
Vector: no
Vector_Bounds: -
Null_Allowed: no
PORT_TABLE:
Port_Name: y
Description: "output"
Direction: out
Default_Type: v
Allowed_Types: [v,vd,i,id]
Vector: no
Vector_Bounds: -
Null_Allowed: no
PARAMETER_TABLE:
Parameter_Name: g
Description: "linear gain"
Data_Type: real
Default_Value: 1.0
Limits: -
Vector: no
Vector_Bounds: -
Null_Allowed: yes
PARAMETER_TABLE:
Parameter_Name: a
Description: "exponential gain"
Data_Type: real
Default_Value: 1.0
Limits: -
Vector: no
Vector_Bounds: -
Null_Allowed: yes

View File

@ -0,0 +1 @@
limitsmbv

View File