Professional Documents
Culture Documents
Contents
1 Revisions: insert photo of motor pot (10/10); insert better drawings; renumber figures to “11pid...” (8/07); try to cut repetition
(3/07).
1
2 Lab 10: Op Amps V: PID Motor Control
Today’s circuit looks straightforward: a potentiometer sets a target position; a DC motor tries to achieve that
position, which is measured by a second potentiometer. Lags cause the difficulty: the correction signal is
likely to arrive too late to solve a problem that the circuit senses. If that happens, the remedy can make things
worse.
This motor control circuit is a classic feedback network called a “PID” circuit: the circuit response ulti-
mately will include three functions of the circuit error signal, P , I, and D: “proportional,” “integral,” and
“derivative.” Stability is the central issue.
This feedback problem holds two sorts of interest, for our course.
• Pedagogical Appeal:
– It gives us a chance to apply—and to apply in concert—a collection of circuits that you have seen
either only as fragments, or only on paper:
• PID confronts a classic control problem; it provides a scheme with many practical applications
Students often tell us that they like to build circuits that do something—in contrast to circuits that produce just
images on a scope screen. Today’s circuit qualifies: it guarantees to make a little DC motor squirm (“squirm”
when it’s unstable; tamely spin when it’s stable).
This PID circuit is by far the most complex in this course to date. That makes it a good setup for improving
your debugging skills (this is a “glass-half-full” way to say that you’re very likely to make some wiring errors
today). We often boast that in this course, bugs are our most important product. This boast becomes most
convincing near the end of the course, when you put together a computer from IC’s; but even today the circuit
is complex enough to make it a challenge. (The debugging will be especially challenging if your sloppy
lab partner fails to keep leads short and color-coded, and forgets to bypass power supplies. We know you
wouldn’t make such errors.)
Finally, we’re happy to let this lab reinforce a concern first discussed in the fourth op amp lab: stability.
Although today’s circuit problem is singular—integrator within the loop—and the remedy more subtle than
usual, the general stability problem is one that confronts us in almost every circuit that has gain.
Lab 10: Op Amps V: PID Motor Control 3
The task we undertake here is one we have described in the class notes for Op Amps 5. We will repeat some
of what appears in those notes, to save you the trouble of consulting those as you do the lab. But those notes
are more thorough than what we will write in this lab.
Our goal, most simply stated, is just to use a feedback loop to get one DC voltage to match another; and since
both voltages come from potentiometers, the goal can also be described (maybe sounding more exciting) as
making the position of one potentiometer shaft mimic that of another. We want to be able to use our fingers
to turn a potentiometer by hand and see a motor-driven pot mimic our action. Such controls are sometimes
offered on fancy audio equipment, so that the equipment can be controlled either by twisting a knob, or by
using a remote that controls the knob from across the room.
The motor-pot gadget is nicely made, with an extreme gear-reduction box driving the pot slowly at high
torque—but mediated by a nylon clutch that can slip:
The clutch serves two purposes: it permits a human hand to control the potentiometer directly, when the
motor is stopped. It also protects the motor against stalling and overheating, if the motor drives the pot to one
of its limits.
The special difficulty, today, comes from the fact that the motor-to-potentiometer block, our circuit’s load,
4 Lab 10: Op Amps V: PID Motor Control
integrates voltages. So, we can’t use an ordinary op amp as the triangle in the feedback loop of fig.2.
The extra -90 degree shift, or integration, in today’s circuit forces us to alter our methods. Since we cannot
afford the phase shift of an ordinary op amp, we build ourselves a custom amplifier: one that provides modest
gain and no phase shift. We will apply the radical remedy, in other words of altering not the load in the loop
but the op amp itself.
And here’s a reminder of today’s circuit—redrawn to suggest that we now will be able to tinker with the
amplifier’s gain. Later, we will alter also its phase behavior.
Figure 3: Proportional-only drive will cause some overshoot; gain will affect this
We will first try this circuit with its gain adjusted low, and we expect to find the circuit fairly stable. Then, as
we increase gain, we should begin to see overshoot and ringing; if we push on to still higher gains, we should
see the circuit oscillate continuously.
At the end of these notes we attach some scope images describing just such responses to variations in simple
“proportional” gain.
Time: 25 min.
Let’s start with a subcircuit that is familiar: a high-current driver, capable of driving a substantial current (up
to a couple of hundred milliamps). We’ll use the power transistors you’ve met before: MJE3055 (npn) and
MJE2955 (pnp). The motor presents the kind of troublesome load likely to induce parasitic oscillations, as
in the last exercise of Lab Op Amps 4. We need, therefore, the protections that we invoked there: not only
decoupling of supplies, but also both a snubber and high-frequency feedback that bypasses the troublesome
phase-shifting elements.
We are trying hard, here, to decouple one part of the circuit from the others: the 15µF caps should prevent sup-
ply disturbances from upsetting the target signal. Similar caps at the ends of the motor-driven potentiometer
aim to stabilize the feedback signal.
You may also want to use an external power supply to provide the motor’s ±15V supplies, if you have
such an extra supply handy. We suggest this not for decoupling, but because the motor’s maximum current
exceeds the breadboard’s 100mA rated output, and might disturb those supplies even if one inserted plenty of
decoupling caps. The external supply, unlike the breadboard supply, can provide the necessary current. (But
we have also built this lab happily without this separate power supply.)
Lab 10: Op Amps V: PID Motor Control 5
Figure 4: Motor-driver
Note that you must not use ’411 op amps. The ’411 has the nasty property—common to “bi-fet” devices—
that it flips its output phase if the input voltage goes below its specified common-mode input range. The
result is that if an input to any of the amplifiers in this loop momentarily swings to within about a volt of the
negative supply, the loop is very likely to get hung up by this nasty positive feedback.2
Wire up the two potentiometers, as well as the motor-driver itself. The resistors at the ends of the two
potentiometers—6.8k resistors on input, 4.7k resistors on the motor pot—restrict input and output range to
a range of about ± 7V, so as to keep all signals well within a range that keeps the op amps happy. The
difference in R values makes sure that the input range cannot exceed the achievable output range.
You can test this motor driver by varying the input voltage, and watching the voltage out of the motor-driven
pot. Don’t be dismayed if you see a good deal of hash on the scope screen. This hash may look very much
like a parasitic oscillation, familiar to you from the recent nasty oscillators lab. The image just below shows
what we saw, when watching the motor drive, with the motor moving:
But if we look at this hash more closely, we find some clues that it is not the usual parasitic oscillation at
work:
2 This hazard is not hypothetical; we first breadboarded this circuit with ’411’s—and were forcibly reminded of the part’s nasty
Figure 6: Motor drive hash seen in greater detail: not parasitic oscillation, after all
These spikes seem to be the effects of the DC motor’s brushes breaking contact periodically with the motor’s
commutator. One clue is the fact that noise is not continuous, but seems to be a set of narrow spikes at a
low repetition rate. The other clue—pretty conclusive—is the fact that the spike voltages exceed the power
supply: this effect looks a lot like the behavior of an inductor (the motor winding), angry each time the
commutator switches the current off. So, don’t let this hash worry you. It’s ugly, but we’ll live with it.
Any VIN more than a few tenths of a volt should evoke a change of output voltage. You will hear the motor
whirring, and will see the shaft slowly turning (the motor drive is geared down through a two-stage worm-
and conventional- gearing scheme). After perhaps 20 seconds, the pot will reach its limit and will cease
turning. But that’s all right: a clever clutch scheme allows the motor to slip harmlessly when the pot reaches
either end of its range. If the signs of VIN and the change in VOUT do not match, then be sure to interchange
leads of one of the pots, so as to make them match. We don’t want a hidden inversion, here. It would upset
our scheme when we later close the loop.
Now we do a strange thing: we use three op amps to make a rather-crummy op-amp like circuit.
The first stage you recognize as a standard differential amp. It shows unity gain. The second stage simply
inverts3 ; the third stage seems to be doing no more than undoing the inversion of the preceding circuit. That
is true, at this stage; but we include this circuit because soon we will use it, fed by two more inputs, as a
summing circuit. So used, it will put together the three elements of the PID controller: Proportional, Integral,
and Derivative. In the present P -only circuit we also use the third amplifier to vary the overall gain of our
home-made op amp.
The entire circuit, then, is simply a differential amplifier with adjustable gain. And this gain is always low
relative to the very-high values we are accustomed to in op amps. We need the modesty of this gain, and we
need an associated virtue of this simple circuit: no appreciable phase-shift between input and output. Both
characteristics contrast with those of an ordinary op amp, as you know. The fixed, high gain of an ordinary
op amp, along with its integrator behavior beginning at 10 or 20 Hz would get us into trouble today, turning
negative feedback into positive.
Common-mode gain. . . We suggest that you use a resistor substitution box to set the summing circuit’s
gain. Set the gain at ten, and see whether a common-mode signal—a volt or so applied from the input pot,
applied to both inputs—evokes the output you would expect. (Do you expect zero output?)
. . . (Pseudo-) Differential Gain Then ground one input (the 100k that feeds the first op amp’s inverting
input, using the level from the potentiometer as input. Watch that input, and the circuit output, with the R
substitution box values set to 100k: see if you get the expected gain of +10.
• Yes, the gain is positive when the input pot drives the non-inverting input to this home-made op amp,
since two inverting stages follow the diff amp;
• we are applying a “pseudo-differential” signal by grounding one input of the diff amp and driving the
other. (You did this also in Lab 5, as you drove the home-made “op amp.”.) Since the differential gain is
so much higher than the common-mode, this pseudo-differential signal works almost as a true differen-
tial signal would: an applied signal of v appears as a differential signal of magnitude v, combined with
a common-mode signal of magnitude v/2. Given even a mediocre CMRR, this modest common-mode
signal mixed with the differential is harmless.
A DVM may be handier than a scope, at this point, to confirm that the output of this chain of three op-
amp circuits shows a pseudo-differential gain of +10, while you drive the input with the input potentiometer
voltage. When you finish this test, leave the output voltage close to zero volts.
You have already tested the motor driver. Let’s now check the three new stages—those that form the pseudo
op amp—by letting their output feed the motor-driver. Confirm that you can make the motor spin one way,
then the other, by adjusting the input pot slightly above and then below zero volts. (The motor-driven pot
fortunately can take the pot to its limit without damaging pot or motor4 .)
3 This inversion is included so as to let this signal share a polarity with the “Derivative” and “Integral” signals, soon to be generated;
slippage.
8 Lab 10: Op Amps V: PID Motor Control
Figure 8: Try making motor spin, to test the diff amp, gain stage, sum and motor drive
Now reduce the gain, using the R substitution box: set gain to about 1.5 (RSUM = 15k). Replace the ground
connection to the inverting input of our “pseudo op amp” with the voltage from the output potentiometer.
Watch Vin on one channel of the scope, Voutput−pot on the other channel. If a digital scope is available, this
is a good time to use it, because a very-slow sweep rate is desirable: as low as 0.5 second- or even 1 second
-per division.
Lab 10: Op Amps V: PID Motor Control 9
Several ways to test the loop: Apply Voltage Steps, by Hand or from Function-Generator? Two or
three methods are available to you, to test the new setup:
You start with a very low gain (1.5), which should make the circuit stable, even in this P-only form. Now use
the substitution box to dial up increasing gain. At RSum = 220k (|gain| = 22) we saw some overshoot and
a cycle or two of oscillation, evident in the motion of the motor and pot shaft. If this shaft were controlling,
say, the rudder of an airplane, this effect would be pretty unsettling. The circuit works—but it would be nice
if we could get it to settle faster and to overshoot less.
Increasing the gain, at RSum = 680k (|gain| = 68), we were able to make out several cycles of oscillation
(the bigger, uglier trace shows the motor drive voltage; there the oscillation is more obvious):
Figure 10: P only: gain is high enough to take us to the edge of oscillation
With a little more gain (RSum = 1M, in our case —|gain| = 100) and the application of either a step change
at the input, or a displacement of the output pot by hand we saw a continuous oscillation. Find the gain that
sets your circuit oscillating, and then note the period of oscillation, at the lowest gain that will give sustained
oscillation. We will call this the period of “natural oscillation,” and soon we will use it to scale the remedies
that we’ll apply against oscillation.
10 Lab 10: Op Amps V: PID Motor Control
Well, of course we can get it to settle faster; we can improve performance. (If we couldn’t, would the name
of this sort of controller include the “I” and “D” in its name, ‘PID”?)
We can speed up the settling markedly, and even crank up the P gain (“proportional”) a good deal, once
we have added this derivative. Thinking of the stability difficulty as a problem of taming the phase shifts of
sinusoids—as we did for op amps generally—we can see that inserting a derivative into the feedback loop
will tend to undo an integration.
The integrations are the hazard, here: one is built in, the translation from motor rotation to motor position.
Additional integrations resulting from lagging phase shifts can carry us to the deadly minus-180-degree shift
that converts nice feedback into nasty—the sort that brings on the oscillation you have just seen.
The standard op amp differentiator shown below can contribute its output to the summing circuit. Here, we
show the entire prior circuit, with the differentiator added. The differentiator’s gain is rolled off at about
1kHz.
Our goal, in adding derivative, is to cancel the extra phase shift otherwise caused by a low-pass effect that
brings on instability. How do we know at what frequency this trouble occurs, and therefore how to set the
frequency-response or (equivalently) gain of the differentiator?
It turns out that you already have this information: you got it by measuring the frequency (or period) of
“natural” oscillation, back in section §10L.2.6. There, as you know, you gradually increased the P-only
gain till you saw that an input disturbance would evoke either an output that took a long time to settle, or a
continuous oscillation. (When we ran that experiment, for example, we got a “natural oscillation” period of
roughly 0.6 second).
We aim to make the derivative contribution, D, equal to the P contribution, at the “corner” frequency where
sustained oscillation would occur. The D should keep the loop stable, until yet another low-pass cuts in; at
that point, we should have arranged to make the loop gain safely low: less than unity, so that a disturbance
must die away.
RC defines the differentiator’s gain (you’ll find an argument for this proposition in the Class Notes for Op
Amps 5, in case you need to be persuaded). Here, we reproduce the argument made in those Op Amps 5
notes, for setting the D gain.
input is volts/second; output is volts; the conversion factor needs units of seconds.
A Scaling Rule of thumb: frequency of natural oscillation dictates“D” gain. If as this formula suggests,
RC should be about 1/6 of the period of natural oscillation, then for our Toscillation = 0.6s we’d set RC to
12 Lab 10: Op Amps V: PID Motor Control
about 0.1 s, or a bit less.5 If we use a convenient C value of 0.1 µF, the R we need is about 1M. Let’s make this
value adjustable, though—because we want to be able to try the effect of more or less than the usual derivative
weight: if you have a second resistor substitution box, use it to set the differentiator’s gain (RC). Otherwise,
use a 1M variable resistor. Watching the position of the rotator will let you estimate R to perhaps 20 percent;
the midpoint value certainly is 500k, and 750k is close to the 3/4-rotation position. The differentiator’s output
goes into the summing circuit installed earlier, through a resistor chosen to give this D term weight equal to
the P ’s.
We hope you will find this D to be strong and effective medicine. Once it has tamed your circuit’s response—
eliminating the overshoot and ringing—crank up the P gain, to about twenty (RSUM GAIN = 220k) or more.
Is the circuit still stable? If not, try more “D.” Does an excess of D cause trouble? The scope image of the
circuit’s response will let you judge whether you have too much or too little D: too little, and you’ll see
remnants of the overshoot you saw with “P-only”; too much D, and you’ll see an RC-ish curve in the output
voltage as it approaches the target: it chickens out as it gets close.
Switch The toggle switch across the feedback resistor will let us cut D in and out; the switch seems prefer-
able to relying, say, on a very-large variable R to feed the summing circuit. We find it can be hard to keep
track of multiple pot settings, to know whether we’re contributing D or not. A switch makes the ON/OFF
condition easier to note.
Adding the third term—the “I” of PID—can drive residual error (a difference between the input pot voltage
and the output pot voltage) to zero. In today’s circuit, that residual error is hard to see on the scope, so
adding I will not reward you as adding D did. Your best hope will come if you cut the P gain very low: try
RSum = 100k, so that the circuit feedback ought to tolerate a residual error, when not fed an I of the error.
If you have been using a function generator to provide step inputs to your circuit, now replace that signal
source with the manually-adjusted pot input. Slow the scope sweep rate, to a rate that permits you to see the
multi-second effect of the integration.
5 See.,
e.g., Tietze and Schenk, Electronic Circuits: Design and Applications (1991). A less formal approach appears in
St.Clair’s paperback tutorial, self-published (”Controller Tuning and Control Loop Performance” By David W. St. Clair ISBN
0-9669703-6 Straight-Line Controls, Inc.; from his website (members.aol.com/pidcontrol/) one can download a simulator that al-
lows one to try his rules. The easiest simulator, along with a good tutorial, appears in a University of Exeter, U.K., site
(http://newton.ex.ac.uk/teaching/CDHW/Feedback/). The simulation lets you try (as you would expect!) the effect of varying P gain and
of adding in D and I—just as we do in today’s lab.
Lab 10: Op Amps V: PID Motor Control 13
If you are using a digital scope, you will be able to watch input (“Target”), output (“Motor pot”)and Integrator
signals, after a step input applied from your input potentiometer. If you are patient, you can even make out
the effects of the motor and pot’s “sticktion”: the motor and pot do not move smoothly in response to a
slowly-changing input (the I term6 ). Instead, the motor fails to move till the I voltage reaches some minimal
level; then output voltage jumps to a new level, and waits for another shove. You can see these effects in
some of the scope images attached at the end of these lab notes.
It sounds dangerous, doesn’t it?—tacking in an integral term when integration, plus other lagging phase
shifts, are just what threatens the circuit’s stability. It is dangerous, as you can confirm by overdoing the I.
You should be able to evoke continuous oscillation, as in the dark days before you knew about the stabilizing
effect of D! Yet, remarkable though this fact is, some I does improve loop performance, and need not bring
on instability.
Figure 14: Increasing P-only gain, taken to brink of oscillation; and effect of integration term
lb op5 pid oct10.tex; October 6, 2010