So what you REALLY want is
Code:module varswcap (inout pos, neg input [7:0] capcontrl);
electrical pos, neg;
parameter real caplsb = 1p; // 1pf /bit
parameter real tr = 20p; // sec transition time for change
real capval = 0;
integer capset;
analog begin
I(pos,neg) <+ capval * ddt(V(pos,neg);
capval = transition(capset, 0, tr, tr);
end
always @(capcontrl) begin
if (^capcontrl != 1'bx) // no x or z values allowed..
capset = capontrol
end
--------------------------------------------
BUT This model create and destroys charge every time the capacitor value changes ..
so you might want to model how the total Q changes when you change capacitor values..
(does the charge remain fairly constant while a capacitor is disconnected from the system?
What happens to the voltage when it getst connected back in?