TSTEP in transient simulation

alex
2013-07-15
2013-08-10
  • alex
    alex
    2013-07-15

    If i do:
    ngspice 2 -> tran 1e-9 1e-4 0
    i get good results (nice looking sine wave)

    But if i do
    ngspice 2 -> tran 1e-10 1e-4 0
    i get bad results (v(4) remains around 4.89 V) !

    Consider for example
    ngspice 2 -> plot v(4)
    for the following circuit file in interactive mode:

    Oscillator for a VCO
    common base amplifier stage
    ICC 1 0 -5
    RSource 1 0 1
    R1 1 2 100
    R2 2 3 4700
    R3 3 0 1000
    CS 2 0 0.1u
    R4 3 6 33
    C0 6 0 0.01u
    L1 2 4 10n
    Q1 4 3 7 Q2N3904
    R5 7 0 1500

    *feedback network
    R6 7 8 100
    C1 4 8 470p
    C2 8 0 470p
    C4 4 0 633p

    .op

    .control
    pz 7 0 4 0 cur pol
    print all
    .endc

    • Model for 2N3904 NPN BJT (from Eval library in Pspice)
      .model Q2N3904 NPN(Is=6.734f Xti=3 Eg=1.11 Vaf=74.03 Bf=416.4 Ne=1.259
    • Ise=6.734f Ikf=66.78m Xtb=1.5 Br=.7371 Nc=2 Isc=0 Ikr=0 Rc=1
    • Cjc=3.638p Mjc=.3085 Vjc=.75 Fc=.5 Cje=4.493p Mje=.2593 Vje=.75
    • Tr=239.5n Tf=301.2p Itf=.4 Vtf=4 Xtf=2 Rb=10)

    For the bad result v(4) remains around 4.89 V, whereas for the good result I obtain a nice looking sine wave.
    The problem is that I get the bad result for the finer time step in TSTEP (1e-10) and the good result for the coarser TSTEP (1e-9)
    Is this good or it is a bug and how do I handle this cases ?

    Thank you.

     
  • Robert Larice
    Robert Larice
    2013-07-25

    Hello alex,

    Your circuit is an oscillator.
    Oscillators need a tiny bit of energy to start up.
    In the real world you have at least a bit of thermal noise
    which starts an exponential growth of your oscillator.
    But if you do a numerical simulation, you don't have such
    a helper. If you are lucky, some floating point rounding
    during the process of the numerical simulation will start you up.
    But it is important to understand, that floating point rounding
    is not a random, but a deterministic process.
    Thus if all the rounding steps by chance don't change your
    simulated values in the first iteration,
    then further iterations wont change them too,
    which means, you are stuck, no exponential growth, no oscillation.
    Since there are a great many of numerical operations when
    processing a transient time step, it is practically impossible
    to guess which parameters might be mercy-full and cause at least
    little bit change to your node values,
    causing the impression of something strange and unpredictable
    going on.

    You can deliberately kick your oscillator to avoid this problem.
    One way is to put an initial condition onto the
    capacitor of your LC tank.
    Another would be do add a PULSE voltage source to kick it.

    Sometimes, you might not want to simulate the lengthy startup
    of your oscillator at all (costs a lot of simulator time).
    To do that, try to estimate an almost correct initial condition,
    so as to arrive at equilibrium faster.

    Robert

     
  • alex
    alex
    2013-08-10

    Thank you very much !