From 8de9004468e5bb20ceb5df408758b78085729650 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Wed, 16 Oct 2024 17:02:36 +0200 Subject: [PATCH] added operator "cph()" to transform discontinuous phase ph(xxx) in AC analyses to aontinuous phase, like ngspice cph() function. Usage: instead of ph(out) use "ph(out) cph()" --- src/save.c | 13 +++++++++++++ xschem_library/devices/architecture.sym | 7 ++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/save.c b/src/save.c index 2116a15f..8361aa90 100644 --- a/src/save.c +++ b/src/save.c @@ -1557,6 +1557,7 @@ static double ravg_store(int what , int i, int p, int last, double value) #define GE 45 #define LE 46 #define COND 47 /* conditional expression: X cond Y ? --> X if conf == 1 else Y */ +#define CPH 48 /* continuous phase. Instead of -180..+180 avoid discontinuities */ #define ORDER_DERIV 1 /* 1 or 2: 1st order or 2nd order differentiation. 1st order is faster */ @@ -1614,6 +1615,7 @@ int plot_raw_custom_data(int sweep_idx, int first, int last, const char *expr, c else if(!strcmp(n, "**")) stack1[stackptr1++].i = POW; else if(!strcmp(n, "?")) stack1[stackptr1++].i = COND; /* conditional expression */ else if(!strcmp(n, "atan()")) stack1[stackptr1++].i = ATAN; + else if(!strcmp(n, "cph()")) stack1[stackptr1++].i = CPH; else if(!strcmp(n, "asin()")) stack1[stackptr1++].i = ASIN; else if(!strcmp(n, "acos()")) stack1[stackptr1++].i = ACOS; else if(!strcmp(n, "tan()")) stack1[stackptr1++].i = TAN; @@ -1970,6 +1972,17 @@ int plot_raw_custom_data(int sweep_idx, int first, int last, const char *expr, c stack1[i].prev = stack2[stackptr2 - 1]; stack2[stackptr2 - 1] = result; break; + case CPH: + if(p == first) { + result = stack2[stackptr2 - 1]; + } else { + double ph = stack2[stackptr2 - 1]; + double prev_ph = stack1[i].prev; + result = ph - (360.) * floor((ph - prev_ph)/(360.) + 0.5); + } + stack1[i].prev = result; + stack2[stackptr2 - 1] = result; + break; case SQRT: stack2[stackptr2 - 1] = sqrt(stack2[stackptr2 - 1]); break; diff --git a/xschem_library/devices/architecture.sym b/xschem_library/devices/architecture.sym index 080f0bcf..142177e9 100644 --- a/xschem_library/devices/architecture.sym +++ b/xschem_library/devices/architecture.sym @@ -1,4 +1,4 @@ -v {xschem version=3.4.4 file_version=1.2 +v {xschem version=3.4.6RC file_version=1.2 * * This file is part of XSCHEM, * a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit @@ -25,10 +25,11 @@ spice_ignore=true verilog_ignore=true tedax_ignore=true vhdl_ignore=true -template=" nothing here, use global schematic properties "} +template="code=ARCHITECTURE +\\"Use global schematic properties for code\\""} V {} S {} E {} L 4 0 -10 355 -10 {} -T {ARCHITECTURE} 5 -30 0 0 0.3 0.3 {} +T {@code} 5 -30 0 0 0.3 0.3 {} T {@schprop@schverilogprop@schvhdlprop@schsymbolprop} 45 5 0 0 0.3 0.3 {font=monospace layer=8}