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

Both sides previous revisionPrevious revision
Next revision
Previous revision
simulating_a_time-varying_capacitor_in_spice [2024/09/10 10:16] bmsimulating_a_time-varying_capacitor_in_spice [2024/09/10 11:51] (current) bm
Line 20: Line 20:
  
 <code> <code>
-.subckt inductor + - params: IL0=0 +.subckt capacitor + - params: VC0=0 
-.func L(time) {5m+3m*sin(2*pi*100k*time)} +.func C(time) {5n+3n*sin(2*pi*100k*time)} 
-gcurr + - value={(sdt(V(+,-))+IL0*L(0))/L(time)}+hvolt + - value={(sdt(I(hvolt))+VC0*C(0))/C(time)}
 .ends .ends
 </code> </code>
  
-The current through the inductor (see equation above) is modeled via a G-type current source ''gcurr''. The integral is realized via the ''sdt'' function in SPICE. The initial value at time t=0 of the inductor must be given as parameter.+Current Dependent Voltage Source 
 + 
 +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.
  
 First, we save the code for this subcircuit into a .txt-file and, for example, place this file in the same folder as your SPICE circuit file. First, we save the code for this subcircuit into a .txt-file and, for example, place this file in the same folder as your SPICE circuit file.
Line 32: Line 34:
 Next, open the text file in LT Spice, right click on the first word ".subckt", and select "Create symbol". Next, open the text file in LT Spice, right click on the first word ".subckt", and select "Create symbol".
  
-The program asks you if you wish to automatically create a symbol. Click "yes". A .asy file is created which contains your custom time-varying inductor, typically in the folder 'C:Users\YourUserName\AppData\Local\LTspice\lib\sym\AutoGenerated'+The program asks you if you wish to automatically create a symbol. Click "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 inductor in a circuit, click "component" (F2) and insert the custom inductor by searching "inductor" in the window.+To use the time-varying capacitor in a circuit, click "component" (F2) and insert the custom capacitor by searching "capacitor" in the window.
  
-Plotting the value of the inductance in SPICE in function of time is not straightforward. Let us just check some individual times: we compare the value of the current through and voltage over the inductor (i) in the case of the time-varying inductor at time $t_i$ (after the transition period), and (ii) in the case of a static inductor with value $L(t_i)$. +Plotting the value of the capacitance in SPICE in function of time is not straightforward. Let us just check some individual times: we 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)$. 
  
 Case (i): We apply a high frequency source in order to create an envelope facilitating comparison between both cases. 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|}}
  
-{{:simulating_a_time-varying_inductor_in_spice-1.png|}} +At a certain time, e.g., t=50µs, the value of the capacitor equals $C$(50µs)=  nF + 3 nF.sin(2π.100 kHz.50µs)=5 nF.
- +
-At a certain time, e.g., t=50µs, the value of the inductor equals $L$(50µs)= 5 mH + 3 mH.sin(2π.100 kHz.50 µs)=5 mH.+
 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. 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 mH: +Case (ii): We compare this value with a static inductor of 5 nF
- +{{:simulating_a_time-varying_capacitor_in_spice-2.png|}}
-{{:simulating_a_time-varying_inductor_in_spice-2.png|}}+
  
 We find that both the current and voltage correspond to case (i). 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 inductor was modeled correctly in SPICE.+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.
  
  
simulating_a_time-varying_capacitor_in_spice.1725963387.txt.gz · Last modified: by bm