[go: up one dir, main page]

Menu

Time-modulated capacitors in NGSPICE: missing (dC/dt)·V term?

2025-09-01
2025-09-01
  • Lucas J Fernandez

    Hi all,

    I hope you are doing well.
    I’ve been working with time-modulated capacitors in NGSPICE and noticed something that seems inconsistent with the expected physics. Cutting to the chase:

    The charge of a capacitor with time-dependent capacitance is
    Q=C(t)V(t)

    and the current should be

    I(t) = \frac{dQ}{dt} = \frac{dC}{dt}V(t) + C(t)\frac{dV}{dt}

    However, NGSPICE appears to neglect the (dC/dt).V term. In my test circuit (see below), the simulated capacitor current (black line in the attached figure) agrees only with the C(t).dV/dt contribution.

    My questions:
    – Is this a known limitation of NGSPICE’s capacitor model?
    – Is there a recommended workaround to include the full time-dependent behavior (e.g. using B-sources, behavioral capacitors, or Verilog-A)?

    Thanks very much for any insight!

    Best regards,
    Lucas

    CT circuit
    *==============================================================
    
    .param freq=500k      $ source frequency
    .param dt=1/freq/400    $ time step for transient analysis
    .param tau=20/freq      $ evolution time
    
    * Voltage source
    Vs1 v1 0 SIN(0 1 {freq})
    
    * Time modulated capacitance
    Ck v1 0 {1000p*(1+0.9*cos(3.14159*freq*time))}
    
    * Also tried: --> gives the same result.
    * Ck v1 0 C = {1000p*(1+0.9*cos(3.14159*freq*time))}
    
    
    *--------------------------------------------------------------
    *--------------------------------------------------------------
    * Transient analysis specs
    *--------------------------------------------------------------
    
    .tran {dt} {tau} uic
    
    *==============================================================
    .control
        run
        set wr_singlescale
        wrdata current.dat V(v1) I(Vs1)
    .endc
    
    .END
    
     
  • Holger Vogt

    Holger Vogt - 2025-09-01

    This is how ngspice is dealing with variable capacitors (inpcom.c, lines 6695 ff.):

        /* Cxxx n1 n2 C = {equation} or Cxxx n1 n2 {equation}
           -->
           Exxx  n-aux 0  n2 n1  1
           Cxxx  n-aux 0         1
           Bxxx  n1 n2  I = i(Exxx) * equation
           or
           Cxxx n1 n2 Q = {equation}
           -->
           Gxxx  n1 n2 n-aux 0  1
           Lxxx  n-aux 0        1
           Bxxx  0 n-aux I = equation
        */
    
     
  • Lucas J Fernandez

    Thank you!

    I modified the code to define charge instead, as Q(t)=C(t)V(t). The line in the code reads

    * Time modulated charge
    Ck v1 0 Q={1000p*(1+0.9*cos(3.14159*freq*time))*V(v1)}
    

    Now it works (see atachment).
    Best regards,
    Lucas

     

Log in to post a comment.