qucs_s icon indicating copy to clipboard operation
qucs_s copied to clipboard

Variables are not allowed in PULSE source parameters

Open Evidlo opened this issue 2 years ago • 4 comments

I'm trying to do a simple variable substitution from an equation into a device parameter, but it seems like the variable is being completely ignored. I'm on Qucs-S 0.0.23 using ngspice.

out

SPICE output

* Qucs 0.0.23 /tmp/test3.sch
.INCLUDE "/tmp/.mount_qucslvIHaR/usr/share/qucs-s/xspice_cmlib/include/ngspice_mathfunc.inc"
* Qucs 0.0.23  /tmp/test3.sch
.PARAM low=1e-3
.PARAM high=1e-3
V1 out 0 DC 0 PULSE( 0  1 0N 1N 1N 0 2e-09)  AC 0
V2 out2 0 DC 0 PULSE( 0  1 0N 1N 1N 0.001 0.002)  AC 0
.control
echo "" > spice4qucs.cir.noise
echo "" > spice4qucs.cir.pz
let low=1e-3
let high=1e-3
tran 9.90099e-05 0.01 0 
write test3_tran.txt v(out) v(out2) 
destroy all
reset

exit
.endc
.END

It seems like high and low are being ignored on V1 and the default source values are being substituted there.

Evidlo avatar May 23 '22 23:05 Evidlo

It is a limitation of the Ngspice. The SIN and PULSE sources are defined as vectors. And variables are not allowed inside the vectors. Also related to #53

ra3xdh avatar May 24 '22 12:05 ra3xdh

Do the other engines have this constraint? Which engine do you think is the best?

Evidlo avatar May 26 '22 01:05 Evidlo

Do the other engines have this constraint?

Yes, all SPICE engines (XYCE, SpiceOpus) define these sources as vectors.

Which engine do you think is the best?

The Ngspice is the best SPICE engine because of good simulation performance and compatibility with the existing models. Ngspice is set as default simulation kernel since v0.0.23.

ra3xdh avatar May 26 '22 15:05 ra3xdh

Below I will show four methods of changing VSRC pulse source parameters.

substitute vsrc pulse parameters
.param PW=1u PER=2u
V1 1 0 dc 0 pulse (0 1 0 1n 1n {PW} {PER})
.tran 1n 5u

.control
* original data
run
plot V(1)
* substitute via parameters
alterparam PW=0.5u 
alterparam PER=2.2u
reset
run
plot tran2.V(1)+1.2 tran1.V(1)
* substitute directly via vectors pw2 per2
let pw2=1.3u
let per2=1.9u
alter @V1[pulse] = [ 0 1 0 1n 1n $&pw2 $&per2 ]
run
plot tran3.V(1)+2.4 tran2.V(1)+1.2 tran1.V(1)
* substitute again via parameters and vectors pw3, per3
let pw3=1.25u
let per3=1.6u
alterparam PW=$&pw3 
alterparam PER=$&per3
reset
run
plot tran4.V(1)+3.6 tran3.V(1)+2.4 tran2.V(1)+1.2 tran1.V(1)
.endc

.end

What kind of limitations in ngspice do you still envision?

holvo avatar Jul 02 '22 15:07 holvo

This issue may be resolved using full SPICE definition of the square voltage source. I have also recently added the alterparam support #189 which may help to implement parameter sweep on PULSE source. Closing this.

ra3xdh avatar Nov 28 '22 07:11 ra3xdh