Hello,
I am new in Ngspice and i face a problem when i am trying to change a parameter and plot the variation of this parameter.
For example this netlist
Circuit
.param alpha_T = -0.001
.param T = 25
R1 1 2 r={200*(1+alpha_T * T)}
R2 2 0 200
V1 1 0 10V
.tran 1ms 1
end
so what i want to do is to plot v(2) for severals value of T, i know that we can do this in Pspice by using the .step param T List 20 25 30
so how we can sweep a parameter like T in Ngspice, also how to plot the variation of T with v(2)
Thanks
Michael
https://sourceforge.net/p/ngspice/mailman/message/29740898/
My answer is not the most straightforward one
(R='expression' doesn't seem to work correctly
on ngspice-25).
See the screendump for a possible plot.
Last edit: marcel hendrix 2014-05-03
Thank you very much Marcel,
just one more question, how to write the data of the 2 axes V(T) and Vout into file, to use it in Matlab ?
Put a line
before the write statement (and/or look in the manual).
To select the correct columns is a Matlab problem.
The manual explains how to selectively write traces to disk.
-marcel
And if i want to sweep a parameter into a library
.include INA.LIB
and T is a parameter into INA.LIB
Thanks
Michael
Did you look at LET and ALTER in the manual?
-marcel
Thank you Marcel
I tried Let and Alter
Vin 1 0 1
R1 1 2 1k
R2 2 0 r={200*(1+alpha_T * T)}
.tran 1ms 10ms
.control
let start_T = 20
let stop_T = 30
let delta_T = 1
let T_act = start_T
*loop
while T_act le stop_T
alter T T_act
run
wrdata sweepT.out v(2) v(1) T_act
set appendwrite
let T_act = T_act + delta_T
end
plot v(2) v(1)
.endc
.end
but this code didn't work cause the values written to the file (sweepT) aren't correct and when i tried to plot the T_act, i got an error "T_act isn't a vector"
Last edit: Michael 2014-05-03
It ain't pretty ...
The main problem was that ALTER changes the device directly, you
don't need to go through the parameter. Also, the alpha_T in the
control loop can't be a parameter because a control section
is a third interpreter layer :-E
I didn't make it plot, sorry. You probably will need to read in
the diskfile again, assign the scale/value columns to variables,
and then plot.
Note that diskfile contains paired scale/value columns. The actual
value of the scales is a bit mysterious, maybe somebody else can
explain.
-marcel
~~~~
:::html
Test sweeping
Vin 1 0 1
R1 1 2 1k
R2 2 0 200
.tran 1ms 10ms
.control
let start_T = 20
let stop_T = 30
let delta_T = 1
let T_act = start_T
let alpha_T = -0.001
let new_R = 200
while T_act le stop_T
let new_R = 200 * (1 + alpha_T * T_act)
alter r2 new_R
run
wrdata sweepT.out v(2) v(1) T_act new_R
set appendwrite
let T_act = T_act + delta_T
end
asciiplot v(2) v(1)
.endc
.end
I would also like to have this parameter change method. It is interesting when you have to test the behaviour of a trimmer or a trimpot in a filter circuit (like an graphic equalizer, for example).
I can use the alter command and the only problem is that the script will be longer and more prone to mistakes. The bad part about this is that you can´t save vectors between runs (with different names) so you can plot them stacked for comparison reasons. Almost all simulators have this feature.
thanks!
Hardy
Last edit: Hardy Leonardo da Cunha Pereira 2015-11-13
please have a look at manual chapter
16.13.4.2 .step
Holger
Will this feature also support subcircuit parameter sweeps ? If possible kindly support this too. "alter" and "altermod" can not be used for this purpose.
You may use alter or altermod in subcircuits (manual, at the end of Chapt. 17.5.3).
After loading the circuit, use the command 'listing expand' (or 'listing expand > listtext.txt', if you want to put the output into a file listtext.txt). Then you may have a look at the subcircuits, how they are expanded, and what names to use in the alter command.
Holger
Command 'alterparam' to alter (and sweep) parameters is available in ngspice-28.
Could this ticket be reopened? It would be quite helpful to do a parametric DC sweep in the same way than PSPICE does:
.DC LIN PARAM Ik 1p 400p 1pThis would be needed to facilitate the KiCad ngspice integration, see discussion: https://gitlab.com/kicad/code/kicad/-/merge_requests/564#note_481539302