diff --git a/src/xspice/examples/analog_models4_transient.deck b/src/xspice/examples/analog_models4_transient.deck index 9ad60efee..0fc5654b1 100644 --- a/src/xspice/examples/analog_models4_transient.deck +++ b/src/xspice/examples/analog_models4_transient.deck @@ -16,7 +16,7 @@ v4 4 0 DC 1.0 * * *** sine block *** -a1 1 10 sine1 +a1 2 10 sine1 .model sine1 sine (cntl_array=[-1.0 0.0 10.0 20.0] + freq_array=[500 500 2000 2000] + out_low=-1.0 out_high=1.0) diff --git a/src/xspice/icm/analog/sine/cfunc.mod b/src/xspice/icm/analog/sine/cfunc.mod index dbe015a50..02cc869fe 100644 --- a/src/xspice/icm/analog/sine/cfunc.mod +++ b/src/xspice/icm/analog/sine/cfunc.mod @@ -8,31 +8,32 @@ 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 - + 7 Sep 2012 Holger Vogt + SUMMARY This file contains the model-specific routines used to - functionally describe the sine (controlled sine-wave + functionally describe the sine (controlled sine-wave oscillator) code model. -INTERFACES +INTERFACES - FILE ROUTINE CALLED + FILE ROUTINE CALLED + + CMmacros.h cm_message_send(); - CMmacros.h cm_message_send(); - CM.c void *cm_analog_alloc() void *cm_analog_get_ptr() @@ -40,7 +41,7 @@ INTERFACES REFERENCED FILES Inputs from and outputs to ARGS structure. - + NON-STANDARD FEATURES @@ -50,11 +51,11 @@ NON-STANDARD FEATURES /*=== INCLUDE FILES ====================*/ -#include "sin.h" +#include "sin.h" #include - + /*=== CONSTANTS ========================*/ @@ -65,50 +66,59 @@ NON-STANDARD FEATURES - -/*=== LOCAL VARIABLES & TYPEDEFS =======*/ + +/*=== 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) */ +} Local_Data_t; - - /*=== FUNCTION PROTOTYPE DEFINITIONS ===*/ - + /*============================================================================== FUNCTION void cm_sine() -AUTHORS +AUTHORS 20 Mar 1991 Harry Li -MODIFICATIONS +MODIFICATIONS 2 Oct 1991 Jeffrey P. Murray + 7 Sep 2012 Holger Vogt SUMMARY This function implements the sine (controlled sinewave oscillator) code model. -INTERFACES +INTERFACES - FILE ROUTINE CALLED + FILE ROUTINE CALLED + + CMmacros.h cm_message_send(); - CMmacros.h cm_message_send(); - CM.c void *cm_analog_alloc() void *cm_analog_get_ptr() RETURNED VALUE - + Returns inputs and outputs via ARGS structure. GLOBAL VARIABLES - + NONE NON-STANDARD FEATURES @@ -120,7 +130,7 @@ NON-STANDARD FEATURES /*=== CM_SINE ROUTINE ===*/ -void cm_sine(ARGS) /* structure holding parms, +void cm_sine(ARGS) /* structure holding parms, inputs, outputs, etc. */ { int i; /* generic loop counter index */ @@ -142,13 +152,16 @@ void cm_sine(ARGS) /* structure holding parms, 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 */ + /**** 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); @@ -161,11 +174,31 @@ void cm_sine(ARGS) /* structure holding parms, 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); + return; + } + + } + if(ANALYSIS == MIF_DC){ OUTPUT(out) = (output_hi + output_low)/2; - PARTIAL(out,cntl_in) = 0; + PARTIAL(out,cntl_in) = 0; phase = (double *) cm_analog_get_ptr(INT1,0); *phase = 0; @@ -176,28 +209,19 @@ void cm_sine(ARGS) /* structure holding parms, phase = (double *) cm_analog_get_ptr(INT1,0); phase1 = (double *) cm_analog_get_ptr(INT1,1); - /* Allocate storage for breakpoint domain & freq. range values */ - x = (double *) calloc((size_t) cntl_size, sizeof(double)); - if (!x) { - cm_message_send(allocation_error); - return; - } - y = (double *) calloc((size_t) freq_size, sizeof(double)); - if (!y) { - cm_message_send(allocation_error); - return; - } + loc = STATIC_VAR (locdata); + x = loc->control; + y = loc->freq; - - /* Retrieve x and y values. */ + /* Retrieve x and y values. */ for (i=0; i= *(x+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; - } else { /*** cntl_input within bounds of end midpoints... - must determine position progressively & then + } else { /*** cntl_input within bounds of end midpoints... + must determine position progressively & then calculate required output. ***/ for (i=0; i= *(x+i))) { - + if ((cntl_input < *(x+i+1)) && (cntl_input >= *(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 peak value of the wave, the center of the wave, the @@ -249,9 +273,9 @@ void cm_sine(ARGS) /* structure holding parms, } else { /* Output AC Gain */ - ac_gain.real = 0.0; + ac_gain.real = 0.0; 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 eb97f14af..f505a3fef 100644 --- a/src/xspice/icm/analog/sine/ifspec.ifs +++ b/src/xspice/icm/analog/sine/ifspec.ifs @@ -58,3 +58,9 @@ Vector: no no Vector_Bounds: - - Null_Allowed: yes yes + +STATIC_VAR_TABLE: + +Static_Var_Name: locdata +Description: "local static data" +Data_Type: pointer