diff --git a/examples/digital/74HCng_short_2.lib b/examples/digital/compare/74HCng_short_2.lib similarity index 100% rename from examples/digital/74HCng_short_2.lib rename to examples/digital/compare/74HCng_short_2.lib diff --git a/examples/digital/adder-comparison.txt b/examples/digital/compare/adder-comparison.txt similarity index 100% rename from examples/digital/adder-comparison.txt rename to examples/digital/compare/adder-comparison.txt diff --git a/examples/digital/adder_Xspice.cir b/examples/digital/compare/adder_Xspice.cir similarity index 100% rename from examples/digital/adder_Xspice.cir rename to examples/digital/compare/adder_Xspice.cir diff --git a/examples/digital/adder_behav.cir b/examples/digital/compare/adder_behav.cir similarity index 100% rename from examples/digital/adder_behav.cir rename to examples/digital/compare/adder_behav.cir diff --git a/examples/digital/adder_bip.cir b/examples/digital/compare/adder_bip.cir similarity index 100% rename from examples/digital/adder_bip.cir rename to examples/digital/compare/adder_bip.cir diff --git a/examples/digital/adder_common.inc b/examples/digital/compare/adder_common.inc similarity index 100% rename from examples/digital/adder_common.inc rename to examples/digital/compare/adder_common.inc diff --git a/examples/digital/adder_mos.cir b/examples/digital/compare/adder_mos.cir similarity index 100% rename from examples/digital/adder_mos.cir rename to examples/digital/compare/adder_mos.cir diff --git a/examples/digital/nggtk.tcl b/examples/digital/compare/nggtk.tcl similarity index 100% rename from examples/digital/nggtk.tcl rename to examples/digital/compare/nggtk.tcl diff --git a/examples/p-to-n-examples/behav-283-1.cir b/examples/digital/digital_devices/behav-283-1.cir similarity index 100% rename from examples/p-to-n-examples/behav-283-1.cir rename to examples/digital/digital_devices/behav-283-1.cir diff --git a/examples/p-to-n-examples/behav-283-1.stim b/examples/digital/digital_devices/behav-283-1.stim similarity index 100% rename from examples/p-to-n-examples/behav-283-1.stim rename to examples/digital/digital_devices/behav-283-1.stim diff --git a/examples/p-to-n-examples/behav-283.cir b/examples/digital/digital_devices/behav-283.cir similarity index 100% rename from examples/p-to-n-examples/behav-283.cir rename to examples/digital/digital_devices/behav-283.cir diff --git a/examples/p-to-n-examples/behav-tristate-pulse.cir b/examples/digital/digital_devices/behav-tristate-pulse.cir similarity index 100% rename from examples/p-to-n-examples/behav-tristate-pulse.cir rename to examples/digital/digital_devices/behav-tristate-pulse.cir diff --git a/examples/p-to-n-examples/behav-tristate-pulse.stim b/examples/digital/digital_devices/behav-tristate-pulse.stim similarity index 100% rename from examples/p-to-n-examples/behav-tristate-pulse.stim rename to examples/digital/digital_devices/behav-tristate-pulse.stim diff --git a/examples/p-to-n-examples/behav-tristate.cir b/examples/digital/digital_devices/behav-tristate.cir similarity index 100% rename from examples/p-to-n-examples/behav-tristate.cir rename to examples/digital/digital_devices/behav-tristate.cir diff --git a/examples/p-to-n-examples/behav-tristate.stim b/examples/digital/digital_devices/behav-tristate.stim similarity index 100% rename from examples/p-to-n-examples/behav-tristate.stim rename to examples/digital/digital_devices/behav-tristate.stim diff --git a/examples/p-to-n-examples/counter.cir b/examples/digital/digital_devices/counter.cir similarity index 100% rename from examples/p-to-n-examples/counter.cir rename to examples/digital/digital_devices/counter.cir diff --git a/examples/p-to-n-examples/decoder.cir b/examples/digital/digital_devices/decoder.cir similarity index 100% rename from examples/p-to-n-examples/decoder.cir rename to examples/digital/digital_devices/decoder.cir diff --git a/examples/p-to-n-examples/decoder.stim b/examples/digital/digital_devices/decoder.stim similarity index 100% rename from examples/p-to-n-examples/decoder.stim rename to examples/digital/digital_devices/decoder.stim diff --git a/examples/p-to-n-examples/ex283.cir b/examples/digital/digital_devices/ex283.cir similarity index 100% rename from examples/p-to-n-examples/ex283.cir rename to examples/digital/digital_devices/ex283.cir diff --git a/examples/p-to-n-examples/ex283.stim b/examples/digital/digital_devices/ex283.stim similarity index 100% rename from examples/p-to-n-examples/ex283.stim rename to examples/digital/digital_devices/ex283.stim diff --git a/examples/p-to-n-examples/ex4.cir b/examples/digital/digital_devices/ex4.cir similarity index 100% rename from examples/p-to-n-examples/ex4.cir rename to examples/digital/digital_devices/ex4.cir diff --git a/examples/p-to-n-examples/ex4.stim b/examples/digital/digital_devices/ex4.stim similarity index 100% rename from examples/p-to-n-examples/ex4.stim rename to examples/digital/digital_devices/ex4.stim diff --git a/examples/p-to-n-examples/ex5.cir b/examples/digital/digital_devices/ex5.cir similarity index 100% rename from examples/p-to-n-examples/ex5.cir rename to examples/digital/digital_devices/ex5.cir diff --git a/examples/p-to-n-examples/ex5.stim b/examples/digital/digital_devices/ex5.stim similarity index 100% rename from examples/p-to-n-examples/ex5.stim rename to examples/digital/digital_devices/ex5.stim diff --git a/examples/p-to-n-examples/nggtk.tcl b/examples/digital/digital_devices/nggtk.tcl similarity index 100% rename from examples/p-to-n-examples/nggtk.tcl rename to examples/digital/digital_devices/nggtk.tcl diff --git a/examples/p-to-n-examples/xspice_c4.cir b/examples/digital/digital_devices/xspice_c4.cir similarity index 100% rename from examples/p-to-n-examples/xspice_c4.cir rename to examples/digital/digital_devices/xspice_c4.cir diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index 7b6ad0f89..64acd47b3 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -773,7 +773,7 @@ char *find_back_assignment(const char *p, const char *start) /* Set a compatibility flag. Currently available are flags for: -- LTSPICE, HSPICE, Spice3, PSPICE, KiCad, Spectre +- LTSPICE, HSPICE, Spice3, PSPICE, KiCad, Spectre, XSPICE */ struct compat newcompat; static void set_compat_mode(void) @@ -781,6 +781,7 @@ static void set_compat_mode(void) char behaviour[80]; newcompat.hs = FALSE; newcompat.ps = FALSE; + newcompat.xs = FALSE; newcompat.lt = FALSE; newcompat.ki = FALSE; newcompat.a = FALSE; @@ -793,6 +794,8 @@ static void set_compat_mode(void) newcompat.isset = newcompat.hs = TRUE; /*HSPICE*/ if (strstr(behaviour, "ps")) newcompat.isset = newcompat.ps = TRUE; /*PSPICE*/ + if (strstr(behaviour, "xs")) + newcompat.isset = newcompat.xs = TRUE; /*XSPICE*/ if (strstr(behaviour, "lt")) newcompat.isset = newcompat.lt = TRUE; /*LTSPICE*/ if (strstr(behaviour, "ki")) @@ -820,7 +823,7 @@ static void set_compat_mode(void) } /* reset everything for 'make check' */ if (newcompat.mc) - newcompat.eg = newcompat.hs = newcompat.spe = newcompat.ps = + newcompat.eg = newcompat.hs = newcompat.spe = newcompat.ps = newcompat.xs = newcompat.ll = newcompat.lt = newcompat.ki = newcompat.a = FALSE; } @@ -835,6 +838,8 @@ static void print_compat_mode(void) { fprintf(stdout, " hs"); if (newcompat.ps) fprintf(stdout, " ps"); + if (newcompat.xs) + fprintf(stdout, " xs"); if (newcompat.lt) fprintf(stdout, " lt"); if (newcompat.ki) diff --git a/src/include/ngspice/compatmode.h b/src/include/ngspice/compatmode.h index 5cbc26af5..1355a74ed 100644 --- a/src/include/ngspice/compatmode.h +++ b/src/include/ngspice/compatmode.h @@ -16,6 +16,7 @@ struct compat bool spe; /* spectre */ bool eg; /* EAGLE */ bool mc; /* to be set for 'make check' */ + bool xs; /* XSPICE */ }; extern struct compat newcompat; diff --git a/src/spicelib/devices/isrc/isrcacct.c b/src/spicelib/devices/isrc/isrcacct.c index dc87c6e77..b71987f30 100644 --- a/src/spicelib/devices/isrc/isrcacct.c +++ b/src/spicelib/devices/isrc/isrcacct.c @@ -11,6 +11,7 @@ Author: 1985 Thomas L. Quarles #include "ngspice/suffix.h" #include "ngspice/missing_math.h" #include "ngspice/1-f-code.h" +#include "ngspice/compatmode.h" #ifndef HAVE_LIBFFTW3 extern void fftFree(void); @@ -56,6 +57,7 @@ ISRCaccept(CKTcircuit *ckt, GENmodel *inModel) double PHASE; double phase; double deltat; + double tmax = 1e99; TD = here->ISRCfunctionOrder > 2 ? here->ISRCcoeffs[2] : 0.0; @@ -78,60 +80,79 @@ ISRCaccept(CKTcircuit *ckt, GENmodel *inModel) time = ckt->CKTtime - TD; tshift = TD; - /* normalize phase to 0 - 360° */ - /* normalize phase to cycles */ - phase = PHASE / 360.0; - phase = fmod(phase, 1.0); - deltat = phase * PER; - while (deltat > 0) - deltat -= PER; - time += deltat; - tshift = TD - deltat; - - if(time >= PER) { - /* repeating signal - figure out where we are */ - /* in period */ - basetime = PER * floor(time/PER); - time -= basetime; + if (newcompat.xs) { + /* normalize phase to 0 - 360° */ + /* normalize phase to cycles */ + phase = PHASE / 360.0; + phase = fmod(phase, 1.0); + deltat = phase * PER; + while (deltat > 0) + deltat -= PER; + time += deltat; + tshift = TD - deltat; + } + else if (PHASE > 0.0) { + tmax = PHASE * PER; } - if( time <= 0.0 || time >= TR + PW + TF) { - if(ckt->CKTbreak && SAMETIME(time,0.0)) { - error = CKTsetBreak(ckt,basetime + TR + tshift); - if(error) return(error); - } else if(ckt->CKTbreak && SAMETIME(TR+PW+TF,time) ) { - error = CKTsetBreak(ckt,basetime + PER + tshift); - if(error) return(error); - } else if (ckt->CKTbreak && (time == -tshift) ) { - error = CKTsetBreak(ckt,basetime + tshift); - if(error) return(error); - } else if (ckt->CKTbreak && SAMETIME(PER,time) ) { - error = CKTsetBreak(ckt,basetime + tshift + TR + PER); - if(error) return(error); + if (!newcompat.xs && time > tmax) { + /* Do nothing */ + } + else { + if (time >= PER) { + /* repeating signal - figure out where we are */ + /* in period */ + basetime = PER * floor(time / PER); + time -= basetime; } - } else if ( time >= TR && time <= TR + PW) { - if(ckt->CKTbreak && SAMETIME(time,TR) ) { - error = CKTsetBreak(ckt,basetime + tshift + TR + PW); - if(error) return(error); - } else if(ckt->CKTbreak && SAMETIME(TR+PW,time) ) { - error = CKTsetBreak(ckt,basetime + tshift + TR + PW + TF); - if(error) return(error); + + if (time <= 0.0 || time >= TR + PW + TF) { + if (ckt->CKTbreak && SAMETIME(time, 0.0)) { + error = CKTsetBreak(ckt, basetime + TR + tshift); + if (error) return(error); + } + else if (ckt->CKTbreak && SAMETIME(TR + PW + TF, time)) { + error = CKTsetBreak(ckt, basetime + PER + tshift); + if (error) return(error); + } + else if (ckt->CKTbreak && (time == -tshift)) { + error = CKTsetBreak(ckt, basetime + tshift); + if (error) return(error); + } + else if (ckt->CKTbreak && SAMETIME(PER, time)) { + error = CKTsetBreak(ckt, basetime + tshift + TR + PER); + if (error) return(error); + } } - } else if (time > 0 && time < TR) { - if(ckt->CKTbreak && SAMETIME(time,0) ) { - error = CKTsetBreak(ckt,basetime + tshift + TR); - if(error) return(error); - } else if(ckt->CKTbreak && SAMETIME(time,TR)) { - error = CKTsetBreak(ckt,basetime + tshift + TR + PW); - if(error) return(error); + else if (time >= TR && time <= TR + PW) { + if (ckt->CKTbreak && SAMETIME(time, TR)) { + error = CKTsetBreak(ckt, basetime + tshift + TR + PW); + if (error) return(error); + } + else if (ckt->CKTbreak && SAMETIME(TR + PW, time)) { + error = CKTsetBreak(ckt, basetime + tshift + TR + PW + TF); + if (error) return(error); + } } - } else { /* time > TR + PW && < TR + PW + TF */ - if(ckt->CKTbreak && SAMETIME(time,TR+PW) ) { - error = CKTsetBreak(ckt,basetime + tshift+TR + PW +TF); - if(error) return(error); - } else if(ckt->CKTbreak && SAMETIME(time,TR+PW+TF) ) { - error = CKTsetBreak(ckt,basetime + tshift + PER); - if(error) return(error); + else if (time > 0 && time < TR) { + if (ckt->CKTbreak && SAMETIME(time, 0)) { + error = CKTsetBreak(ckt, basetime + tshift + TR); + if (error) return(error); + } + else if (ckt->CKTbreak && SAMETIME(time, TR)) { + error = CKTsetBreak(ckt, basetime + tshift + TR + PW); + if (error) return(error); + } + } + else { /* time > TR + PW && < TR + PW + TF */ + if (ckt->CKTbreak && SAMETIME(time, TR + PW)) { + error = CKTsetBreak(ckt, basetime + tshift + TR + PW + TF); + if (error) return(error); + } + else if (ckt->CKTbreak && SAMETIME(time, TR + PW + TF)) { + error = CKTsetBreak(ckt, basetime + tshift + PER); + if (error) return(error); + } } } } diff --git a/src/spicelib/devices/isrc/isrcload.c b/src/spicelib/devices/isrc/isrcload.c index fd86d1ce7..f947686c9 100644 --- a/src/spicelib/devices/isrc/isrcload.c +++ b/src/spicelib/devices/isrc/isrcload.c @@ -11,6 +11,7 @@ Modified: 2000 Alansfixes #include "ngspice/sperror.h" #include "ngspice/suffix.h" #include "ngspice/1-f-code.h" +#include "ngspice/compatmode.h" #ifdef XSPICE_EXP /* gtri - begin - wbk - modify for supply ramping option */ @@ -75,6 +76,7 @@ ISRCload(GENmodel *inModel, CKTcircuit *ckt) double PHASE; double phase; double deltat; + double tmax = 1e99; V1 = here->ISRCcoeffs[0]; V2 = here->ISRCcoeffs[1]; @@ -99,29 +101,42 @@ ISRCload(GENmodel *inModel, CKTcircuit *ckt) PHASE = here->ISRCfunctionOrder > 7 ? here->ISRCcoeffs[7] : 0.0; - /* normalize phase to cycles */ - phase = PHASE / 360.0; - phase = fmod(phase, 1.0); - deltat = phase * PER; - while (deltat > 0) - deltat -= PER; - /* shift time by pase (neg. for pos. phase value) */ - time += deltat; - - if(time > PER) { - /* repeating signal - figure out where we are */ - /* in period */ - basetime = PER * floor(time/PER); - time -= basetime; + if (newcompat.xs) { /* 7th parameter is PHASE */ + /* normalize phase to cycles */ + phase = PHASE / 360.0; + phase = fmod(phase, 1.0); + deltat = phase * PER; + while (deltat > 0) + deltat -= PER; + /* shift time by pase (neg. for pos. phase value) */ + time += deltat; } - if (time <= 0 || time >= TR + PW + TF) { + else if (PHASE > 0.0) { /* 7th parameter is number of pulses */ + tmax = PHASE * PER; + } + + if (!newcompat.xs && time > tmax) { value = V1; - } else if (time >= TR && time <= TR + PW) { - value = V2; - } else if (time > 0 && time < TR) { - value = V1 + (V2 - V1) * (time) / TR; - } else { /* time > TR + PW && < TR + PW + TF */ - value = V2 + (V1 - V2) * (time - (TR + PW)) / TF; + } + else { + if (time > PER) { + /* repeating signal - figure out where we are */ + /* in period */ + basetime = PER * floor(time / PER); + time -= basetime; + } + if (time <= 0 || time >= TR + PW + TF) { + value = V1; + } + else if (time >= TR && time <= TR + PW) { + value = V2; + } + else if (time > 0 && time < TR) { + value = V1 + (V2 - V1) * (time) / TR; + } + else { /* time > TR + PW && < TR + PW + TF */ + value = V2 + (V1 - V2) * (time - (TR + PW)) / TF; + } } } break; diff --git a/src/spicelib/devices/vsrc/vsrcacct.c b/src/spicelib/devices/vsrc/vsrcacct.c index 85ad3e3fd..1ec386681 100644 --- a/src/spicelib/devices/vsrc/vsrcacct.c +++ b/src/spicelib/devices/vsrc/vsrcacct.c @@ -11,6 +11,7 @@ Author: 1985 Thomas L. Quarles #include "ngspice/suffix.h" #include "ngspice/missing_math.h" #include "ngspice/1-f-code.h" +#include "ngspice/compatmode.h" #ifndef HAVE_LIBFFTW3 extern void fftFree(void); @@ -53,6 +54,7 @@ VSRCaccept(CKTcircuit *ckt, GENmodel *inModel) double tshift; double time = 0.; double basetime = 0; + double tmax = 1e99; double PHASE; double phase; @@ -79,60 +81,79 @@ VSRCaccept(CKTcircuit *ckt, GENmodel *inModel) time = ckt->CKTtime - TD; tshift = TD; - /* normalize phase to 0 - 360° */ - /* normalize phase to cycles */ - phase = PHASE / 360.0; - phase = fmod(phase, 1.0); - deltat = phase * PER; - while (deltat > 0) - deltat -= PER; - time += deltat; - tshift = TD - deltat; - - if(time >= PER) { - /* repeating signal - figure out where we are */ - /* in period */ - basetime = PER * floor(time/PER); - time -= basetime; + if (newcompat.xs) { + /* normalize phase to 0 - 360° */ + /* normalize phase to cycles */ + phase = PHASE / 360.0; + phase = fmod(phase, 1.0); + deltat = phase * PER; + while (deltat > 0) + deltat -= PER; + time += deltat; + tshift = TD - deltat; + } + else if (PHASE > 0.0) { + tmax = PHASE * PER; } - if( time <= 0.0 || time >= TR + PW + TF) { - if(ckt->CKTbreak && SAMETIME(time,0.0)) { - error = CKTsetBreak(ckt,basetime + TR + tshift); - if(error) return(error); - } else if(ckt->CKTbreak && SAMETIME(TR+PW+TF,time) ) { - error = CKTsetBreak(ckt,basetime + PER + tshift); - if(error) return(error); - } else if (ckt->CKTbreak && (time == -tshift) ) { - error = CKTsetBreak(ckt,basetime + tshift); - if(error) return(error); - } else if (ckt->CKTbreak && SAMETIME(PER,time) ) { - error = CKTsetBreak(ckt,basetime + tshift + TR + PER); - if(error) return(error); + if (!newcompat.xs && time > tmax) { + /* Do nothing */ + } + else { + if (time >= PER) { + /* repeating signal - figure out where we are */ + /* in period */ + basetime = PER * floor(time / PER); + time -= basetime; } - } else if ( time >= TR && time <= TR + PW) { - if(ckt->CKTbreak && SAMETIME(time,TR) ) { - error = CKTsetBreak(ckt,basetime + tshift + TR + PW); - if(error) return(error); - } else if(ckt->CKTbreak && SAMETIME(TR+PW,time) ) { - error = CKTsetBreak(ckt,basetime + tshift + TR + PW + TF); - if(error) return(error); + + if (time <= 0.0 || time >= TR + PW + TF) { + if (ckt->CKTbreak && SAMETIME(time, 0.0)) { + error = CKTsetBreak(ckt, basetime + TR + tshift); + if (error) return(error); + } + else if (ckt->CKTbreak && SAMETIME(TR + PW + TF, time)) { + error = CKTsetBreak(ckt, basetime + PER + tshift); + if (error) return(error); + } + else if (ckt->CKTbreak && (time == -tshift)) { + error = CKTsetBreak(ckt, basetime + tshift); + if (error) return(error); + } + else if (ckt->CKTbreak && SAMETIME(PER, time)) { + error = CKTsetBreak(ckt, basetime + tshift + TR + PER); + if (error) return(error); + } } - } else if (time > 0 && time < TR) { - if(ckt->CKTbreak && SAMETIME(time,0) ) { - error = CKTsetBreak(ckt,basetime + tshift + TR); - if(error) return(error); - } else if(ckt->CKTbreak && SAMETIME(time,TR)) { - error = CKTsetBreak(ckt,basetime + tshift + TR + PW); - if(error) return(error); + else if (time >= TR && time <= TR + PW) { + if (ckt->CKTbreak && SAMETIME(time, TR)) { + error = CKTsetBreak(ckt, basetime + tshift + TR + PW); + if (error) return(error); + } + else if (ckt->CKTbreak && SAMETIME(TR + PW, time)) { + error = CKTsetBreak(ckt, basetime + tshift + TR + PW + TF); + if (error) return(error); + } } - } else { /* time > TR + PW && < TR + PW + TF */ - if(ckt->CKTbreak && SAMETIME(time,TR+PW) ) { - error = CKTsetBreak(ckt,basetime + tshift+TR + PW +TF); - if(error) return(error); - } else if(ckt->CKTbreak && SAMETIME(time,TR+PW+TF) ) { - error = CKTsetBreak(ckt,basetime + tshift + PER); - if(error) return(error); + else if (time > 0 && time < TR) { + if (ckt->CKTbreak && SAMETIME(time, 0)) { + error = CKTsetBreak(ckt, basetime + tshift + TR); + if (error) return(error); + } + else if (ckt->CKTbreak && SAMETIME(time, TR)) { + error = CKTsetBreak(ckt, basetime + tshift + TR + PW); + if (error) return(error); + } + } + else { /* time > TR + PW && < TR + PW + TF */ + if (ckt->CKTbreak && SAMETIME(time, TR + PW)) { + error = CKTsetBreak(ckt, basetime + tshift + TR + PW + TF); + if (error) return(error); + } + else if (ckt->CKTbreak && SAMETIME(time, TR + PW + TF)) { + error = CKTsetBreak(ckt, basetime + tshift + PER); + if (error) return(error); + } } } } diff --git a/src/spicelib/devices/vsrc/vsrcload.c b/src/spicelib/devices/vsrc/vsrcload.c index 96422b5f2..beee1c99c 100644 --- a/src/spicelib/devices/vsrc/vsrcload.c +++ b/src/spicelib/devices/vsrc/vsrcload.c @@ -11,6 +11,7 @@ Modified: 2000 AlansFixes #include "ngspice/sperror.h" #include "ngspice/suffix.h" #include "ngspice/1-f-code.h" +#include "ngspice/compatmode.h" #ifdef XSPICE_EXP /* gtri - begin - wbk - modify for supply ramping option */ @@ -98,6 +99,7 @@ VSRCload(GENmodel *inModel, CKTcircuit *ckt) double PHASE; double phase; double deltat; + double tmax = 1e99; V1 = here->VSRCcoeffs[0]; V2 = here->VSRCcoeffs[1]; @@ -122,29 +124,42 @@ VSRCload(GENmodel *inModel, CKTcircuit *ckt) PHASE = here->VSRCfunctionOrder > 7 ? here->VSRCcoeffs[7] : 0.0; - /* normalize phase to cycles */ - phase = PHASE / 360.0; - phase = fmod(phase, 1.0); - deltat = phase * PER; - while (deltat > 0) - deltat -= PER; - /* shift time by pase (neg. for pos. phase value) */ - time += deltat; - - if(time > PER) { - /* repeating signal - figure out where we are */ - /* in period */ - basetime = PER * floor(time/PER); - time -= basetime; + if (newcompat.xs) { /* 7th parameter is PHASE */ + /* normalize phase to cycles */ + phase = PHASE / 360.0; + phase = fmod(phase, 1.0); + deltat = phase * PER; + while (deltat > 0) + deltat -= PER; + /* shift time by pase (neg. for pos. phase value) */ + time += deltat; } - if (time <= 0 || time >= TR + PW + TF) { + else if (PHASE > 0.0) { /* 7th parameter is number of pulses */ + tmax = PHASE * PER; + } + + if (!newcompat.xs && time > tmax) { value = V1; - } else if (time >= TR && time <= TR + PW) { - value = V2; - } else if (time > 0 && time < TR) { - value = V1 + (V2 - V1) * (time) / TR; - } else { /* time > TR + PW && < TR + PW + TF */ - value = V2 + (V1 - V2) * (time - (TR + PW)) / TF; + } + else { + if (time > PER) { + /* repeating signal - figure out where we are */ + /* in period */ + basetime = PER * floor(time / PER); + time -= basetime; + } + if (time <= 0 || time >= TR + PW + TF) { + value = V1; + } + else if (time >= TR && time <= TR + PW) { + value = V2; + } + else if (time > 0 && time < TR) { + value = V1 + (V2 - V1) * (time) / TR; + } + else { /* time > TR + PW && < TR + PW + TF */ + value = V2 + (V1 - V2) * (time - (TR + PW)) / TF; + } } } break;