1. FINAL PROJECT: ANALOG PID CONTROL USING OP-AMPS
Objectives
1. Understanding the theory of summing, inverting, differential, derivative, and integra-
tor op-amps.
2. Build a complete analog PID control circuit.
3. Test the input–output signal relation of a PID circuit (i.e., P-only, D only, I only, PD,
PI, PID versions of the circuit).
Components
Item Quantity Part No. Supplier
3 23966 Jameco Electronics (www.jameco.com)
8 29663 Jameco Electronics (www.jameco.com)
4 107633 Jameco Electronics (www.jameco.com)
4 29997 Jameco Electronics (www.jameco.com)
1 - - - Jameco Electronics (www.jameco.com)
2 25540 Jameco Electronics (www.jameco.com)
2 198791 Jameco Electronics (www.jameco.com)
1 20722 Jameco Electronics (www.jameco.com)
LM358 Op-Amp IC
Resistor 1 kΩ
Resistor 4.7 kΩ
Resistor 100 kΩ
Resistor 330 kΩ , 220 Ω , 2.0 MΩ
Capacitor 0.22 µF
Battery 9 V
Breadboard
Set of connection wires 1 set 20079 Jameco Electronics (www.jameco.com)
Theory
The “pure” derivative has a large gain at high frequency and will amplify the noise in the
closed loop, and hence lead to stability problems. In order to reduce the gain of the pure
derivative at high frequency, a practical derivative op-amp circuit is modified so that it has
a first-order pole in addition to the derivative, hence reducing the high frequency gain of
the transfer function thereby reducing the problem of noise amplification. This is done by
2. LABORATORY EXPERIMENTS
100 kΩ 100 kΩ
100 kΩ
100 kΩ
1 kΩ1 kΩ
1 kΩ
1 kΩ
1 kΩ
4.7 kΩ
1 kΩ
4.7 kΩ
1 kΩ
1 kΩ
Vi
Vref
Vo
–
–
–
–
–
+
+
+
+
+
–9 V
+9 V
–9 V
–9 V
+9 V
–9 V
+9 V
–9 V
+9 V
+9 V
R4 = 220 Ω , 2.0 MΩ
R3 = 330 kΩ
R1 = 4.7 kΩ
R2 = 4.7 kΩ
C = 0.22 μF
C = 0.22 μF
FIGURE 11.18: Analog PID control circuit.
adding a resistor R1 in series with the capacitor C (Figures 11.18, 11.19, 11.20, and 11.21).
Let us derive the transfer function for this practical derivative circuit. Notice that v+ = GND
and v+ = v− at the input terminals of the op-amp. Since there cannot be current drawn into
the op-amp, then
i1(t) = i2(t) (11.87)
where i1(t) is the current on the input side of the op-amp through R1 and C, and i2(t) is the
current on the feedback loop of the op-amp through R2. It is easy to show that
Vi(t) = R1 ⋅ i1(t) +
1
C ∫
t
0
i1(𝜏)d𝜏 (11.88)
Vi(s) = R1 ⋅ i1(s) +
1
C
1
s
i1(s) (11.89)
i1(s) =
Cs
R1Cs + 1
Vi(s) (11.90)
3. MECHATRONICS
FIGURE 11.19: Analog PID control circuit lab setup.
Similarly,
i2(t) =
0 − Vo(t)
R2
(11.91)
i2(s) =
−Vo(s)
R2
(11.92)
FIGURE 11.20: Picture of the analog PID control circuit based on op-amps on a breadboard.
4. LABORATORY EXPERIMENTS
i1(s) = i2(s) (11.93)
Cs
R1Cs + 1
Vi(s) =
−Vo(s)
R2
(11.94)
Vo(s)
Vi(s)
= −
R2Cs
R1Cs + 1
(11.95)
which shows that the new transfer function is a modified version of the differentiator. It not
only has a zero at the origin s = 0, but also has a pole at s = −1∕(R1C). This added pole
eliminates the high noise amplification problem of the “pure” differentiator.
In practice, an integral op-amp circuit typically includes a parallel resistor with the
capacitor (R4 in Figure 11.18). The reason for this is that a “pure” integrator adds a −90
degree phase (phase lag) to the loop at all frequencies. If we could reduce that phase lag at
least at lower frequencies, it would improve the stability of the closed loop system. Hence,
a pure integrator may be modified with a resistor R4 in parallel with the capacitor in the
feedback path to accomplish this. Let us show the new transfer function by derivation. Let
i1(t) be the current across R1, i2(t) be the current across R2, and i3(t) be the current across
C. From the same op-amp relations, it follows that
i1(t) = i2(t) + i3(t) (11.96)
i1(s) = i2(s) + i3(s) (11.97)
It is straightforward to show the relationships between currents, voltages, and resistors/
capacitor,
Vi(t)
R3
=
0 − Vo(t)
R4
+ C
d(0 − Vo(t))
dt
(11.98)
Vi(s)
R3
=
−Vo(s)
R4
+ Cs(−Vo(s)) (11.99)
5. MECHATRONICS
Vo(s)
Vi(s)
= −
R4
R3
1
(R4Cs + 1)
(11.100)
Vo(s)
Vi(s)
= −
1
RCs + 1
; for R3 = R4 = R (11.101)
which shows that the addition of R4 in parallel with the C capacitor on the feedback path
changes the “pure integrtor” (which has a pole at s = 0.0) into a first-order filter with a
pole at s = −1∕(R4C), where R and C parameters should be chosen such that the pole at
s = − 1
R4C
≈ 0.0 is close to the origin in order to approximate the integrator function.
The textbook PID controller transfer function is
u(s) =
(
Kp +
Ki
s
+ Kds
)
⋅ e(s) (11.102)
u(t) = Kp ⋅ e(t) + Ki ⋅
∫
e(𝜏)d𝜏 + Kd ⋅
de(t)
dt
(11.103)
where e(s) is the Laplace transform of the error signal, s(s) is the PID controller output.
Procedure
1. Assemble the circuit on the breadboard as shown in Figure 11.18. Take care not to
connect the 9-V batteries until the entire circuit has been assembled.
2. Derive the complete transfer function of the PID controller. Calculate the proportional,
derivative, and integrator gains: Kp, Kd, Ki, and the additional pole location of the
modified derivative term, and pole location and gain of the modified integral term.
Experiment with both pure-derivative and pure integral, and modified derivative and
modified integral, versions of the circuit. That is, remove R4 from the integrator
circuit to implement a pure integrator, and remove R1 from the derivative circuit to
implement a pure derivative function.
For the measurements to be taken below, remove R1 from the derivative circuit
and remove R4 from the integrator circuit. There are ten (10) results to capture.
3. Set up the function generator to produce two different wave forms with an amplitude
of 6 V: square wave and sine wave. The frequency of the wave functions can be easily
adjusted on the function generator, for example to 1.0 Hz. Connect the function
generator signal to Vi (feedback signal). Connect the Vref signal to the ground voltage
level.
4. Connect the oscilloscope channel 1 to the input signal from the function generator,
and oscilloscope channel 2 to the output of the differential op-amp, and sketch (or
take a picture of the oscilloscope screen) the input and output waveforms.
5. Connect the oscilloscope channel 1 to the input signal of the proportional op-amp
(output of the differential op-amp), and oscilloscope channel 2 to the output of the
proportional op-amp, and sketch (or take a digital picture of the oscilloscope screen)
the input and output waveforms.
6. Connect the oscilloscope channel 1 to the input signal of the derivative op-amp
(output of the differential op-amp), and oscilloscope channel 2 to the output of the
derivative op-amp, and sketch (or take a digital picture of the oscilloscope screen)
the input and output waveforms.
7. Connect the oscilloscope channel 1 to the input signal of the integrating op-amp
(output of the differential op-amp), and oscilloscope channel 2 to the output of the
6. LABORATORY EXPERIMENTS
integrator op-amp, and sketch (or take a digital picture of the oscilloscope screen) the
input and output waveforms.
8. Connect the oscilloscope channel 1 to the input signal of the op-amp (output of the
differential op-amp), and oscilloscope channel 2 to the output of the summing op-amp
(which is the output of the PID controller circuit), sketch (or take a digital picture
of the oscilloscope screen) the input and output waveforms. Confirm that the output
voltage of the summing op-amp is the sum of the voltages from the P-I-D sections of
the circuits (voltage outputs from P, I, and D circuits) multiplied with −1.
9. (Optional) Repeat the above 10-result test with the modified derivative (R1 is in the
circuit) and the modified integral term (R4 is in the circuit). Note that the values of the
added R1 and R4’s affect the performance of the PID controller and must be selected
properly for the intended performance.
10. (Optional) Repeat the above 10-result test with the modified derivative (R1 is in the
circuit) and the modified integral term (R4 is in the circuit). Except that in this case,
select a poor value for R4 on purpose so that the circuit is not a good approximation
to the integral function circuit.
11. (Optional) Closed loop control test: build a mathematical model of the PID circuit
(using MATLAB® or Simulink®) and simulate for the same circuit parameters and
input signal conditions, and compare your simulation results with the experiments.
Comment on the causes of the differences between simulation and experimental
results.
12. (Optional) Build a second-order system, that is double integrator (mass-force anal-
ogy), circuit to “simulate” the plant dynamics. Simply connect two integrators in
series. Then connect the output of the PID controller circuit to the input of the
double-integrator (plant), and the output of the double integrator into the negative
port of the PID’s comparator circuit at the input (Figures 2.35 and 2.36 in the text-
book). Using a potentiometer, generate the desired (commanded) output voltage.
Simulate the whole system in MATLAB® or Simulink®. Test the same simulated
conditions on the actual circuit and compare the closed loop system response results
(simulation results and hardware test results). Digital implementation of the PID con-
troller in real-time is given by Equations 2.42–2.44 in the textbook. If the sampling
period T is fast relative to the bandwidth of the system, the digital implementation
should give almost identical results to the analog implementation. The difference
between digital and analog implementation can be tested in simulation only using
MATLAB®/Simulink® without any hardware involvement, in that we should be able
to confirm a selection of a sampling period that is fast enough that the difference
between analog and digital implementation of the PID controller is insignificant. In
the simulation, we can also include the quantization errors due to finite word-length
(finite resolution) of the ADC and DAC converters. Equations 2.42 and 2.44 do not
include the effect of the quantization errors introduced by DAC and ADC.