6
\$\begingroup\$

I want to vary a capacitor's value over time. A previous question (LTspice: Vary a resistor's value over time) asked how to vary a resistor's value over time. One of the answers was to use a time variable in the resistor's value e.g. R=11-100*time. I tried this for a resistor and sure enough it worked. I thought I could use a similar approach for a capacitor e.g. C=11-100*time, but it doesn't work and I get an error message "Can't find definition of model 'C' ". I'm far from being an LTspice guru and would appreciate some help. Thanks.

\$\endgroup\$

3 Answers 3

4
\$\begingroup\$

Well, yes and no. From the ltspice help:

There is also a general nonlinear capacitor available. Instead of specifying the capacitance, one writes an expression for the charge.

LTspice will compile this expression and symbolically differentiate it with respect to all the variables, finding the partial derivative's that correspond to capacitances.

Syntax: Cnnn n1 n2 Q=<expression> [ic=<value>] [m=<value>]

There is a special variable, x, that means the voltage across the device. Therefore, a 100pF constant capacitance can be written as

Cnnn n1 n2 Q=100p*x

A capacitance with an abrupt change from 100p to 300p at zero volts can be written as

Cnnn n1 n2 Q=x*if(x<0,100p,300p)

This requires a bit of different thinking, and although you can make use of the special time variable, I have never verified that things work as expected. Especially intresting would be the point where the capacity will suddenly be lower than what the cap is currently holding in energy, what will ltspice do here? Or if when for the next timestep the capacity is now higher, will the stored energy be the same or scaled too?

You should test if it behaves the way you want it in a seperate test circuit first.

\$\endgroup\$
6
  • \$\begingroup\$ Thanks. I tried this in a simple series RC circuit with R=1k and Q=x*(time/100ms)*1u and f=1kHz, and that worked as expected. When I tried in the more complex circuit where I actually want to vary the capacitor the behaviour was not as expected. I ensured that the charge changed smoothly with time but the LTspice integrator generated large voltage spikes (>13kV in a circuit with Vcc=10V). I reduced the integration time step but it didn't help. Back to the drawing board I think! \$\endgroup\$
    – jaybeuu
    Mar 24, 2015 at 18:31
  • 1
    \$\begingroup\$ Tried a few experiments. I find that if I vary the charge VERY slowly with time then it behaves very close to what I would expect. If I run the simulation twice, 1st with a fixed capacitor and then with a variable capacitor that after some time T equals the fixed capacitor, then I would expect the two simulations to behave the same after time >T. They are close, but not the same. I'll continue to experiment. Good job I'm not trying to simulate tuning an old AM radio with a big old variable capacitor! \$\endgroup\$
    – jaybeuu
    Mar 24, 2015 at 19:05
  • \$\begingroup\$ @jaybeuu: I would not expect totally the same due to rounding errors etc. and with fixed vs. variable the accumulated energy will likely not be the same at the point the capacitances equalize. you might get better results with .opt numdgt 15 which is causing double instead of float math (this gets rid of rounding errors). Also make sure your cap has an esr, that often helps too. Otherwise trying to variate the capacitance in a way a slow turning knob would do is probably leading the most realistic results, yes. \$\endgroup\$
    – PlasmaHH
    Mar 24, 2015 at 19:14
  • \$\begingroup\$ Added an ESR but at the end of the simulation I got the message "Ignoring Rser for arbitrary capacitance device.V1: Missing value, assumed 0V @ DC Direct Newton iteration for .op point succeeded.". Any ideas? As you say, I'm finding that turning the knob very slowly appears to provide realistic results. \$\endgroup\$
    – jaybeuu
    Mar 24, 2015 at 19:35
  • \$\begingroup\$ @jaybeuu: "V1: Missing value, assumed 0V" means you never set any value for your voltage source. no idea about the ignored rser, maybe just add the parasitics yourself. \$\endgroup\$
    – PlasmaHH
    Mar 24, 2015 at 20:47
1
\$\begingroup\$

Here in these LTSpice snap shots I modeled the popular MFJ regenerative receiver circuit so that I could add an AGC circuit to the audio later on. I have the tuning coil L1 with an inductance value stated as {lt) and C7 capacitance is stated as {ct) these two components will then be tuned in an AC Anlysis Plot with various component values that the software will vary and plot.

To do this you will write 4 seperate spice directives as numbered below, do not add the number at the beginning of these directives

  1. .param lt = 14u
  2. .step param lt list 80n 410n 1.41u 4.71u 14.71u
  3. .param ct = 28p
  4. .step param ct list 5p 28p 56p

The .param describes the value of the coil and capacitor to begin with, the coil is 14 uH and the tuning capacitor is 28 pF. The .step directive tells the software to plot values of inductance for L1 from 14.7 uH down to 80 nH. And the .step directive for C7 tells the software to plot values for C7 from 56 pF down to 5 pF.

The measurement will be taken from a circuit node that you name " tune " as the Net Name with no port type but you can select " output " if you want.

When you run the AC Analysis it will take about a minute or so to plot all of this. When it is done, you then click the circuit node " tune " and the plot will appear as shown in the Snap Shot 2 posted here. All of these resonant tuning plots will be done at once. So have fun with this I have!

P.S. I know that this is not time or temperature related but I am thinking that perhaps you can do something with time and temperature parameters and steps. Someone might be able then to use this from this vantage of view.

Snap shot 1 Snap Shot 2

\$\endgroup\$
1
  • \$\begingroup\$ OP wants to vary the value in time, dynamically, not statically with .step directives. \$\endgroup\$ Mar 12, 2020 at 16:22
1
\$\begingroup\$

Did you try something called YX circuit?

For C=f(V) we use YX circuit and for L=f(V) or R=f(V) use ZX circuit ZX:

  • ports 1 and 2 are + and - input ports - control voltage
  • ports 5 and 4 are + and - output ports of pseudo component Eout 4 6 poly(2) (1, 2) (3, 0) 0 0 0 0 1 Fcopy 0 3 vsense 1 Rin 1 2 1G Vsense 6 5 0 Lref 3 0 1uH ; reference inductance

YX:

  • ports 1 and 2 are + and - input ports - control voltage
  • ports 5 and 4 are + and - output ports of pseudo component Ecopy 3 6 poly(2) (1, 2) (4, 5) 0 0 0 0 1 Fout 4 5 vsense 1 Rin 1 2 1G Vsense 0 6 0 Cref 3 0 1n

from> SPICE A guide to Circuit simulation & Analysis Using SPICE, Paul W. Tuinenga

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.