Analog PID loop

  • Thread starter Rx7man
  • Start date
  • #26
4,515
80
I read did not read the whole thread. I am just looking at the schematic of the first post on the opamps. I question what is the circuit doing as it looks to be a straight pass gain of 2 circuit. The top one is low pass with pole frequency of about 154Hz. The bottom opamp is high pass with zero frequency of 154Hz. Middle one is straight pass. So the input to output is just straight pass with gain of 2.

I ran LTSpice and that verify my suspicion
PF1 circuit.jpg

PF1 Plot.jpg



I know I don't understand all the details, but a straight pass is a straight, you can see amplitude and phase response are just simply straight pass with gain of 2. The simulation agree with me.

I use OP27 so the performance is out of the picture. I left off the resistors to the +ve input because it's irrelevant. I use single end driving at the input to simplify the circuit. These should not affect the result.
 
Last edited:
  • Like
Likes Rx7man
  • #27
Baluncore
Science Advisor
2019 Award
7,811
2,731
@yungman
I would like to run and modify your model. Can you please post your Ltspice.asc and Ltspice.plt files.
Give them an extra extension.TXT so they can be attached to PF as;
Ltspice.asc.txt and Ltspice.plt.txt
 
  • Like
Likes Rx7man
  • #28
4,515
80
@yungman
I would like to run and modify your model. Can you please post your Ltspice.asc and Ltspice.plt files.
Give them an extra extension.TXT so they can be attached to PF as;
Ltspice.asc.txt and Ltspice.plt.txt
Yes, I was wondering how I can attach the file.
 

Attachments

  • #29
DaveE
Gold Member
657
478
A brief comment about the schematic above (post #26 et. al.). First @yungman is correct, this has a flat frequency response with a gain of -2 (not counting the high frequency issues with op-amp gain-bandwidth limits). Thus it is a "P" controller, and would work just as well if you eliminated amplifiers U1, U2, U3, and U4 (and their associated components) and changed R1 to 50K. You can see this by inspection as @yungman described, it doesn't need a simulator.

However, my real point is that in analog circuits, differentiators only work at low frequencies. The desired frequency response (like H(s) = H0⋅s ) requires infinite gain at infinite frequencies, i.e. an amplifier with infinite gain-bandwidth. You can't buy those. However, the bad part is that the transition from an effective differentiator at low frequencies (where the amplifier works well) to high frequencies (where it doesn't) will essentially guarantee an unstable circuit. This is how you can build an oscillator, if you want. Be very careful with this part of the design.

In practice differentiators are always converted, at higher frequencies, to proportional (i.e. flat frequency response) or integral (decreasing gain with increasing frequency) BEFORE you exceed the amplifier's gain-bandwith product. That's what R12 does in this design.

I have no idea why R5 is included in this design. There may be a good reason, but I don't know what it is.

Finally, op-amps are really good these days, you probably don't need a separate amplifier for each of these different functions, just lots of well chosen R's and C's around one op-amp.
 
  • Like
Likes Rx7man
  • #30
Tom.G
Science Advisor
3,296
2,048
I have no idea why R5 is included in this design. There may be a good reason, but I don't know what it is.
R5 supplies DC feedback around the Integrator. Without R5 any DC input to the circuit, or any input offset in U1 will quickly drive U1 into saturation because it is operating open-loop for DC.

R5, in conjunction with C1, also determines the corner frequency of the integrator (low pass filter as you call it).

In PID controllers the Integrator corner frequency is much lower than that of the Differentiator. Its purpose is when there is a small setpoint error (which there always is do to the finite Proportional gain), the Integrator will accumulate that small error and drive the output to the setpoint.

Cheers,
Tom
 
  • Like
Likes Rx7man
  • #31
4,515
80
R5 supplies DC feedback around the Integrator. Without R5 any DC input to the circuit, or any input offset in U1 will quickly drive U1 into saturation because it is operating open-loop for DC.

R5, in conjunction with C1, also determines the corner frequency of the integrator (low pass filter as you call it).

In PID controllers the Integrator corner frequency is much lower than that of the Differentiator. Its purpose is when there is a small setpoint error (which there always is do to the finite Proportional gain), the Integrator will accumulate that small error and drive the output to the setpoint.

Cheers,
Tom
Not much of an integrator, R5 should be a lot higher to be an integrator.
 
  • #32
DaveE
Gold Member
657
478
R5 supplies DC feedback around the Integrator. Without R5 any DC input to the circuit, or any input offset in U1 will quickly drive U1 into saturation because it is operating open-loop for DC.

R5, in conjunction with C1, also determines the corner frequency of the integrator (low pass filter as you call it).

In PID controllers the Integrator corner frequency is much lower than that of the Differentiator. Its purpose is when there is a small setpoint error (which there always is do to the finite Proportional gain), the Integrator will accumulate that small error and drive the output to the setpoint.

Cheers,
Tom
The thread is about PID controllers. This circuit is intended to be a feedback compensation network, so (nearly) infinite DC gain is acceptable, even common. There will be external negative feedback that isn't shown to control the integrator.

I do completely understand what R5 does, I can sketch the bode plot without a simulator. But, I still don't know why it's there. As I said, maybe there is a good reason; in practice these designs are more complex than the canonical forms.

However, I do agree that it is good practice to clamp the integrator to keep it within a reasonable range to facilitate quick recovery from saturation (anti-windup). This clamp would typically be something non-linear, like a zener. I like to do this, but it is way beyond the scope of this thread. We are also lacking much of the system level information required for detailed design.
 
  • Like
Likes Rx7man
  • #33
4,515
80
Got to be an easier way to do the circuit, I wasn't even trying to get involve in the discussion, just open the thread and the circuit was just so glaring to me, such a big complicate circuit, something must be really wrong, so I stop and look and it's more glaring. I even had to spent 10 minutes putting in LTSpice to make sure before I posted. Whatever integrator or differentiator, this can be done a lot simpler.
 
  • #34
414
185
A couple comments.

1)
Danger, Will Robinson! Danger!


What does Danger Will Robinson mean?
It is a reference to a common bit of dialogue spoken by the robot in the 1960's TV series, "Lost in Space" . The robot often served as young Will Robinson's companion and guardian. The phrase made it into the culture, and still serves as a warning that someone is probably about to make a mistake.


www.quora.com/What-does-Danger-Will-Robinson-mean

In industry an Emergency Stop is required to directly, physically, remove power to a circuit, or directly mechanically disengage or prohibit physical movement.

By definition something is not doing as expected and it is required to take the simplest, most effective means to avoid danger or damage.

In a car the ignition key serves this purpose. (At least it used to until people were more worried about theft than about safety.)

If you need an Emergency Stop button, have it directly disconnect the power source from whatever is being controlled. Do NOT count on ANY semiconductor, or even a relay, to do this.

2)
I don't think you will need a fancy PID controller for this project if it is on a vehicle that a human is driving. The Human has learned in Driver Education training how to implement that algorithm to maintain speed. It seems to have worked rather well over the decades that carburetors were used. A small Derivative term did get added as an 'Acceleration Pump' to keep the engine running for sudden WOT (Wide Open Throttle) activity. (like beating that Yellow light up ahead. :rolleyes: )

Cheers,
Tom
I will certainly have AT LEAST one positive shutdown method.. definitely the key will kill all power, and in "testing" mode I will probably have a big red E stop button as well
This is a diesel, so what I'm looking for is that the fuel rack does what i'm telling it too with reasonable accuracy despite temperature changes, G force changes, etc
Also, since it's a diesel, if there's a physical failure of the solenoid actuator mechanism, cutting electrical power will do nothing to stop it, you need a butterfly in the intake system to starve it of air. Vehicle will be manual, so you'd have a clutch to prevent physically accelerating, but serious engine damage is still no fun..
Here's a great example of what happens!
 
  • #35
414
185
Got to be an easier way to do the circuit, I wasn't even trying to get involve in the discussion, just open the thread and the circuit was just so glaring to me, such a big complicate circuit, something must be really wrong, so I stop and look and it's more glaring. I even had to spent 10 minutes putting in LTSpice to make sure before I posted. Whatever integrator or differentiator, this can be done a lot simpler.
I'm all ears for a simpler analog PID circuit.. The ones that came up when I googled it were all approximately like this though
 
  • #36
DaveE
Gold Member
657
478
Something like this is a simpler version of the compensation network. Fewer components for the same function as the previous posts. But these designs aren't that simple in practice, you do have to know what you want.

edit: BTW R2 and C3 aren't part of "PID". They are there to make it actually work (stability).
img002 (2).jpg
 
Last edited:
  • Like
Likes Rx7man and yungman
  • #37
DaveE
Gold Member
657
478
Diesel trucks are slow compared to the world of electronics. In practice (modern times) this would be a software implemented controller.

All of the ancillary features like start-up, shut-down, response to large transients, tuning, user interface, etc. are about a million times easier with software. The feedback controls could be a one IC solution if you choose the right micro-controller.
 
  • #38
4,515
80
This feels more like a total analog closed loop feedback project. Remember, if you put MPU into the loop, you have to have an ADC to convert the voltage into digital, work on the data, then put it out to a DAC to transform back to analog. Maybe you have much faster ADC inside the MPU now. When I was designing all the MPU controllers, they use Successive Approx ADC inside, it can get slow. You might add an extra pole you don't want and make life much more difficult. I was going to suggest a simple circuit like what DaveE drew in post #36. You have zeros, you have poles in case you need it or leave it if you don't.

In this kind of circuit, the electro mechanical part is the slowest, it can serves as the dominant pole. But it's hard to characterize the exact pole or zero or whatever. I am not an expert on closed loop control system, but I did a few in my career. In this situation, I use faster components( opamps) to make sure they stay out of my way. Use DaveE's type of circuit, start out with R1 and C1 that forms a lag-lead network. I want to lower the gain of the opamp as soon as it's out of the control frequency ( in this case, looks like it's in below 200Hz). I would use C1 to reduce the gain of the loop starting from say 1KHz or so, then adjust R1 to bend the bode plot up to get a smooth single pole crossover.............R2 C2 to me is for emergency fix if still want to be more stable.

I don't go any further after this, I observe. If I power up, and I see the mechanical motion just ease to to the resting point, this is over compensate, all you have to do is make sure the response is fast enough, if so, you are done.

If the motion overshot and ease back to resting position one time, you are still ok. It just have one ring.

If it overshoot, then back under shoot a few times, you still have work to do. Look at the frequency of the oscillation and look at putting a zero to straighten it out.

The characterization of the electro mechanical component is very hard, I found it easier to do it this way. You start out with a sound basic closed loop stability design then try and see. The circuit daveE posted in #36 is a very good start.
 
  • #39
Averagesupernova
Science Advisor
Gold Member
3,625
627
Having witnessed a diesel engine attempt to run away, I would take this project very seriously. Before any more effort is put into this I would determine if you actually need to incorporate a governor into this or just control the position of the rack. We haven't actually been told if this is an automotive project or not. What type of machine will this be powering?
 
  • Like
Likes DaveE
  • #40
4,515
80
If it is some sort of engine control for truck, I won't mess with it. I personally would NOT do anything to experiment on my car for sure, this is dangerous. It's fun and game over here, like pet project, homework that doesn't make any difference to real live. I won't mess with a car where your life depends on it. Last thing you want is your stuff fighting with what's in the car.

That said, there's another even bigger problem with using MPU inside the feedback loop. If the ADC inside the MPU is successive approx type, you have a more serious problem. Inside is doing a whole bunch of comparisons....bigger....smaller........It relies on the input analog signal is stable, not changing. If there's no sample and hold circuit, it tries to compare while the signal is moving......Huston, we got a problem!!!! You literally can fail to acquire the data and have long dead time and can vary from time to time. You cannot model this as poles and zeros. Read the datasheet on the MPU you are using. I doubt it would have a flash ADC inside. Those MPU are meant for monitor voltages so successive approx is good enough.
 
  • Like
Likes Rx7man
  • #41
Baluncore
Science Advisor
2019 Award
7,811
2,731
This feels more like a total analog closed loop feedback project. Remember, if you put MPU into the loop, you have to have an ADC to convert the voltage into digital, work on the data, then put it out to a DAC to transform back to analog. Maybe you have much faster ADC inside the MPU now. When I was designing all the MPU controllers, they use Successive Approx ADC inside, it can get slow.
Control of the solenoid is by microcontroller PWM, which is autonomous, energy efficient and replaces the DAC. The controller does not have to compute faster than the injector rack control.

Microcontrollers for motor control typically have two or more internal A-D converters, with 8 or more MUX inputs. There is plenty of time to do the ADC, it will take less than 20 usec in the background. SAR A-D converters are faster than quad slope by a factor of 1000.

Take at look at an AC motor microcontroller. It is over 100 times faster than is needed for diesel injection rack control. The internal computations can all be 16 bit integer. The PID requires 3 multiplies, one subtraction and 4 additions, which now takes less than 10 usec.

The software solution is the minimum chip count solution. The hardware required is 1. A microcontroller; 2. A low-side gate driver; 3. N-chan MOSFET; 4. Freewheel diode.
 
  • Like
Likes Rx7man and Averagesupernova
  • #42
DaveE
Gold Member
657
478
if you put MPU into the loop, you have to have an ADC to convert the voltage into digital, work on the data, then put it out to a DAC to transform back to analog. Maybe you have much faster ADC inside the MPU now. When I was designing all the MPU controllers, they use Successive Approx ADC inside, it can get slow.
Old school. This part costs $2 and can sample 12bits at 1Ms/sec. There are lots and lots of other choices. IMO, the speed is probably really limited by extra sw features and poor code/algorithms. However, even with a few floating point MACs in each sample period, you can still run much faster than a truck.
https://www.digikey.com/product-detail/en/silicon-labs/EFM32TG11B120F128GM32-B/336-5683-ND/9677675
 
  • #43
4,515
80
I am out of date.
 
  • #44
Averagesupernova
Science Advisor
Gold Member
3,625
627
If it is some sort of engine control for truck, I won't mess with it. I personally would NOT do anything to experiment on my car for sure, this is dangerous.
Then some of the things I do would make you squirm. Not limited to passenger vehicles.
 
  • Like
Likes Joshy and Rx7man
  • #45
DaveE
Gold Member
657
478
I am out of date.
LOL, me too.
BTW, I've never met anybody that is really good at doing this with analog circuits or digital controls (including me). It is really two very different disciplines. There are control system types (like me) that can do the modeling with Laplace transforms or Z-transforms, and can design algorithms, but they either can't do analog design, or they can't write good code (like me).
 
  • Like
Likes Rx7man
  • #46
DaveE
Gold Member
657
478
If it is some sort of engine control for truck, I won't mess with it. I personally would NOT do anything to experiment on my car for sure, this is dangerous. It's fun and game over here, like pet project, homework that doesn't make any difference to real live. I won't mess with a car where your life depends on it. Last thing you want is your stuff fighting with what's in the car.
In any case, don't drive it on the streets. Consider your liability exposure if things go wrong. Like the cost of rebuilding the front of someone's house, replacing a Porsche, or negligent homicide, for example. You just can't do the kind of testing, engineering procedures, and QA that a real car manufacturer is required to do; that the judge/jury at your trial will expect.
 
  • Like
Likes yungman
  • #47
414
185
That was a lot of good reading, thanks for the replies.
This isn't designed to control the SPEED of the engine (that's a slow process and will be done digitally for sure), it's intended to make sure the fuel (or timing) racks are in the position they're commanded to be, which happens pretty quick.

There is hardly anything original on my truck, and being a manual, if something does fail, I can always hit the clutch

Here's what I'm reading right now on analog PID controllers (starts at page 8) https://www.dialog-semiconductor.co...of_a_dc_motor_using_analog_pid_controller.pdf
 
  • #48
DaveE
Gold Member
657
478
I think you can find better references on the web than this one. I have some serious problems with how they've described Integrators. They don't require an error, and they typically don't overshoot. Although how anyone could make a statement about the transient response (overshoot, for example) without fully describing the system dynamics and the gains chosen is beyond me.
 
  • #49
414
185
I think you can find better references on the web than this one. I have some serious problems with how they've described Integrators. They don't require an error, and they typically don't overshoot. Although how anyone could make a statement about the transient response (overshoot, for example) without fully describing the system dynamics and the gains chosen is beyond me.
I'm no expert on this, but just going by the circuit diagram it appears that they all require an error in order to be active, with the exception of the D term which requires a change in error, rather than an absolute error. And the integrator usually would cause overshoot because of windup.. yes, the entire system does need to be taken into account though, but a poorly tuned I term would certainly cause it.

Going back to circuit analysis, I noticed with the electrolytic caps, they have them in serial with backwards polarities.. is this common and good practice for systems where you can have either polarity? Should there be a bypass diode to prevent reverse charging ?
1596384310718.png
 
  • #50
DaveE
Gold Member
657
478
Using electrolytic caps in that way is not a good design practice IMO. There are better ways to get long time constants without them. There are also ways of adding a DC bias into the circuit to ensure the correct polarity at all times if you do use them.
 
  • Like
Likes Rx7man

Related Threads on Analog PID loop

  • Last Post
Replies
1
Views
2K
Replies
4
Views
1K
  • Last Post
Replies
6
Views
991
  • Last Post
Replies
5
Views
1K
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
3
Views
289
  • Last Post
Replies
13
Views
2K
  • Last Post
Replies
2
Views
3K
  • Last Post
Replies
4
Views
1K
Replies
1
Views
3K
Top