From 2bbfdd55cb8eb52a1056114658764918b3916128 Mon Sep 17 00:00:00 2001 From: rlar Date: Mon, 30 Dec 2013 17:18:29 +0100 Subject: [PATCH] analog/{sine,square,triangle}, xtradev/core, whitespace cleanup --- src/xspice/icm/analog/sine/cfunc.mod | 230 ++++++------ src/xspice/icm/analog/sine/ifspec.ifs | 42 +-- src/xspice/icm/analog/sine/sin.h | 30 +- src/xspice/icm/analog/square/cfunc.mod | 240 ++++++------ src/xspice/icm/analog/square/ifspec.ifs | 64 ++-- src/xspice/icm/analog/square/square.h | 28 +- src/xspice/icm/analog/triangle/cfunc.mod | 218 +++++------ src/xspice/icm/analog/triangle/ifspec.ifs | 58 +-- src/xspice/icm/analog/triangle/triangle.h | 26 +- src/xspice/icm/xtradev/core/cfunc.mod | 423 ++++++++++------------ src/xspice/icm/xtradev/core/core.h | 8 +- src/xspice/icm/xtradev/core/ifspec.ifs | 134 +++---- 12 files changed, 701 insertions(+), 800 deletions(-) diff --git a/src/xspice/icm/analog/sine/cfunc.mod b/src/xspice/icm/analog/sine/cfunc.mod index 76187da08..1419dd069 100644 --- a/src/xspice/icm/analog/sine/cfunc.mod +++ b/src/xspice/icm/analog/sine/cfunc.mod @@ -53,39 +53,28 @@ NON-STANDARD FEATURES #include "sin.h" #include - - +#include /*=== CONSTANTS ========================*/ - - /*=== MACROS ===========================*/ - - /*=== LOCAL VARIABLES & TYPEDEFS =======*/ - typedef struct { - - double *control; /* the storage array for the - control vector (cntl_array) */ - - double *freq; /* the storage array for the - frequency vector (freq_array) */ + double *control; /* the storage array for the + control vector (cntl_array) */ + double *freq; /* the storage array for the + frequency vector (freq_array) */ } Local_Data_t; /*=== FUNCTION PROTOTYPE DEFINITIONS ===*/ - - - /*============================================================================== FUNCTION void cm_sine() @@ -126,156 +115,143 @@ NON-STANDARD FEATURES NONE ==============================================================================*/ -#include /*=== CM_SINE ROUTINE ===*/ -void cm_sine(ARGS) /* structure holding parms, - inputs, outputs, etc. */ +void +cm_sine(ARGS) { - int i; /* generic loop counter index */ - int cntl_size; /* control array size */ - int freq_size; /* frequency array size */ + int i; /* generic loop counter index */ + int cntl_size; /* control array size */ + int freq_size; /* frequency array size */ - double *x; /* pointer to the control array values */ - double *y; /* pointer to the frequency array values */ - double cntl_input; /* control input */ - /*double out;*/ /* output value */ - double dout_din; /* partial derivative of output wrt control in */ - double output_low; /* output low value */ - double output_hi; /* output high value */ - double *phase; /* pointer to the instantaneous phase value */ - double *phase1; /* pointer to the previous value for the phase */ - double freq=0.0; /* frequency of the sine wave */ - double center; /* dc offset for the sine wave */ - double peak; /* peak voltage value for the wave */ - double radian; /* phase value in radians */ + double *x; /* pointer to the control array values */ + double *y; /* pointer to the frequency array values */ + double cntl_input; /* control input */ + double dout_din; /* partial derivative of output wrt control in */ + double output_low; /* output low value */ + double output_hi; /* output high value */ + double *phase; /* pointer to the instantaneous phase value */ + double *phase1; /* pointer to the previous value for the phase */ + double freq=0.0; /* frequency of the sine wave */ + double center; /* dc offset for the sine wave */ + double peak; /* peak voltage value for the wave */ + double radian; /* phase value in radians */ Mif_Complex_t ac_gain; - Local_Data_t *loc; /* Pointer to local static data, not to be included - in the state vector */ - + Local_Data_t *loc; /* Pointer to local static data, not to be included + in the state vector */ /**** Retrieve frequently used parameters... ****/ - - cntl_size = PARAM_SIZE(cntl_array); - freq_size = PARAM_SIZE(freq_array); + cntl_size = PARAM_SIZE(cntl_array); + freq_size = PARAM_SIZE(freq_array); output_low = PARAM(out_low); - output_hi = PARAM(out_high); + output_hi = PARAM(out_high); - if(cntl_size != freq_size){ - cm_message_send(array_error); - return; - } - - if(INIT == 1){ - - cm_analog_alloc(INT1,sizeof(double)); - - - /*** allocate static storage for *loc ***/ - STATIC_VAR (locdata) = calloc (1 , sizeof ( Local_Data_t )); - loc = STATIC_VAR (locdata); - - - /* Allocate storage for breakpoint domain & freq. range values */ - x = loc->control = (double *) calloc((size_t) cntl_size, sizeof(double)); - if (!x) { - cm_message_send(allocation_error); - return; - } - y = loc->freq = (double *) calloc((size_t) freq_size, sizeof(double)); - if (!y) { - cm_message_send(allocation_error); + if (cntl_size != freq_size) { + cm_message_send(array_error); return; } + if (INIT == 1) { - } + cm_analog_alloc(INT1, sizeof(double)); - if(ANALYSIS == MIF_DC){ + /*** allocate static storage for *loc ***/ + STATIC_VAR(locdata) = calloc(1, sizeof(Local_Data_t)); + loc = STATIC_VAR(locdata); - OUTPUT(out) = (output_hi + output_low)/2; - PARTIAL(out,cntl_in) = 0; - phase = (double *) cm_analog_get_ptr(INT1,0); - *phase = 0; + /* Allocate storage for breakpoint domain & freq. range values */ + x = loc->control = (double *) calloc((size_t) cntl_size, sizeof(double)); + if (!x) { + cm_message_send(allocation_error); + return; + } + y = loc->freq = (double *) calloc((size_t) freq_size, sizeof(double)); + if (!y) { + cm_message_send(allocation_error); + return; + } - }else - - if(ANALYSIS == MIF_TRAN){ - - phase = (double *) cm_analog_get_ptr(INT1,0); - phase1 = (double *) cm_analog_get_ptr(INT1,1); - - loc = STATIC_VAR (locdata); - x = loc->control; - y = loc->freq; - - /* Retrieve x and y values. */ - for (i=0; icontrol; + y = loc->freq; - if (cntl_input >= x[cntl_size-1]){ + /* Retrieve x and y values. */ + for (i = 0; i < cntl_size; i++) { + x[i] = PARAM(cntl_array[i]); + y[i] = PARAM(freq_array[i]); + } + + /* Retrieve cntl_input value. */ + cntl_input = INPUT(cntl_in); + + /* Determine segment boundaries within which cntl_input resides */ + if (cntl_input <= *x) { + + /*** cntl_input below lowest cntl_voltage ***/ + dout_din = (y[1] - y[0]) / (x[1] - x[0]); + freq = *y + (cntl_input - *x) * dout_din; + + if (freq <= 0) { + cm_message_send(sine_freq_clamp); + freq = 1e-16; + } + + } else if (cntl_input >= x[cntl_size-1]) { + + /*** cntl_input above highest cntl_voltage ***/ dout_din = (y[cntl_size-1] - y[cntl_size-2]) / - (x[cntl_size-1] - x[cntl_size-2]); + (x[cntl_size-1] - x[cntl_size-2]); freq = y[cntl_size-1] + (cntl_input - x[cntl_size-1]) * dout_din; - } else { /*** cntl_input within bounds of end midpoints... - must determine position progressively & then - calculate required output. ***/ + } else { - for (i=0; i= x[i])) { - - /* Interpolate to the correct frequency value */ - - freq = ((cntl_input - x[i])/(x[i+1] - x[i]))* - (y[i+1]-y[i]) + y[i]; + /* Interpolate to the correct frequency value */ + freq = ((cntl_input - x[i]) / (x[i+1] - x[i])) * + (y[i+1] - y[i]) + y[i]; } - - } } -/* calculate the peak value of the wave, the center of the wave, the - instantaneous phase and the radian value of the phase */ - peak = (output_hi - output_low)/2; - center = (output_hi + output_low)/2; - *phase = *phase1 + freq*(TIME - T(1)); - radian = *phase * 2.0 * PI; - OUTPUT(out) = peak*sin(radian) + center; - PARTIAL(out,cntl_in) = 0; + /* calculate the peak value of the wave, the center of the wave, the + instantaneous phase and the radian value of the phase */ + peak = (output_hi - output_low) / 2; + center = (output_hi + output_low) / 2; - } else { /* Output AC Gain */ + *phase = *phase1 + freq*(TIME - T(1)); + radian = *phase * 2.0 * PI; + + OUTPUT(out) = peak * sin(radian) + center; + PARTIAL(out, cntl_in) = 0; + + } else { /* Output AC Gain */ ac_gain.real = 0.0; - ac_gain.imag= 0.0; - AC_GAIN(out,cntl_in) = ac_gain; + ac_gain.imag = 0.0; + AC_GAIN(out, cntl_in) = ac_gain; + } } - diff --git a/src/xspice/icm/analog/sine/ifspec.ifs b/src/xspice/icm/analog/sine/ifspec.ifs index f505a3fef..94f0345ed 100644 --- a/src/xspice/icm/analog/sine/ifspec.ifs +++ b/src/xspice/icm/analog/sine/ifspec.ifs @@ -4,18 +4,18 @@ Copyright 1991 Georgia Tech Research Corporation, Atlanta, Ga. 30332 All Rights Reserved -AUTHORS +AUTHORS 20 Mar 1991 Harry Li SUMMARY - This file contains the interface specification file for the + This file contains the interface specification file for the analog sine (controlled sinewave oscillator) code model. ===============================================================================*/ - + NAME_TABLE: @@ -26,37 +26,37 @@ Description: "controlled sine wave oscillator" PORT_TABLE: -Port_Name: cntl_in out +Port_Name: cntl_in out Description: "input" "output" -Direction: in out +Direction: in out Default_Type: v v -Allowed_Types: [v,vd,i,id,vnam] [v,vd,i,id] +Allowed_Types: [v,vd,i,id,vnam] [v,vd,i,id] Vector: no no -Vector_Bounds: - - -Null_Allowed: no no +Vector_Bounds: - - +Null_Allowed: no no PARAMETER_TABLE: -Parameter_Name: cntl_array freq_array +Parameter_Name: cntl_array freq_array Description: "control in array" "frequency array" -Data_Type: real real -Default_Value: 0.0 1.0e3 -Limits: - [0 -] -Vector: yes yes -Vector_Bounds: [2 -] [2 -] -Null_Allowed: no no +Data_Type: real real +Default_Value: 0.0 1.0e3 +Limits: - [0 -] +Vector: yes yes +Vector_Bounds: [2 -] [2 -] +Null_Allowed: no no PARAMETER_TABLE: Parameter_Name: out_low out_high Description: "output low value" "output high value" -Data_Type: real real -Default_Value: -1.0 1.0 -Limits: - - -Vector: no no -Vector_Bounds: - - -Null_Allowed: yes yes +Data_Type: real real +Default_Value: -1.0 1.0 +Limits: - - +Vector: no no +Vector_Bounds: - - +Null_Allowed: yes yes STATIC_VAR_TABLE: diff --git a/src/xspice/icm/analog/sine/sin.h b/src/xspice/icm/analog/sine/sin.h index ea79bb393..8c013d45f 100644 --- a/src/xspice/icm/analog/sine/sin.h +++ b/src/xspice/icm/analog/sine/sin.h @@ -8,17 +8,17 @@ Georgia Tech Research Corporation, Atlanta, Ga. 30332 All Rights Reserved PROJECT A-8503-405 - -AUTHORS + +AUTHORS 20 Mar 1991 Harry Li -MODIFICATIONS +MODIFICATIONS 2 Oct 1991 Jeffrey P. Murray - + SUMMARY @@ -26,9 +26,9 @@ SUMMARY sine code model. -INTERFACES +INTERFACES - FILE ROUTINE CALLED + FILE ROUTINE CALLED N/A N/A @@ -36,7 +36,7 @@ INTERFACES REFERENCED FILES NONE - + NON-STANDARD FEATURES @@ -47,12 +47,12 @@ NON-STANDARD FEATURES /*=== INCLUDE FILES ====================*/ - + /*=== CONSTANTS ========================*/ #define PI 3.141592654; - + #define INT1 1 char *allocation_error = "\n**** Error ****\nSINE: Error allocating sine block storage \n"; @@ -66,14 +66,10 @@ char *array_error = "\n**** Error ****\nSINE: Size of control array different th - -/*=== LOCAL VARIABLES & TYPEDEFS =======*/ + +/*=== LOCAL VARIABLES & TYPEDEFS =======*/ + + - - /*=== FUNCTION PROTOTYPE DEFINITIONS ===*/ - - - - diff --git a/src/xspice/icm/analog/square/cfunc.mod b/src/xspice/icm/analog/square/cfunc.mod index 32bbd8426..c717f9896 100644 --- a/src/xspice/icm/analog/square/cfunc.mod +++ b/src/xspice/icm/analog/square/cfunc.mod @@ -51,43 +51,29 @@ NON-STANDARD FEATURES /*=== INCLUDE FILES ====================*/ +#include #include "square.h" - /*=== CONSTANTS ========================*/ - - /*=== MACROS ===========================*/ - - /*=== LOCAL VARIABLES & TYPEDEFS =======*/ - - typedef struct { - - double *control; /* the storage array for the - control vector (cntl_array) */ - - double *freq; /* the storage array for the - pulse width array (pw_array) */ - - Boolean_t tran_init; /* for initialization of phase1) */ - + double *control; /* the storage array for the + control vector (cntl_array) */ + double *freq; /* the storage array for the + pulse width array (pw_array) */ + Boolean_t tran_init; /* for initialization of phase1) */ } Local_Data_t; /*=== FUNCTION PROTOTYPE DEFINITIONS ===*/ - - - - /*============================================================================== FUNCTION void cm_square() @@ -129,7 +115,6 @@ NON-STANDARD FEATURES NONE ==============================================================================*/ -#include /*=== CM_SQUARE ROUTINE ===*/ @@ -156,43 +141,42 @@ NON-STANDARD FEATURES * * ***********************************************************/ -void cm_square(ARGS) /* structure holding parms, - inputs, outputs, etc. */ +void +cm_square(ARGS) { - int i; /* generic loop counter index */ - int cntl_size; /* control array size */ - int freq_size; /* frequency array size */ - int int_cycle; /* integer number of cycles */ + int i; /* generic loop counter index */ + int cntl_size; /* control array size */ + int freq_size; /* frequency array size */ + int int_cycle; /* integer number of cycles */ - double *x; /* pointer to the control array values */ - double *y; /* pointer to the frequecy array values */ - double cntl_input; /* control input */ - /*double out;*/ /* output */ - double dout_din; /* slope of the frequency array wrt the control - array. Used to extrapolate a frequency above - and below the control input high and low level */ - double output_low; /* output low */ - double output_hi; /* output high */ - double dphase; /* fractional part into cycle */ - double *phase; /* pointer to the phase value */ - double *phase1; /* pointer to the old phase value */ - double freq=0.0; /* frequency of the wave */ - double d_cycle; /* duty cycle */ - double *t1; /* pointer containing the value of time1 */ - double *t2; /* pointer containing the value of time2 */ - double *t3; /* pointer containing the value of time3 */ - double *t4; /* pointer containing the value of time4 */ - double time1; /* time1 = duty_cycle * period of the wave */ - double time2; /* time2 = time1 + risetime */ - double time3; /* time3 = current time+time to end of period*/ - double time4; /* time4 = time3 + falltime */ - double t_rise; /* risetime */ - double t_fall; /* falltime */ + double *x; /* pointer to the control array values */ + double *y; /* pointer to the frequecy array values */ + double cntl_input; /* control input */ + double dout_din; /* slope of the frequency array wrt the control + array. Used to extrapolate a frequency above + and below the control input high and low level */ + double output_low; /* output low */ + double output_hi; /* output high */ + double dphase; /* fractional part into cycle */ + double *phase; /* pointer to the phase value */ + double *phase1; /* pointer to the old phase value */ + double freq = 0.0; /* frequency of the wave */ + double d_cycle; /* duty cycle */ + double *t1; /* pointer containing the value of time1 */ + double *t2; /* pointer containing the value of time2 */ + double *t3; /* pointer containing the value of time3 */ + double *t4; /* pointer containing the value of time4 */ + double time1; /* time1 = duty_cycle * period of the wave */ + double time2; /* time2 = time1 + risetime */ + double time3; /* time3 = current time+time to end of period*/ + double time4; /* time4 = time3 + falltime */ + double t_rise; /* risetime */ + double t_fall; /* falltime */ Mif_Complex_t ac_gain; - Local_Data_t *loc; /* Pointer to local static data, not to be included - in the state vector */ + Local_Data_t *loc; /* Pointer to local static data, not to be included + in the state vector */ /**** Retrieve frequently used parameters... ****/ @@ -207,22 +191,22 @@ void cm_square(ARGS) /* structure holding parms, /* check and make sure that the control array is the same size as the frequency array */ - if(cntl_size != freq_size) { + if (cntl_size != freq_size) { cm_message_send(square_array_error); return; } /* First time throught allocate memory */ - if(INIT==1) { - cm_analog_alloc(INT1,sizeof(double)); - cm_analog_alloc(T1,sizeof(double)); - cm_analog_alloc(T2,sizeof(double)); - cm_analog_alloc(T3,sizeof(double)); - cm_analog_alloc(T4,sizeof(double)); + if (INIT == 1) { + cm_analog_alloc(INT1, sizeof(double)); + cm_analog_alloc(T1, sizeof(double)); + cm_analog_alloc(T2, sizeof(double)); + cm_analog_alloc(T3, sizeof(double)); + cm_analog_alloc(T4, sizeof(double)); /*** allocate static storage for *loc ***/ - STATIC_VAR (locdata) = calloc (1 , sizeof ( Local_Data_t )); - loc = STATIC_VAR (locdata); + STATIC_VAR(locdata) = calloc(1, sizeof(Local_Data_t)); + loc = STATIC_VAR(locdata); /* Allocate storage for breakpoint domain & pulse width values */ x = loc->control = (double *) calloc((size_t) cntl_size, sizeof(double)); @@ -237,16 +221,15 @@ void cm_square(ARGS) /* structure holding parms, } loc->tran_init = FALSE; - } - if(ANALYSIS == MIF_DC) { + if (ANALYSIS == MIF_DC) { /* initialize time values */ - t1 = (double *) cm_analog_get_ptr(T1,0); - t2 = (double *) cm_analog_get_ptr(T2,0); - t3 = (double *) cm_analog_get_ptr(T3,0); - t4 = (double *) cm_analog_get_ptr(T4,0); + t1 = (double *) cm_analog_get_ptr(T1, 0); + t2 = (double *) cm_analog_get_ptr(T2, 0); + t3 = (double *) cm_analog_get_ptr(T3, 0); + t4 = (double *) cm_analog_get_ptr(T4, 0); *t1 = -1; *t2 = -1; @@ -254,25 +237,26 @@ void cm_square(ARGS) /* structure holding parms, *t4 = -1; OUTPUT(out) = output_low; - PARTIAL(out,cntl_in) = 0; + PARTIAL(out, cntl_in) = 0; - } else if(ANALYSIS == MIF_TRAN) { + } else if (ANALYSIS == MIF_TRAN) { /* Retrieve previous values */ - phase = (double *) cm_analog_get_ptr(INT1,0); - phase1 = (double *) cm_analog_get_ptr(INT1,1); - t1 = (double *) cm_analog_get_ptr(T1,1); - t2 = (double *) cm_analog_get_ptr(T2,1); - t3 = (double *) cm_analog_get_ptr(T3,1); - t4 = (double *) cm_analog_get_ptr(T4,1); + phase = (double *) cm_analog_get_ptr(INT1, 0); + phase1 = (double *) cm_analog_get_ptr(INT1, 1); + + t1 = (double *) cm_analog_get_ptr(T1, 1); + t2 = (double *) cm_analog_get_ptr(T2, 1); + t3 = (double *) cm_analog_get_ptr(T3, 1); + t4 = (double *) cm_analog_get_ptr(T4, 1); time1 = *t1; time2 = *t2; time3 = *t3; time4 = *t4; - loc = STATIC_VAR (locdata); + loc = STATIC_VAR(locdata); x = loc->control; y = loc->freq; @@ -282,7 +266,7 @@ void cm_square(ARGS) /* structure holding parms, } /* Retrieve x and y values. */ - for (i=0; i= x[cntl_size-1]) { + /*** cntl_input above highest cntl_voltage ***/ dout_din = (y[cntl_size-1] - y[cntl_size-2]) / - (x[cntl_size-1] - x[cntl_size-2]); + (x[cntl_size-1] - x[cntl_size-2]); freq = y[cntl_size-1] + (cntl_input - x[cntl_size-1]) * dout_din; - /* freq = y[cntl_size-1]; */ } else { /*** cntl_input within bounds of end midpoints... - must determine position progressively & then - calculate required output. ***/ + must determine position progressively & then + calculate required output. ***/ - for (i=0; i= x[i])) { /* Interpolate to the correct frequency value */ - freq = ((cntl_input - x[i])/(x[i+1] - x[i]))* - (y[i+1]-y[i]) + y[i]; + freq = ((cntl_input - x[i])/(x[i+1] - x[i])) * + (y[i+1]-y[i]) + y[i]; } } + } + /* calculate the instantaneous phase */ *phase = *phase1 + freq*(TIME - T(1)); /* convert the phase to an integer */ - int_cycle = (int)*phase1; + int_cycle = (int) *phase1; /* dphase is the percent into the cycle for the period */ dphase = *phase1 - int_cycle; /* Calculate the time variables and the output value - for this iteration */ + for this iteration */ - if((time1 <= TIME) && (TIME <= time2)) { - time3 = T(1) + (1 - dphase)/freq; + if ((time1 <= TIME) && (TIME <= time2)) { + + time3 = T(1) + (1 - dphase) / freq; time4 = time3 + t_fall; - if(TIME < time2) { + if (TIME < time2) cm_analog_set_temp_bkpt(time2); - } cm_analog_set_temp_bkpt(time3); cm_analog_set_temp_bkpt(time4); - OUTPUT(out) = output_low + ((TIME - time1)/(time2 - time1))* - (output_hi - output_low); + OUTPUT(out) = output_low + ((TIME - time1) / (time2 - time1)) * + (output_hi - output_low); - } else if((time2 <= TIME) && (TIME <= time3)) { + } else if ((time2 <= TIME) && (TIME <= time3)) { - time3 = T(1) + (1.0 - dphase)/freq; + time3 = T(1) + (1.0 - dphase) / freq; time4 = time3 + t_fall; - if(TIME < time3) { + + if (TIME < time3) cm_analog_set_temp_bkpt(time3); - } + cm_analog_set_temp_bkpt(time4); + OUTPUT(out) = output_hi; - } else if((time3 <= TIME) && (TIME <= time4)) { + } else if ((time3 <= TIME) && (TIME <= time4)) { - if(dphase > 1-d_cycle) { + if (dphase > 1 - d_cycle) dphase = dphase - 1.0; - } /* subtract d_cycle from 1 because my initial definition - of duty cyle was that part of the cycle which the output - is low. The more standard definition is the part of the - cycle where the output is high. */ - time1 = T(1) + ((1-d_cycle) - dphase)/freq; + of duty cyle was that part of the cycle which the output + is low. The more standard definition is the part of the + cycle where the output is high. */ + time1 = T(1) + ((1-d_cycle) - dphase) / freq; time2 = time1 + t_rise; - if(TIME < time4) { + if (TIME < time4) cm_analog_set_temp_bkpt(time4); - } cm_analog_set_temp_bkpt(time1); cm_analog_set_temp_bkpt(time2); - OUTPUT(out) = output_hi + ((TIME - time3)/(time4 - time3))* - (output_low - output_hi); + OUTPUT(out) = output_hi + ((TIME - time3) / (time4 - time3)) * + (output_low - output_hi); } else { - if(dphase > 1-d_cycle) { + if (dphase > 1 - d_cycle) dphase = dphase - 1.0; - } /* subtract d_cycle from 1 because my initial definition - of duty cyle was that part of the cycle which the output - is low. The more standard definition is the part of the - cycle where the output is high. */ - time1 = T(1) + ((1-d_cycle) - dphase)/freq; + of duty cyle was that part of the cycle which the output + is low. The more standard definition is the part of the + cycle where the output is high. */ + time1 = T(1) + ((1-d_cycle) - dphase) / freq; time2 = time1 + t_rise; - if((TIME < time1) || (T(1) == 0)) { + if ((TIME < time1) || (T(1) == 0)) cm_analog_set_temp_bkpt(time1); - } cm_analog_set_temp_bkpt(time2); + OUTPUT(out) = output_low; + } - PARTIAL(out,cntl_in) = 0.0; + PARTIAL(out, cntl_in) = 0.0; /* set the time values for storage */ - t1 = (double *) cm_analog_get_ptr(T1,0); - t2 = (double *) cm_analog_get_ptr(T2,0); - t3 = (double *) cm_analog_get_ptr(T3,0); - t4 = (double *) cm_analog_get_ptr(T4,0); + t1 = (double *) cm_analog_get_ptr(T1, 0); + t2 = (double *) cm_analog_get_ptr(T2, 0); + t3 = (double *) cm_analog_get_ptr(T3, 0); + t4 = (double *) cm_analog_get_ptr(T4, 0); *t1 = time1; *t2 = time2; @@ -425,8 +410,7 @@ void cm_square(ARGS) /* structure holding parms, /* This model has no AC capabilities */ ac_gain.real = 0.0; - ac_gain.imag= 0.0; - AC_GAIN(out,cntl_in) = ac_gain; + ac_gain.imag = 0.0; + AC_GAIN(out, cntl_in) = ac_gain; } } - diff --git a/src/xspice/icm/analog/square/ifspec.ifs b/src/xspice/icm/analog/square/ifspec.ifs index 5547e702c..27559c116 100644 --- a/src/xspice/icm/analog/square/ifspec.ifs +++ b/src/xspice/icm/analog/square/ifspec.ifs @@ -4,18 +4,18 @@ Copyright 1991 Georgia Tech Research Corporation, Atlanta, Ga. 30332 All Rights Reserved -AUTHORS +AUTHORS 12 Apr 1991 Harry Li SUMMARY - This file contains the interface specification file for the + This file contains the interface specification file for the analog square (controlled squarewave oscillator) code model. ===============================================================================*/ - + NAME_TABLE: @@ -26,56 +26,56 @@ Description: "controlled square wave oscillator" PORT_TABLE: -Port_Name: cntl_in out +Port_Name: cntl_in out Description: "input" "output" -Direction: in out +Direction: in out Default_Type: v v -Allowed_Types: [v,vd,i,id,vnam] [v,vd,i,id] +Allowed_Types: [v,vd,i,id,vnam] [v,vd,i,id] Vector: no no -Vector_Bounds: - - -Null_Allowed: no no +Vector_Bounds: - - +Null_Allowed: no no PARAMETER_TABLE: -Parameter_Name: cntl_array freq_array +Parameter_Name: cntl_array freq_array Description: "control in array" "frequency array" -Data_Type: real real -Default_Value: 0.0 1.0e3 -Limits: - [0 -] -Vector: yes yes -Vector_Bounds: [2 -] [2 -] -Null_Allowed: no no +Data_Type: real real +Default_Value: 0.0 1.0e3 +Limits: - [0 -] +Vector: yes yes +Vector_Bounds: [2 -] [2 -] +Null_Allowed: no no PARAMETER_TABLE: Parameter_Name: out_low out_high Description: "output low value" "output high value" -Data_Type: real real -Default_Value: -1.0 1.0 -Limits: - - -Vector: no no -Vector_Bounds: - - -Null_Allowed: yes yes +Data_Type: real real +Default_Value: -1.0 1.0 +Limits: - - +Vector: no no +Vector_Bounds: - - +Null_Allowed: yes yes PARAMETER_TABLE: -Parameter_Name: duty_cycle rise_time +Parameter_Name: duty_cycle rise_time Description: "duty cycle" "rise time" -Data_Type: real real -Default_Value: 0.5 1.0e-9 -Limits: [1e-6 .999999] - -Vector: no no -Vector_Bounds: - - -Null_Allowed: yes yes +Data_Type: real real +Default_Value: 0.5 1.0e-9 +Limits: [1e-6 .999999] - +Vector: no no +Vector_Bounds: - - +Null_Allowed: yes yes PARAMETER_TABLE: -Parameter_Name: fall_time +Parameter_Name: fall_time Description: "fall time" -Data_Type: real -Default_Value: 1.0e-9 -Limits: - +Data_Type: real +Default_Value: 1.0e-9 +Limits: - Vector: no Vector_Bounds: - Null_Allowed: yes diff --git a/src/xspice/icm/analog/square/square.h b/src/xspice/icm/analog/square/square.h index 9a5067959..b3a964873 100644 --- a/src/xspice/icm/analog/square/square.h +++ b/src/xspice/icm/analog/square/square.h @@ -8,17 +8,17 @@ Georgia Tech Research Corporation, Atlanta, Ga. 30332 All Rights Reserved PROJECT A-8503-405 - -AUTHORS + +AUTHORS 12 Apr 1991 Harry Li -MODIFICATIONS +MODIFICATIONS 2 Oct 1991 Jeffrey P. Murray - + SUMMARY @@ -26,9 +26,9 @@ SUMMARY square (controlled squarewave oscillator) code model. -INTERFACES +INTERFACES - FILE ROUTINE CALLED + FILE ROUTINE CALLED N/A N/A @@ -36,7 +36,7 @@ INTERFACES REFERENCED FILES NONE - + NON-STANDARD FEATURES @@ -47,7 +47,7 @@ NON-STANDARD FEATURES /*=== INCLUDE FILES ====================*/ - + /*=== CONSTANTS ========================*/ @@ -56,7 +56,7 @@ char *square_limit_error = "\n**** Error ****\nSQUARE: Smoothing domain value to char *square_freq_clamp = "\n**** WARNING ****\nSQUARE: Frequency extrapolation limited to 1e-16 \n"; char *square_array_error = "\n**** Error ****\nSQUARE: Size of control array different than frequency array \n"; - + #define INT1 1 #define T1 2 #define T2 3 @@ -69,15 +69,15 @@ char *square_array_error = "\n**** Error ****\nSQUARE: Size of control array dif - -/*=== LOCAL VARIABLES & TYPEDEFS =======*/ + +/*=== LOCAL VARIABLES & TYPEDEFS =======*/ + + - - /*=== FUNCTION PROTOTYPE DEFINITIONS ===*/ - + diff --git a/src/xspice/icm/analog/triangle/cfunc.mod b/src/xspice/icm/analog/triangle/cfunc.mod index 16c4bec66..e12a0c317 100644 --- a/src/xspice/icm/analog/triangle/cfunc.mod +++ b/src/xspice/icm/analog/triangle/cfunc.mod @@ -52,43 +52,29 @@ NON-STANDARD FEATURES /*=== INCLUDE FILES ====================*/ +#include #include "triangle.h" - /*=== CONSTANTS ========================*/ - - /*=== MACROS ===========================*/ - - /*=== LOCAL VARIABLES & TYPEDEFS =======*/ - typedef struct { - - double *control; /* the storage array for the - control vector (cntl_array) */ - - double *freq; /* the storage array for the - pulse width array (pw_array) */ - - int tran_init; /* for initialization of phase1) */ - + double *control; /* the storage array for the + control vector (cntl_array) */ + double *freq; /* the storage array for the + pulse width array (pw_array) */ + int tran_init; /* for initialization of phase1) */ } Local_Data_t; - /*=== FUNCTION PROTOTYPE DEFINITIONS ===*/ - - - - /*============================================================================== FUNCTION void cm_triangle() @@ -132,8 +118,6 @@ NON-STANDARD FEATURES ==============================================================================*/ -#include - /*=== CM_TRIANGLE ROUTINE ===*/ /***************************************************** @@ -159,37 +143,37 @@ NON-STANDARD FEATURES * * *****************************************************/ -void cm_triangle(ARGS) /* structure holding parms, - inputs, outputs, etc. */ +void +cm_triangle(ARGS) { - int i; /* generic loop counter index */ - int cntl_size; /* size of the control array */ - int freq_size; /* size of the frequency array */ - int int_cycle; /* the number of cycles rounded to the nearest int */ + int i; /* generic loop counter index */ + int cntl_size; /* size of the control array */ + int freq_size; /* size of the frequency array */ + int int_cycle; /* the number of cycles rounded to the nearest int */ - double *x; /* pointer holds the values of the control array */ - double *y; /* pointer holds the values of the freq array */ - double cntl_input; /* control input */ - /*double out;*/ /* output */ - double dout_din; /* partial out wrt to control input */ - double output_low; /* lowest point of the wave */ - double output_hi; /* highest point of the wave */ - double dphase; /* percent into the current phase of the cycle */ - double *phase; /* instantaneous phase value */ - double *phase1; /* pointer to the previous phase value */ - double freq=0.0; /* actual frequency of the wave */ - double d_cycle; /* duty cycle */ - double *t1; /* pointer which stores time1 */ - double *t2; /* pointer which stores time2 */ - double *t_end; /* pointer which stores t_start */ - double time1; /* time of high peak */ - double time2; /* time of low peak */ - double t_start; /* time of the beginning of each cycle */ + double *x; /* pointer holds the values of the control array */ + double *y; /* pointer holds the values of the freq array */ + double cntl_input; /* control input */ + + double dout_din; /* partial out wrt to control input */ + double output_low; /* lowest point of the wave */ + double output_hi; /* highest point of the wave */ + double dphase; /* percent into the current phase of the cycle */ + double *phase; /* instantaneous phase value */ + double *phase1; /* pointer to the previous phase value */ + double freq = 0.0; /* actual frequency of the wave */ + double d_cycle; /* duty cycle */ + double *t1; /* pointer which stores time1 */ + double *t2; /* pointer which stores time2 */ + double *t_end; /* pointer which stores t_start */ + double time1; /* time of high peak */ + double time2; /* time of low peak */ + double t_start; /* time of the beginning of each cycle */ Mif_Complex_t ac_gain; - Local_Data_t *loc; /* Pointer to local static data, not to be included - in the state vector */ + Local_Data_t *loc; /* Pointer to local static data, not to be included + in the state vector */ /**** Retrieve frequently used parameters... ****/ @@ -207,15 +191,15 @@ void cm_triangle(ARGS) /* structure holding parms, /* Allocate memory */ - if(INIT==1) { - cm_analog_alloc(INT1,sizeof(double)); - cm_analog_alloc(T1,sizeof(double)); - cm_analog_alloc(T2,sizeof(double)); - cm_analog_alloc(T3,sizeof(double)); + if (INIT == 1) { + cm_analog_alloc(INT1, sizeof(double)); + cm_analog_alloc(T1, sizeof(double)); + cm_analog_alloc(T2, sizeof(double)); + cm_analog_alloc(T3, sizeof(double)); /*** allocate static storage for *loc ***/ - STATIC_VAR (locdata) = calloc (1 , sizeof ( Local_Data_t )); - loc = STATIC_VAR (locdata); + STATIC_VAR(locdata) = calloc(1, sizeof(Local_Data_t)); + loc = STATIC_VAR(locdata); /* Allocate storage for breakpoint domain & pulse width values */ x = loc->control = (double *) calloc((size_t) cntl_size, sizeof(double)); @@ -232,46 +216,47 @@ void cm_triangle(ARGS) /* structure holding parms, loc->tran_init = FALSE; } - if(ANALYSIS == MIF_DC) { + if (ANALYSIS == MIF_DC) { /* initialize time values */ - t1 = (double *) cm_analog_get_ptr(T1,0); - t2 = (double *) cm_analog_get_ptr(T2,0); - t_end = (double *) cm_analog_get_ptr(T3,0); + t1 = (double *) cm_analog_get_ptr(T1, 0); + t2 = (double *) cm_analog_get_ptr(T2, 0); + t_end = (double *) cm_analog_get_ptr(T3, 0); - *t1 = -1; - *t2 = -1; - *t_end = 0; + *t1 = -1; + *t2 = -1; + *t_end = 0; OUTPUT(out) = output_low; - PARTIAL(out,cntl_in) = 0; + PARTIAL(out, cntl_in) = 0; - } else if(ANALYSIS == MIF_TRAN) { + } else if (ANALYSIS == MIF_TRAN) { /* Retrieve previous values and set equal to corresponding variables */ - phase = (double *) cm_analog_get_ptr(INT1,0); - phase1 = (double *) cm_analog_get_ptr(INT1,1); - t1 = (double *) cm_analog_get_ptr(T1,1); - t2 = (double *) cm_analog_get_ptr(T2,1); - t_end = (double *) cm_analog_get_ptr(T3,1); + phase = (double *) cm_analog_get_ptr(INT1, 0); + phase1 = (double *) cm_analog_get_ptr(INT1, 1); - time1 = *t1; - time2 = *t2; + t1 = (double *) cm_analog_get_ptr(T1, 1); + t2 = (double *) cm_analog_get_ptr(T2, 1); + t_end = (double *) cm_analog_get_ptr(T3, 1); + + time1 = *t1; + time2 = *t2; t_start = *t_end; - loc = STATIC_VAR (locdata); + loc = STATIC_VAR(locdata); x = loc->control; y = loc->freq; - if (!loc->tran_init) { + if (! loc->tran_init) { *phase1 = 0.0; loc->tran_init = TRUE; } /* Retrieve x and y values. */ - for (i=0; i= x[cntl_size-1]) { /*** cntl_input above highest cntl_voltage ***/ + dout_din = (y[cntl_size-1] - y[cntl_size-2]) / + (x[cntl_size-1] - x[cntl_size-2]); + freq = y[cntl_size-1] + (cntl_input - x[cntl_size-1]) * dout_din; + /* freq = y[cntl_size-1]; */ - if (cntl_input >= x[cntl_size-1]) { - dout_din = (y[cntl_size-1] - y[cntl_size-2]) / - (x[cntl_size-1] - x[cntl_size-2]); - freq = y[cntl_size-1] + (cntl_input - x[cntl_size-1]) * dout_din; - /* freq = y[cntl_size-1]; */ + } else { + /*** cntl_input within bounds of end midpoints... + must determine position progressively & then + calculate required output. ***/ - } else { - /*** cntl_input within bounds of end midpoints... - must determine position progressively & then - calculate required output. ***/ + for (i = 0; i < cntl_size - 1; i++) { - for (i=0; i= x[i])) { - if ((cntl_input < x[i+1]) && (cntl_input >= x[i])) { + /* Interpolate to the correct frequency value */ - /* Interpolate to the correct frequency value */ - - freq = ((cntl_input - x[i])/(x[i+1] - x[i]))* - (y[i+1]-y[i]) + y[i]; - } + freq = ((cntl_input - x[i]) / (x[i+1] - x[i])) * + (y[i+1] - y[i]) + y[i]; } } + } /* Instantaneous phase is the old phase + frequency/(delta time) int_cycle is the integer value for the number cycles. */ - *phase = *phase1 + freq*(TIME - T(1)); - int_cycle = (int)*phase1; + *phase = *phase1 + freq * (TIME - T(1)); + int_cycle = (int) *phase1; dphase = *phase1 - int_cycle; + /* if the current time is greater than time1, but less than time2, - calculate time2 and set the temporary breakpoint. */ - if((time1 <= TIME) && (TIME <= time2)) { + calculate time2 and set the temporary breakpoint. */ + if ((time1 <= TIME) && (TIME <= time2)) { - time2 = T(1) + (1 - dphase)/freq; + time2 = T(1) + (1 - dphase) / freq; - if(TIME < time2) { + if (TIME < time2) cm_analog_set_temp_bkpt(time2); - } /* store the time that the next cycle is scheduled to begin */ t_start = time2; /* set output value */ - OUTPUT(out) = output_hi - ((TIME - time1)/(time2 - time1))* - (output_hi - output_low); + OUTPUT(out) = output_hi - ((TIME - time1) / (time2 - time1)) * + (output_hi - output_low); } else { /* otherwise, calculate time1 and time2 and set their respective - breakpoints */ + breakpoints */ - if(dphase > d_cycle) { + if (dphase > d_cycle) dphase = dphase - 1.0; - } - time1 = T(1) + (d_cycle - dphase)/freq; - time2 = T(1) + (1 - dphase)/freq; + time1 = T(1) + (d_cycle - dphase) / freq; + time2 = T(1) + (1 - dphase) / freq; - if((TIME < time1) || (T(1) == 0)) { + if ((TIME < time1) || (T(1) == 0)) cm_analog_set_temp_bkpt(time1); - } cm_analog_set_temp_bkpt(time2); /* set output value */ - OUTPUT(out) = output_low + ((TIME - t_start)/(time1 - t_start))* - (output_hi - output_low); + OUTPUT(out) = output_low + ((TIME - t_start) / (time1 - t_start)) * + (output_hi - output_low); } - PARTIAL(out,cntl_in) = 0.0; + PARTIAL(out, cntl_in) = 0.0; /* set the time values for storage */ - t1 = (double *) cm_analog_get_ptr(T1,0); - t2 = (double *) cm_analog_get_ptr(T2,0); - t_end = (double *) cm_analog_get_ptr(T3,0); + t1 = (double *) cm_analog_get_ptr(T1, 0); + t2 = (double *) cm_analog_get_ptr(T2, 0); + t_end = (double *) cm_analog_get_ptr(T3, 0); *t1 = time1; *t2 = time2; @@ -381,8 +362,7 @@ void cm_triangle(ARGS) /* structure holding parms, /* This model has no AC capabilities */ ac_gain.real = 0.0; - ac_gain.imag= 0.0; - AC_GAIN(out,cntl_in) = ac_gain; + ac_gain.imag = 0.0; + AC_GAIN(out, cntl_in) = ac_gain; } } - diff --git a/src/xspice/icm/analog/triangle/ifspec.ifs b/src/xspice/icm/analog/triangle/ifspec.ifs index f7e929353..780b5a0b4 100644 --- a/src/xspice/icm/analog/triangle/ifspec.ifs +++ b/src/xspice/icm/analog/triangle/ifspec.ifs @@ -4,18 +4,18 @@ Copyright 1991 Georgia Tech Research Corporation, Atlanta, Ga. 30332 All Rights Reserved -AUTHORS +AUTHORS 12 Apr 1991 Jeffrey P. Murray SUMMARY - This file contains the interface specification file for the + This file contains the interface specification file for the analog triangle (controlled trianglewave oscillator) code model. ===============================================================================*/ - + NAME_TABLE: @@ -26,48 +26,48 @@ Description: "controlled triangle wave oscillator" PORT_TABLE: -Port_Name: cntl_in out +Port_Name: cntl_in out Description: "input" "output" -Direction: in out +Direction: in out Default_Type: v v -Allowed_Types: [v,vd,i,id,vnam] [v,vd,i,id] +Allowed_Types: [v,vd,i,id,vnam] [v,vd,i,id] Vector: no no -Vector_Bounds: - - -Null_Allowed: no no +Vector_Bounds: - - +Null_Allowed: no no PARAMETER_TABLE: -Parameter_Name: cntl_array freq_array +Parameter_Name: cntl_array freq_array Description: "control in array" "frequency array" -Data_Type: real real -Default_Value: 0.0 1.0e3 -Limits: - [0 -] -Vector: yes yes -Vector_Bounds: [2 -] [2 -] -Null_Allowed: no no +Data_Type: real real +Default_Value: 0.0 1.0e3 +Limits: - [0 -] +Vector: yes yes +Vector_Bounds: [2 -] [2 -] +Null_Allowed: no no PARAMETER_TABLE: Parameter_Name: out_low out_high Description: "output low value" "output high value" -Data_Type: real real -Default_Value: -1.0 1.0 -Limits: - - -Vector: no no -Vector_Bounds: - - -Null_Allowed: yes yes +Data_Type: real real +Default_Value: -1.0 1.0 +Limits: - - +Vector: no no +Vector_Bounds: - - +Null_Allowed: yes yes PARAMETER_TABLE: -Parameter_Name: duty_cycle -Description: "rise time duty cycle" -Data_Type: real -Default_Value: 0.5 -Limits: [1e-6 .999999] -Vector: no -Vector_Bounds: - -Null_Allowed: yes +Parameter_Name: duty_cycle +Description: "rise time duty cycle" +Data_Type: real +Default_Value: 0.5 +Limits: [1e-6 .999999] +Vector: no +Vector_Bounds: - +Null_Allowed: yes STATIC_VAR_TABLE: diff --git a/src/xspice/icm/analog/triangle/triangle.h b/src/xspice/icm/analog/triangle/triangle.h index 3522249ff..3bbc6b717 100644 --- a/src/xspice/icm/analog/triangle/triangle.h +++ b/src/xspice/icm/analog/triangle/triangle.h @@ -8,17 +8,17 @@ Georgia Tech Research Corporation, Atlanta, Ga. 30332 All Rights Reserved PROJECT A-8503-405 - -AUTHORS + +AUTHORS 12 Apr 1991 Harry Li -MODIFICATIONS +MODIFICATIONS 2 Oct 1991 Jeffrey P. Murray - + SUMMARY @@ -26,9 +26,9 @@ SUMMARY triangle (controlled trianglewave oscillator) code model. -INTERFACES +INTERFACES - FILE ROUTINE CALLED + FILE ROUTINE CALLED N/A N/A @@ -36,7 +36,7 @@ INTERFACES REFERENCED FILES NONE - + NON-STANDARD FEATURES @@ -47,7 +47,7 @@ NON-STANDARD FEATURES /*=== INCLUDE FILES ====================*/ - + /*=== CONSTANTS ========================*/ @@ -55,7 +55,7 @@ char *triangle_allocation_error = "\n**** Error ****\nTRIANGLE: Error allocating char *triangle_freq_clamp = "\n**** Warning ****\nTRIANGLE: Extrapolated Minimum Frequency Set to 1e-16 Hz \n"; char *triangle_array_error = "\n**** Error ****\nTRIANGLE: Size of control array different than frequency array \n"; - + #define INT1 1 #define T1 2 #define T2 3 @@ -67,12 +67,12 @@ char *triangle_array_error = "\n**** Error ****\nTRIANGLE: Size of control array - -/*=== LOCAL VARIABLES & TYPEDEFS =======*/ + +/*=== LOCAL VARIABLES & TYPEDEFS =======*/ + + - - /*=== FUNCTION PROTOTYPE DEFINITIONS ===*/ diff --git a/src/xspice/icm/xtradev/core/cfunc.mod b/src/xspice/icm/xtradev/core/cfunc.mod index 1b0235511..bd2d0e09a 100644 --- a/src/xspice/icm/xtradev/core/cfunc.mod +++ b/src/xspice/icm/xtradev/core/cfunc.mod @@ -49,42 +49,30 @@ NON-STANDARD FEATURES /*=== INCLUDE FILES ====================*/ +#include #include "core.h" - /*=== CONSTANTS ========================*/ - - /*=== MACROS ===========================*/ - - /*=== LOCAL VARIABLES & TYPEDEFS =======*/ - typedef struct { - - double *H_array; /* the storage array for the - control vector (cntl_array) */ - - double *B_array; /* the storage array for the - pulse width array (pw_array) */ - - Boolean_t tran_init; /* for initialization of phase1) */ - + double *H_array; /* the storage array for the + control vector (cntl_array) */ + double *B_array; /* the storage array for the + pulse width array (pw_array) */ + Boolean_t tran_init; /* for initialization of phase1) */ } Local_Data_t; /*=== FUNCTION PROTOTYPE DEFINITIONS ===*/ - - - /*============================================================================== FUNCTION cm_core() @@ -125,8 +113,6 @@ NON-STANDARD FEATURES ==============================================================================*/ -#include - /*=== CM_CORE ROUTINE ===*/ /*******************************************************************/ @@ -192,36 +178,36 @@ NON-STANDARD FEATURES /* Last modified: 10/24/91 */ /*******************************************************************/ -void cm_core(ARGS) /* structure holding parms, - inputs, outputs, etc. */ +void +cm_core(ARGS) { /*** The following declarations pertain to PWL mode ***/ - int i; /* generic loop counter index */ - int size; /* size of the x_array */ + int i; /* generic loop counter index */ + int size; /* size of the x_array */ - int mode; /* mode parameter which determines whether - pwl or hyst will be used in analysis. */ + int mode; /* mode parameter which determines whether + pwl or hyst will be used in analysis. */ - double input_domain; /* smoothing range */ - double *H; /* pointer to the H-field array */ - double *B; /* pointer to the B-field array */ - double lower_seg; /* x segment below which input resides */ - double upper_seg; /* x segment above which the input resides */ - double lower_slope; /* slope of the lower segment */ - double upper_slope; /* slope of the upper segment */ - double mmf_input; /* input mmf value */ - double H_input; /* calculated input H value */ - double B_out; /* output B value */ - double flux_out; /* calculated output flux */ - double dout_din; /* partial derivative of the output wrt input */ - double threshold_lower; /* value below which the output begins - smoothing */ - double threshold_upper; /* value above which the output begins smoothing */ - double area; /* cross-sectional area of the core (in meters)*/ - double length; /* length of core (in meters) */ + double input_domain; /* smoothing range */ + double *H; /* pointer to the H-field array */ + double *B; /* pointer to the B-field array */ + double lower_seg; /* x segment below which input resides */ + double upper_seg; /* x segment above which the input resides */ + double lower_slope; /* slope of the lower segment */ + double upper_slope; /* slope of the upper segment */ + double mmf_input; /* input mmf value */ + double H_input; /* calculated input H value */ + double B_out; /* output B value */ + double flux_out; /* calculated output flux */ + double dout_din; /* partial derivative of the output wrt input */ + double threshold_lower; /* value below which the output begins + smoothing */ + double threshold_upper; /* value above which the output begins smoothing */ + double area; /* cross-sectional area of the core (in meters)*/ + double length; /* length of core (in meters) */ Mif_Complex_t ac_gain; @@ -229,38 +215,38 @@ void cm_core(ARGS) /* structure holding parms, char *limit_error="\n***ERROR***\nCORE: Violation of 50% rule in breakpoints!\n"; - /*** The following declarations pertain to HYSTERESIS mode... ***/ - double in, /* input to hysteresis block */ - out, /* output from hysteresis block */ - in_low, /* lower input value for hyst=0 at which - the transfer curve changes from constant - to linear */ - in_high, /* upper input value for hyst=0 at which - the transfer curve changes from constant - to linear */ - hyst, /* the hysteresis value (see above diagram) */ - out_lower_limit, /* the minimum output value from the block */ - out_upper_limit, /* the maximum output value from the block */ - slope, /* calculated rise and fall slope for the block */ - pout_pin, /* partial derivative of output w.r.t. input */ - x_rise_linear, /* = in_low + hyst */ - x_rise_zero, /* = in_high + hyst */ - x_fall_linear, /* = in_high - hyst */ - x_fall_zero; /* = in_low - hyst */ + double + in, /* input to hysteresis block */ + out, /* output from hysteresis block */ + in_low, /* lower input value for hyst=0 at which + the transfer curve changes from constant + to linear */ + in_high, /* upper input value for hyst=0 at which + the transfer curve changes from constant + to linear */ + hyst, /* the hysteresis value (see above diagram) */ + out_lower_limit, /* the minimum output value from the block */ + out_upper_limit, /* the maximum output value from the block */ + slope, /* calculated rise and fall slope for the block */ + pout_pin, /* partial derivative of output w.r.t. input */ + x_rise_linear, /* = in_low + hyst */ + x_rise_zero, /* = in_high + hyst */ + x_fall_linear, /* = in_high - hyst */ + x_fall_zero; /* = in_low - hyst */ - Boolean_t *hyst_state, /* TRUE => input is on lower leg of - hysteresis curve, between -infinity - and in_high + hyst. - FALSE => input is on upper leg - of hysteresis curve, between - in_low - hyst and +infinity */ - *old_hyst_state; /* previous value of *hyst_state */ - - Local_Data_t *loc; /* Pointer to local static data, not to be included - in the state vector */ + Boolean_t + *hyst_state, /* TRUE => input is on lower leg of + hysteresis curve, between -infinity + and in_high + hyst. + FALSE => input is on upper leg + of hysteresis curve, between + in_low - hyst and +infinity */ + *old_hyst_state; /* previous value of *hyst_state */ + Local_Data_t *loc; /* Pointer to local static data, not to be included + in the state vector */ /* Retrieve mode parameter... */ @@ -269,9 +255,7 @@ void cm_core(ARGS) /* structure holding parms, /** Based on mode value, switch to the appropriate model code... **/ - - /******** pwl mode *****************/ - if ( HYSTERESIS != mode ) { + if (HYSTERESIS != mode) { /******** pwl mode *****************/ /* Retrieve frequently used parameters... */ @@ -281,11 +265,11 @@ void cm_core(ARGS) /* structure holding parms, size = PARAM_SIZE(H_array); - if(INIT==1) { + if (INIT == 1) { /*** allocate static storage for *loc ***/ - STATIC_VAR (locdata) = calloc (1 , sizeof ( Local_Data_t )); - loc = STATIC_VAR (locdata); + STATIC_VAR(locdata) = calloc(1, sizeof(Local_Data_t)); + loc = STATIC_VAR(locdata); /* Allocate storage for breakpoint domain & range values */ H = loc->H_array = (double *) calloc((size_t) size, sizeof(double)); @@ -300,28 +284,24 @@ void cm_core(ARGS) /* structure holding parms, } } - loc = STATIC_VAR (locdata); + loc = STATIC_VAR(locdata); H = loc->H_array; B = loc->B_array; /* Retrieve H and B values. */ - for (i=0; i= (H[size-2] + H[size-1])/2.0) { - /*** H_input above highest midpoint ***/ - dout_din = (B[size-1] - B[size-2]) / - (H[size-1] - H[size-2]); - B_out = B[size-1] + (H_input - H[size-1]) * dout_din; - } else { /*** H_input within bounds of end midpoints... ***/ - /*** must determine position progressively & then ***/ - /*** calculate required output. ***/ - for (i=1; i= (H[size-2] + H[size-1]) / 2.0) { - if (H_input < (H[i] + H[i+1])/2.0) { - /* approximate position known... */ + /*** H_input above highest midpoint ***/ + dout_din = (B[size-1] - B[size-2]) / (H[size-1] - H[size-2]); + B_out = B[size-1] + (H_input - H[size-1]) * dout_din; - lower_seg = (H[i] - H[i-1]); - upper_seg = (H[i+1] - H[i]); + } else { /*** H_input within bounds of end midpoints... ***/ + /*** must determine position progressively & then ***/ + /*** calculate required output. ***/ - /* Calculate input_domain about this region's breakpoint.*/ + for (i = 1; i < size; i++) + if (H_input < (H[i] + H[i+1]) / 2.0) { + /* approximate position known... */ - if (PARAM(fraction) == MIF_TRUE) { /* Translate input_domain */ - /* into an absolute.... */ - if ( lower_seg <= upper_seg ) /* Use lower */ - /* segment */ - /* for % calc.*/ - input_domain = input_domain * lower_seg; - else /* Use upper */ - /* segment */ - /* for % calc.*/ - input_domain = input_domain * upper_seg; - } + lower_seg = (H[i] - H[i-1]); + upper_seg = (H[i+1] - H[i]); - /* Set up threshold values about breakpoint... */ - threshold_lower = H[i] - input_domain; - threshold_upper = H[i] + input_domain; + /* Calculate input_domain about this region's breakpoint.*/ - /* Determine where H_input is within region & determine */ - /* output and partial values.... */ - if (H_input < threshold_lower) { /* Lower linear region */ - dout_din = (B[i] - B[i-1])/lower_seg; - B_out = B[i] + (H_input - H[i]) * dout_din; - } else { - if (H_input < threshold_upper) { /* Parabolic region */ - lower_slope = (B[i] - B[i-1])/lower_seg; - upper_slope = (B[i+1] - B[i])/upper_seg; - cm_smooth_corner(H_input,H[i],B[i],input_domain, - lower_slope,upper_slope,&B_out,&dout_din); - } else { /* Upper linear region */ - dout_din = (B[i+1] - B[i])/upper_seg; - B_out = B[i] + (H_input - H[i]) * dout_din; - } - } - break; /* Break search loop...H_input has been found, */ - /* and B_out and dout_din have been assigned. */ + if (PARAM(fraction) == MIF_TRUE) { /* Translate input_domain */ + /* into an absolute.... */ + if (lower_seg <= upper_seg) /* Use lower */ + /* segment */ + /* for % calc.*/ + input_domain = input_domain * lower_seg; + else /* Use upper */ + /* segment */ + /* for % calc.*/ + input_domain = input_domain * upper_seg; } + + /* Set up threshold values about breakpoint... */ + threshold_lower = H[i] - input_domain; + threshold_upper = H[i] + input_domain; + + /* Determine where H_input is within region & determine */ + /* output and partial values.... */ + if (H_input < threshold_lower) { /* Lower linear region */ + + dout_din = (B[i] - B[i-1]) / lower_seg; + B_out = B[i] + (H_input - H[i]) * dout_din; + + } else if (H_input < threshold_upper) { /* Parabolic region */ + + lower_slope = (B[i] - B[i-1]) / lower_seg; + upper_slope = (B[i+1] - B[i]) / upper_seg; + cm_smooth_corner(H_input, H[i], B[i], input_domain, + lower_slope, upper_slope, &B_out, &dout_din); + + } else { /* Upper linear region */ + + dout_din = (B[i+1] - B[i]) / upper_seg; + B_out = B[i] + (H_input - H[i]) * dout_din; + + } + + break; /* Break search loop...H_input has been found, */ + /* and B_out and dout_din have been assigned. */ } - } } /* Calculate value of flux_out... */ @@ -402,21 +384,17 @@ void cm_core(ARGS) /* structure holding parms, /* Adjust dout_din value to reflect area and length multipliers... */ dout_din = dout_din * area / length; - - - if(ANALYSIS != MIF_AC) { /* Output DC & Transient Values */ + if (ANALYSIS != MIF_AC) { /* Output DC & Transient Values */ OUTPUT(mc) = flux_out; - PARTIAL(mc,mc) = dout_din; + PARTIAL(mc, mc) = dout_din; } else { /* Output AC Gain */ ac_gain.real = dout_din; - ac_gain.imag= 0.0; - AC_GAIN(mc,mc) = ac_gain; + ac_gain.imag = 0.0; + AC_GAIN(mc, mc) = ac_gain; } - } + } else { /******** hysteresis mode ******************/ - /******** hysteresis mode ******************/ - else { /** Retrieve frequently used parameters... **/ in_low = PARAM(in_low); @@ -426,144 +404,131 @@ void cm_core(ARGS) /* structure holding parms, out_upper_limit = PARAM(out_upper_limit); input_domain = PARAM(input_domain); - /** Calculate Hysteresis Linear Region Slopes & Derived Values **/ - /* Define slope of rise and fall lines when not being smoothed */ - slope = (out_upper_limit - out_lower_limit)/(in_high - in_low); + slope = (out_upper_limit - out_lower_limit) / (in_high - in_low); x_rise_linear = in_low + hyst; /* Breakpoint - x rising to - linear region */ - x_rise_zero = in_high + hyst; /* Breakpoint - x rising to - zero-slope (out_upper_limit) */ + linear region */ + x_rise_zero = in_high + hyst; /* Breakpoint - x rising to + zero-slope (out_upper_limit) */ x_fall_linear = in_high - hyst; /* Breakpoint - x falling to - linear region */ - x_fall_zero = in_low - hyst; /* Breakpoint - x falling to - zero-slope (out_lower_limit) */ + linear region */ + x_fall_zero = in_low - hyst; /* Breakpoint - x falling to + zero-slope (out_lower_limit) */ /* Set range to absolute value */ if (PARAM(fraction) == MIF_TRUE) input_domain = input_domain * (in_high - in_low); - - - /** Retrieve frequently used inputs... **/ in = INPUT(mc); - - /** Test for INIT; if so, allocate storage, otherwise, retrieve - previous timepoint value for output... **/ + previous timepoint value for output... **/ /* First pass...allocate storage for previous state. */ /* Also, calculate roughly where the current output */ /* will be and use this value to define current state. */ - if (INIT==1) { + if (INIT == 1) { + cm_analog_alloc(TRUE, sizeof(Boolean_t)); + hyst_state = (Boolean_t *) cm_analog_get_ptr(TRUE, 0); + old_hyst_state = (Boolean_t *) cm_analog_get_ptr(TRUE, 1); - cm_analog_alloc(TRUE,sizeof(Boolean_t)); - - hyst_state = (Boolean_t *) cm_analog_get_ptr(TRUE,0); - old_hyst_state = (Boolean_t *) cm_analog_get_ptr(TRUE,1); - - if (in < x_rise_zero + input_domain) { /* Set state to X_RISING */ + if (in < x_rise_zero + input_domain) /* Set state to X_RISING */ *old_hyst_state = X_RISING; - } else { + else *old_hyst_state = X_FALLING; - } + } else { /* Allocation not necessary...retrieve previous values */ - hyst_state = (Boolean_t *) cm_analog_get_ptr(TRUE,0); /* Set out pointer to current - time storage */ - old_hyst_state = (Boolean_t *) cm_analog_get_ptr(TRUE,1); /* Set old-output-state pointer - to previous time storage */ + hyst_state = (Boolean_t *) cm_analog_get_ptr(TRUE, 0); /* Set out pointer to current + time storage */ + old_hyst_state = (Boolean_t *) cm_analog_get_ptr(TRUE, 1); /* Set old-output-state pointer + to previous time storage */ } - - /** Set *hyst_out = *old_hyst_out, unless changed below... - we don't need the last iteration value of *hyst_state. **/ + we don't need the last iteration value of *hyst_state. **/ *hyst_state = *old_hyst_state; - - - /*** Calculate value of hyst_state, pout_pin.... ***/ if (*old_hyst_state == X_RISING) { /* Assume calculations on lower */ /* hysteresis section (x rising) */ - if ( in <= x_rise_linear - input_domain ) { /* Output @ lower limit */ + if (in <= x_rise_linear - input_domain) { /* Output @ lower limit */ out = out_lower_limit; pout_pin = 0.0; - } else { - if ( in <= x_rise_linear + input_domain ) { /* lower smoothing region */ - cm_smooth_corner(in,x_rise_linear,out_lower_limit,input_domain, - 0.0,slope,&out,&pout_pin); - } else { - if (in <= x_rise_zero - input_domain) { /* Rising linear region */ - out = (in - x_rise_linear)*slope + out_lower_limit; - pout_pin = slope; - } else { - if (in <= x_rise_zero + input_domain) { /* Upper smoothing region */ - cm_smooth_corner(in,x_rise_zero,out_upper_limit,input_domain, - slope,0.0,&out,&pout_pin); - } else { /* input has transitioned to X_FALLING region... */ - out = out_upper_limit; - pout_pin = 0.0; - *hyst_state = X_FALLING; - } - } - } + + } else if (in <= x_rise_linear + input_domain) { /* lower smoothing region */ + + cm_smooth_corner(in, x_rise_linear, out_lower_limit, input_domain, + 0.0, slope, &out, &pout_pin); + + } else if (in <= x_rise_zero - input_domain) { /* Rising linear region */ + + out = (in - x_rise_linear)*slope + out_lower_limit; + pout_pin = slope; + + } else if (in <= x_rise_zero + input_domain) { /* Upper smoothing region */ + + cm_smooth_corner(in, x_rise_zero, out_upper_limit, input_domain, + slope, 0.0, &out, &pout_pin); + + } else { /* input has transitioned to X_FALLING region... */ + + out = out_upper_limit; + pout_pin = 0.0; + *hyst_state = X_FALLING; + } + } else { /* Assume calculations on upper hysteresis section (x falling) */ if ( in >= x_fall_linear + input_domain ) { /* Output @ upper limit */ out = out_upper_limit; pout_pin = 0.0; - } else { - if ( in >= x_fall_linear - input_domain ) { /* Upper smoothing region */ - cm_smooth_corner(in,x_fall_linear,out_upper_limit,input_domain, - slope,0.0,&out,&pout_pin); - } else { - if (in >= x_fall_zero + input_domain) { /* Falling linear region */ - out = (in - x_fall_zero)*slope + out_lower_limit; - pout_pin = slope; - } else { - if (in >= x_fall_zero - input_domain) { /* Lower smoothing region */ - cm_smooth_corner(in,x_fall_zero,out_lower_limit,input_domain, - 0.0,slope,&out,&pout_pin); - } else { /* input has transitioned to X_RISING region... */ - out = out_lower_limit; - pout_pin = 0.0; - *hyst_state = X_RISING; - } - } - } + + } else if ( in >= x_fall_linear - input_domain ) { /* Upper smoothing region */ + + cm_smooth_corner(in, x_fall_linear, out_upper_limit, input_domain, + slope, 0.0, &out, &pout_pin); + + } else if (in >= x_fall_zero + input_domain) { /* Falling linear region */ + + out = (in - x_fall_zero)*slope + out_lower_limit; + pout_pin = slope; + + } else if (in >= x_fall_zero - input_domain) { /* Lower smoothing region */ + + cm_smooth_corner(in, x_fall_zero, out_lower_limit, input_domain, + 0.0, slope, &out, &pout_pin); + + } else { /* input has transitioned to X_RISING region... */ + + out = out_lower_limit; + pout_pin = 0.0; + *hyst_state = X_RISING; + } } - - if (ANALYSIS != MIF_AC) { /* DC & Transient Analyses */ - OUTPUT(mc) = out; - PARTIAL(mc,mc) = pout_pin; - + PARTIAL(mc, mc) = pout_pin; } else { /* AC Analysis */ ac_gain.real = pout_pin; - ac_gain.imag= 0.0; - AC_GAIN(mc,mc) = ac_gain; - + ac_gain.imag = 0.0; + AC_GAIN(mc, mc) = ac_gain; } } } - diff --git a/src/xspice/icm/xtradev/core/core.h b/src/xspice/icm/xtradev/core/core.h index 4049e9648..93c63f330 100644 --- a/src/xspice/icm/xtradev/core/core.h +++ b/src/xspice/icm/xtradev/core/core.h @@ -1,4 +1,4 @@ - + /******************************************************/ /****** Structures, etc. for core model. ******/ @@ -12,7 +12,7 @@ #define X_FALLING FALSE #define PWL 1 #define HYSTERESIS 2 - + @@ -25,12 +25,12 @@ /***** Structure Definitions *************************************/ - - + + /***** Function Definitions ***************************************/ diff --git a/src/xspice/icm/xtradev/core/ifspec.ifs b/src/xspice/icm/xtradev/core/ifspec.ifs index 96f12ca8d..598ee2b0d 100644 --- a/src/xspice/icm/xtradev/core/ifspec.ifs +++ b/src/xspice/icm/xtradev/core/ifspec.ifs @@ -4,18 +4,18 @@ Copyright 1991 Georgia Tech Research Corporation, Atlanta, Ga. 30332 All Rights Reserved -AUTHORS +AUTHORS 27 Sept 1991 Jeffrey P. Murray SUMMARY - This file contains the interface specification file for the + This file contains the interface specification file for the analog core code model. ===============================================================================*/ - + NAME_TABLE: @@ -27,109 +27,109 @@ Description: "magnetic core" PORT_TABLE: -Port_Name: mc -Description: "magnetic core" -Direction: inout -Default_Type: gd -Allowed_Types: [g,gd] -Vector: no -Vector_Bounds: - -Null_Allowed: no +Port_Name: mc +Description: "magnetic core" +Direction: inout +Default_Type: gd +Allowed_Types: [g,gd] +Vector: no +Vector_Bounds: - +Null_Allowed: no PARAMETER_TABLE: -Parameter_Name: h_array b_array +Parameter_Name: h_array b_array Description: "magnetic field array" "flux density array" -Data_Type: real real -Default_Value: - - -Limits: - - -Vector: yes yes -Vector_Bounds: [2 -] [2 -] -Null_Allowed: no no +Data_Type: real real +Default_Value: - - +Limits: - - +Vector: yes yes +Vector_Bounds: [2 -] [2 -] +Null_Allowed: no no PARAMETER_TABLE: -Parameter_Name: area length +Parameter_Name: area length Description: "cross-sectional area" "core length" -Data_Type: real real -Default_Value: - - -Limits: - - -Vector: no no -Vector_Bounds: - - -Null_Allowed: no no +Data_Type: real real +Default_Value: - - +Limits: - - +Vector: no no +Vector_Bounds: - - +Null_Allowed: no no PARAMETER_TABLE: -Parameter_Name: input_domain -Description: "input sm. domain" -Data_Type: real -Default_Value: 0.01 -Limits: [1e-12 0.5] -Vector: no -Vector_Bounds: - -Null_Allowed: yes +Parameter_Name: input_domain +Description: "input sm. domain" +Data_Type: real +Default_Value: 0.01 +Limits: [1e-12 0.5] +Vector: no +Vector_Bounds: - +Null_Allowed: yes PARAMETER_TABLE: -Parameter_Name: fraction +Parameter_Name: fraction Description: "smoothing fractional/abs switch" -Data_Type: boolean -Default_Value: TRUE -Limits: - -Vector: no -Vector_Bounds: - -Null_Allowed: yes +Data_Type: boolean +Default_Value: TRUE +Limits: - +Vector: no +Vector_Bounds: - +Null_Allowed: yes PARAMETER_TABLE: -Parameter_Name: mode +Parameter_Name: mode Description: "mode switch (1 = pwl, 2 = hyst)" Data_Type: int -Default_Value: 1 -Limits: [1 2] -Vector: no -Vector_Bounds: - -Null_Allowed: yes +Default_Value: 1 +Limits: [1 2] +Vector: no +Vector_Bounds: - +Null_Allowed: yes PARAMETER_TABLE: -Parameter_Name: in_low in_high +Parameter_Name: in_low in_high Description: "input low value" "input high value" -Data_Type: real real -Default_Value: 0.0 1.0 -Limits: - - -Vector: no no -Vector_Bounds: - - -Null_Allowed: yes yes +Data_Type: real real +Default_Value: 0.0 1.0 +Limits: - - +Vector: no no +Vector_Bounds: - - +Null_Allowed: yes yes PARAMETER_TABLE: -Parameter_Name: hyst out_lower_limit +Parameter_Name: hyst out_lower_limit Description: "hysteresis" "output lower limit" -Data_Type: real real -Default_Value: 0.1 0.0 -Limits: [0 -] - -Vector: no no -Vector_Bounds: - - -Null_Allowed: yes yes +Data_Type: real real +Default_Value: 0.1 0.0 +Limits: [0 -] - +Vector: no no +Vector_Bounds: - - +Null_Allowed: yes yes PARAMETER_TABLE: -Parameter_Name: out_upper_limit +Parameter_Name: out_upper_limit Description: "output upper limit" -Data_Type: real -Default_Value: 1.0 -Limits: - -Vector: no -Vector_Bounds: - -Null_Allowed: yes +Data_Type: real +Default_Value: 1.0 +Limits: - +Vector: no +Vector_Bounds: - +Null_Allowed: yes STATIC_VAR_TABLE: