Thursday, 21 July 2016

LTspice: Vary a capacitor's value over time


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.



Answer



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= [ic=] [m=]


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.


No comments:

Post a Comment

arduino - Can I use TI&#39;s cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...