How to Tune the HF2LI-PID Controllers
I often get questions from first-time users on how to properly tune the PID gain parameters. I am no expert in feedback control systems or the PID loop optimization, but I do believe tuning the HF2LI-PID parameters should not be an intimidating task for anybody who needs to use the HF2LI-PID controllers.
Case Study: Automatic Gain Control
Let us take a very simple case study of controlling the output amplitude of a simple oscillator. This is sometimes called automatic gain control, or AGC. For the best signal-to-noise ratio, we assume that we are working in the resonance frequency peak region of the oscillator as shown below. Note that due to the change in the environment, the peak resonance frequency can drift which also causes the measured amplitude to vary. Therefore, the objective here is to maintain a constant measured amplitude using the HF2LI-PID.
We observe from the above screenshot that the amplitude reading is about 6 mV. Again, we assume that we are already driving the oscillator near its peak resonance frequency. We need to set up now the PID tab in the ziControl graphical user interface. First, we need to select the PID input. This is done by choosing 'Demodulator: R' and '1' in two list items of the Input section. The reason is that we want to control the amplitude (i.e., R) that is measured using the demodulator 1. For the PID output, we need to select 'Sig Out 1: Amplitude' and '7' in the Output section. This corresponds to the fact that we want to adjust the amplitude of the oscillator 7 to control the amplitude of the oscillator output. Note that the Input and Output sections are highlighted in yellow and orange, respectively, in the screenshot below.
If your device-under-test can have an abrupt behavior of shifting 180o during oscillation, it may be better to use X as the PID input in order not to soft limit the amplitude to only positive values. Remember to automatically zero out the Y value by using the 'Auto Zero Phaseshift' function of the demodulator in the Lock-in tab.
Hint: if you are using one of the auxiliary outputs as the PID feedback (i.e., PID Output), then you need to set the Signal to 'Manual' in the Auxiliary I/O tab.
PID Tuning Method
There are in fact many PID tuning methods. They can be classified in two categories:
- Open-loop methods
- Closed-loop methods
In open-loop methods, the tuning is done while the feedback path is not closed. This allows you to observe the open-loop response according to the PID parameters setting. In the closed-loop methods, on the other hand, the PID parameters are adjusted on the fly while the loop is in feedback operation. The method that I suggest to use in this blog post is the closed-loop method, in particular the Good Gain tuning method [1]. In theory, the Good Gain method can be performed on the HF2LI-PID with the loop closed by following the steps below:
1. Initially, try to manually adjust the Setpoint in open loop such that the controlled signal is close to its final value.
Hint: You probably want to open up the demodulator filter bandwidth to at least 5.0 kHz and the demodulator readout to 14.4 kSa/s in order not to interfere with the PID bandwidth tuning.
2. Set all P, I and D values to zero. Increase P gradually until you get a slight overshoot in the step response. (Be careful with the polarity such that you do not have a positive feedback.) The step response can be observed by manually adjusting the Setpoint and observe the controlled signal response in the Spectroscope. You should now observe the error between the measured R and the set point value getting smaller and smaller as P values is increases. Note that with the P-controller you can get close to the final setpoint value (but might never exactly). This depends on the characteristics of the device-under-test as well as the setup delay. Make sure that the HF2LI-PID input and output are not unintentionally soft-limited in value (e.g., limited in amplitude, frequency etc.).
P-tuning: circled spot indicates the on-set of instability in step response when P gets too large
Hint: You can actually use the Toggle function in the PID tab and observe the step response in Spectroscope
3. Once the above condition is met, the rule is usually to set I to an initial value of 1.5Tou. Tou is the delta time between the overshoot and the undershoot of the step response. Increase the I gain parameter gradually until the error value Err gets very close to zero. You can slight decrease the P value by 50% to 80% if the step response becomes slightly unstable.
I-tuning: determine an initial value for I from Tou
4. You can potentially set D to 1/4 of I although it is not necessarily and sometimes might not even bring any improvement.
5. Check the loop response again by applying a step response as in Step 2. Adjust mainly the P and I gain parameters accordingly for fine tuning.
PI-fine tuning: final peak-to-peak noise should be as small as possible
In this case study, I only adjusted the gain parameters P and I without having to set the D gain parameter. I used the spectroscope to help with the fine-tuning by looking at the peak-to-peak noise of the HF2LI-PID output. If this peak-to-peak value gets bigger in the spectroscope during the fine tuning process, then you are probably getting away from the optimal value. Below is a step response from 5 mV to 35 mV of the resonator output under the final tuned HF2LI-PID setting.
Step response of 4 ms under fine tuned PID
I would say that this is very close to the maximum step response speed that we can get with this oscillator. To run a sanity check, I used the modeling tool included in each HF2LI-PID controller to check the simulated response. The simulation showed a step response of about 1.5 ms, not very far from the 4 ms that we have achieved through the Good Gain tuning method.
Conclusion
In this blog post, I demonstrated an example of AGC using the HF2LI-PID controllers. The Good Gain tuning method was used to do the closed loop tuning in real time. The toggle function and the Spectroscope are both very practical tools in ziControl when doing this type of tuning. Of course, it is always possible to run a numerical simulation first in order to tune the PID values. But the advantage of this type of manual tuning is that you can directly perform a trial-and-error operation without the need to figure out exactly the transfer function of the complete closed loop feedback. The method might not be the most accurate, but it is very practical in my opinion. Hopefully this post can be useful to get you started with the HF2LI-PID.
References
- Haugen, Finn, 2010, The Good Gain method for PI(D) controller tuning, July 19, 2010.