# Notes on Vclamp problems and PID controller tuning

Here are a few things to be aware of when setting up voltage clamp
circuitry ala the Squid model:

1) diffamp elements and the PID element have a "saturation" field that
limits the absolute magnitude of their output. Unfortunately this
field defaults to 0, which isn't very useful. Be sure to set it to
some large value (in the squid scripts it's set to 999, but you may
have to use a larger value if you're using some other set of units).

2) The tuning of the PID (proportional-integral-derivative) controller
involves balancing the quality of the voltage clamp against the size
of the integration time step. Basically, higher gain gives a better
clamp, but requires a smaller integration time step to avoid numerical
instability. (For more info on PID controllers see: Franklin, Powel,
Emami-Naeini (1986) "Feedback Control of Dynamic Systems", Addison-Wesley,
pp. 99-106) I'll outline a strategy for tuning the controller below.

3) the abrupt step change in voltage at the beginning of the clamp can
also give rise to numerical instabilities, hence the need to lowpass
filter the command signal with an "RC" element.

Here's the strategy I suggest for tuning the voltage clamp circuitry:

a) decide what rise time your willing to accept on the leading edge
of the step and set the time constant of the "lowpass" element
accordingly (watch out for units - the value "0.1" in the squid
script is in units of msec. If your simulation uses units
of seconds, you'd want "0.0001" for a 100 usec time constant.)

b) set the integration time step, DT, to be 4-5 times smaller than the
lowpass time constant.

c) set the PID integration time constant, tau_i, equal to the integration
time step DT

d) set the PID derivative time constant, tau_d, equal to DT/4

e) empirically determine the value of PID gain where things go unstable
and set the gain just below that point

Squid tutorial voltage clamp

The three plots show the Squid tutorial voltage clamp with the lowpass time
RC time constant set to 0.003, 0.03, and 0.3 msec. Note that with the
slowest (largest) time constant, Vm follows the command voltage well, but
the rise time is slow. With RC = 0.003, there is more overshoot than with
0.03

--Mark Nelson (nelson@vernal.npa.uiuc.edu)