User Tools

Site Tools


simulating_a_time-varying_capacitor_in_spice

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
simulating_a_time-varying_capacitor_in_spice [2024/09/08 17:03] – created bmsimulating_a_time-varying_capacitor_in_spice [2024/09/10 11:51] (current) bm
Line 1: Line 1:
-=====DRAFT===== 
- 
 =====Simulating a time-varying capacitor in Spice===== =====Simulating a time-varying capacitor in Spice=====
  
-The current-voltage characteristic of a capacitor $C_1$ is given by:+The relationship between the voltage $v_Cover and the current $i_C$ through a capacitor is determined by its capacitance $C$:
  
-$$ I_1=C_1 \frac{dV_1}{dt}$$+$$ i_C(t)=C\frac{dv_C(t)}{dt}$$
  
-with $I_1$ and $V_1$ the current through and the voltage over the capacitor $C_1$.+However, this current-voltage relationship is not valid when the capacitor is varying in timeFor a time variant capacitor, the equation modifies to:
  
-We multiply this equation with a time-varying function k(t):+$$ i_C(t)=\frac{d}{dt}[C(t).v_C(t)]=C(t)\frac{dv_C(t)}{dt}+v_C(t)\frac{dC(t)}{dt}$$
  
-$$ k(t).I_1= [k(t).C_1] \frac{dV_1}{dt}$$+Rearranging this equation gives an expression for the voltage over the capacitor:
  
 +$$ v_C(t)=\frac{1}{C(t)}[C(0)v_C(0)+\int_0^t i_C(t) dt] $$
  
 +valid if $C(t)\neq 0$ at //any// time.
  
-Suppose we want we simulate a time-varying capacitor, e.g., a sinusoidal value in function of time with a certain offset: C(t)= 5 µF + 3 µF.sin(2π.10.t).+We will use this expression to simulate a time-varying capacitor in LT SpiceNotice the limitation that $C(t)\neq 0$ at //any// time.
  
 +Suppose we want we simulate a sinusoidal value in function of time with a certain offset: $C(t)$= 5 nF + 3 nF.sin(2π.100 kHz.t). In order to realize this, we have to introduce a custom component in SPICE with the following subcircuit:
  
 +<code>
 +.subckt capacitor + - params: VC0=0
 +.func C(time) {5n+3n*sin(2*pi*100k*time)}
 +hvolt + - value={(sdt(I(hvolt))+VC0*C(0))/C(time)}
 +.ends
 +</code>
  
-This can be realized by introducing an independent voltage source with voltage equal to the requested value of the resistor, i.e. 1 V corresponds to 1 Ω. Thus for our example, we need to introduce a voltage source with DC offset 5V, amplitude 3V and frequency 10 Hz. We allocate a label to the output of the voltage source, e.g., ''output''.+Current Dependent Voltage Source
  
-{{:simulating_a_time-varying_resistor_in_spice-1.png|}}+The voltage over the capacitor (see equation above) is modeled via a current dependent voltage source ''hvolt''. The integral is realized via the ''sdt'' function in SPICE. The initial value at time t=0 of the capacitor must be given as parameter.
  
-Next, we label the value of the time-varying resistor R1 as ''R=V(output)''. As a resultthe value of the resistor wil be identical to the output of the voltage sourceas can be seen in the following figure.+First, we save the code for this subcircuit into a .txt-file andfor exampleplace this file in the same folder as your SPICE circuit file.
  
-Notice that we can plot the value of the resistor by choosing ''V(V1)/I(R1)'' as plot function.+Next, open the text file in LT Spice, right click on the first word ".subckt", and select "Create symbol".
  
-{{:simulating_a_time-varying_resistor_in_spice-2.png|}}+The program asks you if you wish to automatically create a symbolClick "yes". A .asy file is created which contains your custom time-varying capacitor, typically in the folder 'C:Users\YourUserName\AppData\Local\LTspice\lib\sym\AutoGenerated'
  
-----+To use the time-varying capacitor in a circuit, click "component" (F2) and insert the custom capacitor by searching "capacitor" in the window.
  
-<color #808080>**References**</color> +Plotting the value of the capacitance in SPICE in function of time is not straightforwardLet us just check some individual timeswe compare the value of the current through and voltage over the capacitor (i) in the case of the time-varying capacitor at time $t_i$ (after the transition period), and (ii) in the case of a static capacitor with value $C(t_i)$
-  * <color #808080>[[https://maker.pro/forums/resources/simulating-time-variable-resistors.59/|https://maker.pro/forums/resources/simulating-time-variable-resistors.59]]</color>+
  
 +Case (i): We apply a high frequency source in order to create an envelope facilitating comparison between both cases.
  
 +{{:simulating_a_time-varying_capacitor_in_spice-1.png|}}
  
 +At a certain time, e.g., t=50µs, the value of the capacitor equals $C$(50µs)=  5 nF + 3 nF.sin(2π.100 kHz.50µs)=5 nF.
 +If we then zoom in at the simulation at t=50µs, we find the peak value of voltage over and current through the inductor.
  
 +Case (ii): We compare this value with a static inductor of 5 nF:
 +{{:simulating_a_time-varying_capacitor_in_spice-2.png|}}
 +
 +We find that both the current and voltage correspond to case (i).
 +
 +We do the same for a lot of other values of time, and always find a correspondence between both cases. This is not a rigid proof, but it gives us sufficient confidence that the capacitor was modeled correctly in SPICE.
 +
 +
 +----
  
 +**References**
 +  * Biolek, D., Kolka, Z., & Biolkova, V. (2007). Modeling time-varying storage components in PSpice. In Proc. Electronic Devices and Systems IMAPS CS International Conference EDS (Vol. 2007, pp. 39-44).
  
simulating_a_time-varying_capacitor_in_spice.1725815032.txt.gz · Last modified: by bm