Sie sind auf Seite 1von 13

Lab 10c: More Op Amp Applications: PID Motor Control

130 min.: 2 hours, 10 min.

Lab 10c: More Op Amp Applications: PID Motor Control


REV 01 ; February 22, 2006

Reading Proportional-Derivative-Integral (PID) Loops Were afraid the Text doesnt treat this topic, except very indirectly. This indirect treatment appears in the sections of Chapter 4 on op amp stability and compensation ( 4.33 4.35). Well hand you our rough notes on the topic.

Lab Exercises 1. PID motor control (a) (b) (c) (d) motor driver pseudo op amp drive the motor close the loop 25 min. 25 min. 10 min. 15 min. 40 min. 15 min.

2. add derivative 3. add integral

Introduction Todays 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 difculty: 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 ultimately will include three functions of the circuit error signal: proportional, integral, and derivative. Stability is the central issue. We hope youll nd it gratifying to notice that todays circuit gives you a chance to apply several subcircuits that you have met before: integrator, differentiator, summing circuit, push-pull brought within feedback loop, plus a differential amplier (the behavior of this last is familiar, but today is your rst chance to build one out of op amps). This exercise also provides a rst chance to use multiple op amps in one larger circuit, and it returns you to the stability problems of Lab 10b. Today, the remedies will be subtler than those we applied in the earlier lab.

PID Motor Control

The task we undertake here looks simpler than it is. As weve said, all we aim to do is control the position of a DC motors shaft, by letting it drive a potentiometer and feeding back the pots voltage. Heres the scheme:
Revisions: add list of lab exercises; renumber as 10c (2/06); cut long discussion of general theory (moving it to PID Notes); add gure and discussion of excess Deriv oscillation (10/05);x Vsubscripts per Paul complaint, x ckt gure to show 100k rather than 1M as gain of 10, and RSUM = 100k as moderate gain, suggest crank up gain to 20, rather than 10 at sec. 3.1 (10/04); replace current- with voltage-drive, 10/02; cut active lter, 9/02; revise ckt to adjust overall gain rather than P separately: add annotating balloons to gures, & explan. of D gain 3/02.
1

Lab 10c: More Op Amp Applications: PID Motor Control

Figure 1: Basic Motor-Position Control Loop: Very Simple!

What could be simpler? Not much, on paper. But the challenge turns out to lie in keeping the circuit stable. The issue is fundamentally the same as the one you met in Lab 10b, when you noticed that a low-pass in an op-amps feedback loop could turn negative feedback into positive, if we werent careful. The problem arose from the fact that an op amp provides -90 degrees of phase shift, so that just 90 degrees more can get us into trouble. Another way to say thatand a way that may be more appropriate to todays circuitis to note that the op amp acts like an integrator, above a few tensof Hz. This integration effected by the naked op amp results from the internal compensation that rolls off its gain so as to keep the feedback circuit stable. In todays circuit we are stuck with a similar -90 degree shift, or an integration. This time, it comes not from the op amp. We avoid that effect by not using the naked op amp, and so can hide from its phase shift. Instead, the integration comes from the nature of the stuff we are putting inside the loop: a motor whose shaft position we are sensing. We drive the motor (with a voltage); it spins for a while, at a rate proportional to the applied voltage. The position it achieves is the time integral of the spin rate. That last proposition means we are stuck with an integration inside the loop. And heres a reminder of todays circuit:

Figure 2: Proportional-only drive will cause some overshoot; gain will affect this

Soon, much as in the active-lter case, we will try out gradually increasing the gain. We should nd the circuit fairly stable for low gains, then as we increase gain we should begin to see overshoot and ringing, evidence of the circuits restlessness; at still higher gains, the circuit should oscillate continuously. At the end of these notes we attach some scope images describing just such responses to variations in simple proportional gain.

Lab 10c: More Op Amp Applications: PID Motor Control

25 min.

1.1

Motor Driver

Lets start with a subcircuit that is familiar: a high-current driver, capable of driving a substantial current (up to a couple of hundred milliamps). Well use the power transistors youve met before: 2N3055 (npn) and 2N2955 (pnp). The motor presents the kind of troublesome load likely to induce parasitic oscillations, as in the last exercise of Lab 10b. 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 supply disturbances from upsetting the target signal. Similar caps at the ends of the motordriven potentiometer aim to stabilize the feedback signal. We also suggest that you use an external power supply to provide the motors 15V supplies; we do this not for decoupling, but because the motors maximum current exceeds the breadboards 100mA rated output, and might have disturbed those supplies even if one inserted plenty of decoupling caps. The external supply, unlike the breadboard supply, can provide the necessary current.

Figure 3: Motor-driver

Wire up the two potentiometers, as well. The resistors at the ends of the two potentiometers6.8k resistors on input, 4.7k resistors on the motor potrestrict 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. Dont 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:

Lab 10c: More Op Amp Applications: PID Motor Control

Figure 4: Motor drive hash looks like a parasitic oscillation. . .

But if we look at this hash more closely, we nd some clues that it is not the usual parasitic oscillation at work:

Figure 5: Motor drive hash seen in greater detail: not parasitic oscillation, after all

These spikes seem to be the effects of the DC motors brushes breaking contact periodically with the motors 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 cluepretty conclusiveis the fact that the spike voltages exceed the power supply: looks a lot like an inductor (the motor winding) getting angry when we try to switch it off. So, dont let this hash worry you. Its ugly, but well 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). 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 dont want a hidden inversion, here, to upset our scheme when we later close the loop.

Lab 10c: More Op Amp Applications: PID Motor Control

1.2 Pseudo Op Amp


25 min.

Now we do a strange thing: we use three op amps to make a rather-crummy op-amp like circuit.

Figure 6: Differential Amp Followed by Gain Stage and an inversion

The rst stage you recognize as a standard differential amp. It shows unity gain. The second stage simply inverts 2 ; 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 PIDcontroller: Proportional, Integral, and Derivative. This circuit is a differential amplier, with gain that is adjustable, but never anything like so high as what we are accustomed to in op amps. We need this modest gain, and we need a 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 ordinary op amp shows xed, high gain, and integrator behavior beginning at 10 or 20 Hz. We cannot afford to include such an integrator in our loop, becauseas we have noted abovewe are stuck with another integration, and two integrations in series would get us into trouble, turning negative feedback into positive. We suggest that you use a resistor substitution box to set the summing circuits gain. Set the gain at ten, and see whether a common-mode signala volt or so applied from the input pot, applied to both inputsevokes the output you would expect. (Do you expect zero output?) Then ground one input (the 100k that feeds the rst op amps 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. A couple of features of this test may bear explaining: 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
2 This inversion is included so as to let this signal share a polarity with the Derivative and Integral signals, soon to be generated; these signals will come from circuits that necessarily invert.

Lab 10c: More Op Amp Applications: PID Motor Control

the differential gain is so much higher than the common-mode, this pseudo-differential signal works almost as a true differential 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 conrm 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 nish this test, leave the output voltage close to zero volts.

1.3 Drive the Motor


You have already tested the motor driver. Lets now check the three new stagesthe pseudo op ampby letting its output feed the motor-driver. Conrm 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 motor: the motor continues to spin, once the pot has hits its stop; as weve noted already, the motors gearing has been designed to permit this slippage.)

Figure 7: Try making motor spin, to test the diff amp, gain stage, sum and motor drive

Lab 10c: More Op Amp Applications: PID Motor Control

1.4 Close the Loop


15 min.

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.

Figure 8: The loop closed, at last: Proportional only

Watch Vin on one channel of the scope, V outputpot 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. Several ways to test the loop: Manual or Function-Generator Steps? are available to you, to test the new setup: Two ways to drive the input: square wave from function generator: a function generator can provide a small square wave (0.5V, say), at the lowest available frequency (about 0.2Hz). This input can replace the manual input potentiometer, temporarily. This is probably the best choice, since it provides consistency you cannot achieve by hand. Manual step input: you may, however, prefer the simplicity of manually applying a step input from the input pot: a step of perhaps a volt. The output pot should followshowing a few cycles of overshoot and damped oscillation. An alternative test: Disturb the output, and watch recovery: a second way to test the circuits response is available, if you prefer (and you may want to try this in any case, after looking at the response to a step input): leave the input voltage constant, then manually force the pot away from its resting position, simply by turning the knob of the output pot. Let go, and watch the knob return to its initial positionshowing some overshoot and oscillation, as when the change was applied at the input pot. Start with a very low gain, which should make the circuit stable, even in this P-only form. Try RSum = 100k; now use the substitution box to dial up increasing gain. At RSum = 220k we saw some overshoot and a cycle or two of oscillation. That oscillation is evident in the motion of the Two or three methods

Lab 10c: More Op Amp Applications: PID Motor Control

motor and pot shaft; if this shaft were controlling, say, the rudder of an airplane, this effect would be pretty unsettling. The circuit worksbut it would be nice if we could get it to settle faster and to overshoot less. Increasing the gain, at RSum = 680k, 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 9: P only: gain is high enough to take us to the edge of oscillation

With a little more gain (RSum = 1M , in our case) 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 well apply against oscillation.

2 Add Derivative of the Error


40 min.

Well, of course we can get it to settle faster; we can improve performance. (If we couldnt, 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 problem as a problem of taming the phase shifts of sinusoidsas we did for op amps generallywe can see that inserting a derivative into the feedback loop will tend to undo an integration , at least to some degree. 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 transmogries nice feedback into nasty, and that brings on the oscillation you have just seen.

Lab 10c: More Op Amp Applications: PID Motor Control

2.1 Derivative Circuit


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. Its gain is rolled off at about 1kHz.

Figure 10: Derivative added to Loop

How Much Derivative? 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? We have that information: we got it by looking at the frequency (or period) of natural oscillation, back in section 3.4. 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). To avoid complications, lets assume that the gain of the P path is unity. Then our goal is to arrange things so that the derivative contribution, D, is equal to the P contribution, at the frequency where trouble otherwise 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 denes the differentiators gain (youll nd an argument for this proposition in the PID Notes, in case you need to be persuaded). A differentiators output amplitude grows linearly with frequency; VOUT , in other words is proportional to : VOUTDeriv RC Make D match P, at the critical frequency. We want this VOUTDeriv to equal VOUTProportional . We assume that the P gain is one, at this point. We want to control the frequency at which the D gain equals the P gain. At this frequency, GP = 1 = GD = RC 2f RC = 1 RC = 1/(2f).

Lab 10c: More Op Amp Applications: PID Motor Control

10

A Scaling Rule of thumb: frequency of natural oscillation dictatesD gain. This formula suggests, then, that RC should be about 1/6 of the period of natural oscillation. In our case, where Toscillation = 0.6s, wed set RC to about 0.1 s, or a bit less. 3 If we use a convenient C value of 0.1 F, the R we need is about 1M. Lets make this value adjustable, thoughbecause 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 differentiators 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 differentiators output goes into the summing circuit installed earlier, through a resistor chosen to give this D term weight equal to the Ps. We hope you will nd this D to be strong and effective medicine. Once it has tamed your circuits responseeliminating the overshoot and ringingcrank 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 circuits response will let you judge whether you have too much or too little D: too little, and youll see remnants of the overshoot you saw with P-only; too much D, and youll 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 preferable to relying, say, on a very-large variable R to feed the summing circuit. We nd it can be hard to keep track of multiple pot settings, to know whether were contributing D or not. A switch makes the ON/OFF condition easier to note.

3 Add Integral
15 min.

Adding the third termthe I of PIDcan drive residual error (a difference between the input pot voltage and the output pot voltage) to zero. In todays 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.
See., e.g., Tietze and Schenk, Electronic Circuits: Design and Applications (1991). A less formal approach appears in St.Clairs 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 allows 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 Ijust as we do in todays lab.
3

Lab 10c: More Op Amp Applications: PID Motor Control

11

Figure 11: Integral added, to complete the PID loop

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 pots sticktion: the motor and pot do not move smoothly in response to a slowly-changing input (the I term). Instead, the motor fails to move till I 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. ...but Stability may suffer It sounds dangerous, doesnt it?tacking in an integral term when integration, plus other lagging phase shifts, are just what threatens the circuits stability. It is dangerous, as you can conrm 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.
(end lab notes; scope images follow)

Lab 10c: More Op Amp Applications: PID Motor Control


Scope Images: Effect of Increasing Gain, in P-only loop

12

Figure 12: Increasing P-only gain brings increasing overshoot

Lab 10c: More Op Amp Applications: PID Motor Control

13

Figure 13: Increasing P-only gain, taken to brink of oscillation; and effect of integration term

lb10cPID feb06.tex; February 22, 2006

Das könnte Ihnen auch gefallen