#23 enable autostop function during meas inside .control section

open
nobody
None
5
2013-05-09
2013-05-09
Simon Y.H Chen
No

Dear friends,

Meas inside .control section has advantages than .meas function, such as utilize previous result.
However, when we enable the autostop, the simulation will be halt.
Please consider to support this or try to merge the advantages of .meas with "meas+.control".

Very Thanks,
Simon

Please check following netlist:
----------------------------------------------

*remove autostop will generate the correct result
.option autostop
.global vdd gnd

.option scale = 1e-6

* model binning
.model nch.1 nmos ( version=4.4 level=54 lmin=0.1u lmax=20u wmin=0.1u wmax=10u )
.model nch.2 nmos ( version=4.4 level=54 lmin=0.1u lmax=20u wmin=10u wmax=100u )
.model pch.1 pmos ( version=4.4 level=54 lmin=0.1u lmax=20u wmin=0.1u wmax=10u )
.model pch.2 pmos ( version=4.4 level=54 lmin=0.1u lmax=20u wmin=10u wmax=100u )

* parameters
.param vp = 1.0v
.param lmin = 0.10
.param wmin = 0.12
.param plmin = 'lmin'
.param nlmin = 'lmin'
.param wpmin = 'wmin'
.param wnmin = 'wmin'
.param drise = 400ps
.param dfall = 100ps
.param trise = 100ps
.param tfall = 100ps
.param period = 1ns
.param skew_meas = 'vp/2'

* parameterized subckt
.subckt inv in out pw='wpmin' pl='plmin' nw='wnmin' nl='nlmin'
mp out in vdd vdd pch w='pw' l='pl'
mn out in gnd gnd nch w='nw' l='nl'
.ends

v0 vdd gnd 'vp'

* vsrc with repeat
v1 in gnd pwl
+ 0ns 'vp'
+ 'dfall-0.8*tfall' 'vp'
+ 'dfall-0.4*tfall' '0.9*vp'
+ 'dfall+0.4*tfall' '0.1*vp'
+ 'dfall+0.8*tfall' 0v
+ 'drise-0.8*trise' 0v
+ 'drise-0.4*trise' '0.1*vp'
+ 'drise+0.4*trise' '0.9*vp'
+ 'drise+0.8*trise' 'vp'
+ 'period+dfall-0.8*tfall' 'vp'
+ r='dfall-0.8*tfall'

x1 in out inv pw=60 nw=20
c1 out gnd 220fF

.control
tran 1ps 4ns
meas tran inv_delay trig v(in) val=0.5 fall=1 targ v(out) val=0.5 rise=1
meas tran inv_delay2 trig v(in) val=0.5 td=1n fall=1 targ v(out) val=0.5 rise=1
meas tran test_data1 trig AT = 1n targ v(out) val=0.5 rise=3
meas tran out_slew trig v(out) val=0.2 rise=2 targ v(out) val=0.8 rise=2

.endc

.end

Discussion

  • Holger Vogt
    Holger Vogt
    2013-05-09

    Simon, with the current configuration of ngspice this is not possible.

    Inside of a .control section measure is only started when the simulation has finished.

    Changing that would mean a major rewrite.

    Holger

     
  • Holger Vogt
    Holger Vogt
    2013-05-09

    Simon,

    just an idea: use both!

    Modify your example according to this:

    *.meas tran inv_delay trig v(in) val=0.5 fall=1 targ v(out) val=0.5 rise=1
    *.meas tran inv_delay2 trig v(in) val=0.5 td=1n fall=1 targ v(out) val=0.5 rise=1
    .meas tran test_data1 trig AT = 1n targ v(out) val=0.5 rise=3
    *.meas tran out_slew trig v(out) val=0.2 rise=2 targ v(out) val=0.8 rise=2

    .control
    tran 1ps 4ns
    meas tran inv_delay trig v(in) val=0.5 fall=1 targ v(out) val=0.5 rise=1
    meas tran inv_delay2 trig v(in) val=0.5 td=1n fall=1 targ v(out) val=0.5 rise=1
    meas tran test_data1 trig AT = 1n targ v(out) val=0.5 rise=3
    meas tran out_slew trig v(out) val=0.2 rise=2 targ v(out) val=0.8 rise=2

    .endc

    Add at least one .meas statement outside of the .control section. This will care for autostop. For safety you may simply copy all meas commands into .meas. Then the meas commands within the control section will work as usual.

    In my example I have chosen only one .meas line, the one with the longest simulation time requirement (rise=3 comes lst). Again then all meas commands inside of the .control section work as usaual. The simulation time overhead is minimal.

    Regards

    Holger

     
  • Simon Y.H Chen
    Simon Y.H Chen
    2013-05-09

    Wow, Holger,

    If it works, I think this would be "very practical" solution.
    I'll try your suggestion with more cases to check both of overhead and "previous result" are ok with this solution.

    Very Thanks,
    Simon

     
  • Simon Y.H Chen
    Simon Y.H Chen
    2013-05-16

    Dear Holger,

    Thank you for this method, most of the cases work fine.
    However, when the case of ".meas with integ function" occurs, the situation will be change.
    I create an simple .meas with integ command and ngspice will show:
    "Warning: .OPTION AUTOSTOP will not be effective because one of 'max|min|avg|rms|
    integ' is used in .meas
    AUTOSTOP being disabled..."
    However, when I change the command to simple "find command", the speed will be faster.
    Please check if "autostop" could be run with "integ" command.
    Very Thanks,

    ---

    .option autostop
    .global vdd gnd

    .option scale = 1e-6

    * model binning
    .model nch.1 nmos ( version=4.4 level=54 lmin=0.1u lmax=20u wmin=0.1u wmax=10u )
    .model nch.2 nmos ( version=4.4 level=54 lmin=0.1u lmax=20u wmin=10u wmax=100u )
    .model pch.1 pmos ( version=4.4 level=54 lmin=0.1u lmax=20u wmin=0.1u wmax=10u )
    .model pch.2 pmos ( version=4.4 level=54 lmin=0.1u lmax=20u wmin=10u wmax=100u )

    * parameters
    .param vp = 1.0v
    .param lmin = 0.10
    .param wmin = 0.12
    .param plmin = 'lmin'
    .param nlmin = 'lmin'
    .param wpmin = 'wmin'
    .param wnmin = 'wmin'
    .param drise = 400ps
    .param dfall = 100ps
    .param trise = 100ps
    .param tfall = 100ps
    .param period = 1ns
    .param skew_meas = 'vp/2'

    * parameterized subckt
    .subckt inv in out pw='wpmin' pl='plmin' nw='wnmin' nl='nlmin'
    mp out in vdd vdd pch w='pw' l='pl'
    mn out in gnd gnd nch w='nw' l='nl'
    .ends

    v0 vdd gnd 'vp'

    * vsrc with repeat
    v1 in gnd pwl
    + 0ns 'vp'
    + 'dfall-0.8*tfall' 'vp'
    + 'dfall-0.4*tfall' '0.9*vp'
    + 'dfall+0.4*tfall' '0.1*vp'
    + 'dfall+0.8*tfall' 0v
    + 'drise-0.8*trise' 0v
    + 'drise-0.4*trise' '0.1*vp'
    + 'drise+0.4*trise' '0.9*vp'
    + 'drise+0.8*trise' 'vp'
    + 'period+dfall-0.8*tfall' 'vp'
    + r='dfall-0.8*tfall'

    x1 in out inv pw=60 nw=20
    c1 out gnd 220fF
    .meas tran power integ par('i(v0)*v(vdd)') from=2p to=2n
    *change above command to below command , the speed will be ok
    *.meas tran power_dummy find par('i(v0)*v(vdd)') at=2n
    .control
    tran 0.1ps 4ns
    let IVProd = I(v0) * v(vdd)
    meas tran power integ IVProd from=2p to=2n

    .endc

    .end

     
  • Simon Y.H Chen
    Simon Y.H Chen
    2013-05-16

    BTW,
    NGSPICE doesn't have P(v_source) function, so that I use the workaround with .meas.

    However, this method is not good when we want to meas the sum of many voltage sources.

    Could ngspice support p(v_source) ?? Just use par('i(v_source)*v(v_source_port)') internally.

     
  • Holger Vogt
    Holger Vogt
    2013-05-17

    Simon,

    what about

    Vsource1 1 0 1
    R1 1 0 1
    Vsource2 2 0 1
    R2 2 0 1
    ...
    .control
    tran ...
    let psum = v(1)*i(Vsource1) + v(2)*i(Vsource2)
    ...
    plot psum
    .endc

    Holger