Engineering Limits Challenged: Metering Device Project

In summary, the engineer is looking at a metering device that has an electromagnetic coil that actuates it, a variable resistor as a sensor for the actual position, and the ability to respond to changes in inputs quickly. They are considering having part of it analog (perhaps just a P-D loop), and are thinking about using a microcontroller to control it. They are looking for a voltage to PWM controller, and are concerned about stability.
  • #1
Rx7man
425
189
TL;DR Summary
looking for ideas for an analog PID loop
Once again I'm looking at a project that is challenging my engineering limits!
I have a type of metering device that has an electromagnetic coil that actuates it, it's designed to be relatively linear motion depending on amperage applied through it, and it has a variable resistor as a sensor for the actual position. It should be able to respond to changes in inputs quickly, which is one reason I'm considering to at least have part of it analog (Perhaps just a P-D loop, the integral could be software controlled)
I know it's possible to do everything in software, but if I can save processor power and code simplicity with a couple op-amps, I think it's a good move.
The microcontroller will either be a 3.3 or 5V unit (probably 3.3 because of processing power)
I found this image which may work with some minor modifications (supply rails would be 0 and +5V or +12V)
pid-analog-controller.jpg


the second part is the output stage, wondering what sort of transistor and design would be well suited for it..there will be a low side current sense resistor, and low side switching would definitely simplify things.. I think 10A peak current is a reasonable starting point (I'm getting more detailed specs soon hopefully)

Here's a sketch of the physical portion, sorry for the terrible artistry
1596076811660.png


Block diagram of the electrical side of it

1596077735293.png
 

Attachments

  • 1596077547406.png
    1596077547406.png
    7.8 KB · Views: 298
Engineering news on Phys.org
  • #2
I would use the output voltage of the PID controller to control the duty cycle of a low-side N-channel MOSFET. A Schottky flyback diode across the inductor will protect the driver from flyback, and provide a path for flywheel current through the inductor while the MOSFET is off.

Choice of component rating will depend on solenoid specifications.

You must find a voltage to PWM controller. The simplest solution would be an LM555 timer, or a microcontroller with A-D inputs and a PWM output.
 
  • Like
Likes Rx7man and Averagesupernova
  • #3
I'm certainly not an expert on control loops but I do know that delay in the feedback signal will cause instability. Your coil/spring gadget has this type of delay built in. I suspect you need only concern yourself with a PI controller. Drop the D.
 
  • #4
Your controller must be able to outrun the dynamics of the physical system, so the “high-pass” differential part will be essential to stability. The “low-pass” integral part of the PID corrects only the long term error in position.

You will probably need an error amplifier with a controlled gain between the PID output and the PWM controller.
 
  • Like
Likes Averagesupernova
  • #5
@Rx7man, how quick does it need to change? After my post I started thinking about it and @Baluncore posted what I second guessed. As I said, I'm not an expert in control loops. Fascinating stuff and I'll be watching this.
 
  • #6
Averagesupernova said:
how quick does it need to change?
It is not the speed you need to move that is important. It is the speed the load can move while you are trying to control it that is important.

It would be easier to control if the solenoid was filled with silicon grease, or an attached dashpot with oil. Then the electronics would not need to respond as quickly, but you would be limited in how quickly you could then move the load.
 
  • Like
Likes Averagesupernova
  • #7
Baluncore said:
You will probably need an error amplifier with a controlled gain between the PID output and the PWM controller.
In the pic of the schematic I posted, isn't the first op-amp the error amp with a controlled gain?

I'd like to stick to 4 op amps since I can easily get those on a single chip and it doesn't take too much space, so I'd drop the integral,

Averagesupernova said:
@Rx7man, how quick does it need to change? After my post I started thinking about it and @Baluncore posted what I second guessed. As I said, I'm not an expert in control loops. Fascinating stuff and I'll be watching this.
The faster the better! If I can make it so that my code can assume it "just does" what it's told, that would simplify things a lot
This is going to control the fuel control mechanicals on a diesel injection pump, 6 cylinder, 4000 RPM = 200 injections per second or 5 millisecond between events, I think if it took about 10 events for a 90% response that would be adequate. the system has two such devices, one controls the fuel quantity, and the other controls the timing.. they're functionally the same

I know the physical system is designed and engineered for the application, it's just I have no "brain box" for it.. I'm going to have to have enough to worry about with a PID loop for engine speed/load I don't want to have to worry about what the pump itself is doing
 
  • #8
Here's the pump, it's a real unicorn, it's from the left bank of a Komatsu V12 and I'm thinking of repurposing it into a 5.9 Cummins
H pump.jpg
 
  • #9
Your sketch indicates that is going to be a challenging project. You have a mass/force/spring oscillator whose force is a non-linear function of position.

I second the recommendation made by @Baluncore that some form of mechanical damping be liberally applied if you want fast response. This of course implies a more powerful positioner (solenoid).

The first steps to designing your device are to find:
  • the mechanical resonate frequency
  • decide what accuracy you desire
  • decide the minimum response time from a step input

Here are a few links you may find useful:
https://www.omega.com/en-us/resources/tuning-a-pid-controller
https://www.csimn.com/CSI_pages/PIDforDummies.html

(above found with:
https://www.google.com/search?&q=pid+controller+tuning
https://www.google.com/search?&q=pid+controller+tuning+for+dummies)

(as I was responding) re your post about diesel injectors, try:
https://www.google.com/search?&q=control+law+for+diesel+injectors

That may substantially reduce the control constraints due to the long time constant of the engine and its tolerance to non-perfect control performance. But you don't want the control loop to oscillate, that wears out the injectors to quickly.

Cheers,
Tom
 
  • Like
Likes Rx7man
  • #10
I don't have much control over the physical parts in the system, the pump must have been designed to be friendly to this type of control system.. I have faith in Bosch and german engineering!

I have read a fair bit about PID loops and tuning.. Unless there was something specific you were trying to point out in the last google link, I don't think it applies to this, since this is still a mechanically injected system, not a common rail electronic injector system like in new diesels
 
  • #11
Rx7man said:
this is still a mechanically injected system, not a common rail electronic injector system like in new diesels
Then what is the solenoid in your first post?
 
  • #12
Tom.G said:
Then what is the solenoid in your first post?
It's internal to the pump
 
  • #13
So, basically you are building a governor?
 
  • #14
Averagesupernova said:
So, basically you are building a governor?
Yeah, I suppose so.. it'll have a CAN bus link to an accelerator pedal position sensor and a few other devices (variable vane turbo controller and such)
 
  • #15
Many mechanical injection pumps have a governor that controls fuel input based on the difference between RPM and accelerator position. Have you checked if your pump includes a governor? Have you checked if there is a dashpot built into the solenoid/rack to prevent oscillation flogging the six fuel control valves?

When matching pumps to engines you will need to set the maximum fuel injection limit to get full power without black smoke. The turbo will make that setting more complex.

You show a common ground reference at zero volts. Since control signals move equally above and below ground you will need to use a common reference voltage at about half the supply. Maybe +12V as positive supply, 0V for negative supply, with say +5V as your local analogue common.

Looking at the schematic of the PID I see your error amp at the input. If the error is zero, the output of the PID will also be zero, maybe that will give 50% duty cycle. There needs to be an integral component in the PID so the error can be zero while the output to the PWM can be anywhere between 0% and 100% depending on the force needed to hold the rack and spring in that position.
 
  • #16
I don't have the pump in my possession yet, I've just been involved in a lot of discussions about it and one of two known pumps (that aren't in use) came up for sale.

I was thinking the I term could be software mapped, or at least closely approximated.. let's say you output a 25% duty signal, and that leads to 20% solenoid travel, 50% gives 40% travel, etc.. I don't think I'll be needing 100% travel for a very long time, this pump is capable of 1000HP of fuel, and unless I dump a whole lot of money into the engine internals and transmission, about 600-800HP will be my limit.. The good thing about this is I can reduce the torque at lower RPMs when torsional vibration is very high (the drivetrain killer)

Looking for Analog to PWM chips, I found this one which looks compact and simple with a 0 to 1V analog input which makes for pretty easy sensitivity adjustment
https://www.analog.com/media/en/tec...ata-sheets/LTC6992-1-6992-2-6992-3-6992-4.pdf

For the output, an MCP14A1201 gate driver with a IRFIZ34N Mosfet (integrated flyback, 55V/21A, .04Ohm) transistor..

For the current sense, I looked back at the Dave's EEVblog on choosing a low offset precision opamp for his current sense project, the MAX4238 (1mhz GBWP) or Max4239 (6.4mhz) seems to be the cats meow
I'm told the solenoids take 6 amps peak, so designing it for 10 amps is probably good and makes easy math
using a 0.01ohm shunt resistor at 10 amps yields a .1V drop and 1W power dissipation if I'm doing Ohm's law right, I think 3W resistors in that value are readily available.. to get good resolution on a 3.3V ADC I'd probably go with a 30-33x gain and a lowpass filter in front of it so I don't see the individual switching of the mosfet... I don't think I'd need the extra bandwidth of the 4239 for this.

I'm thinking out loud at this point

To help the P term, could I put a resistor from the "set" pin directly to the PID output? if I choose the value right, it should help keep a constant duty flowing to the output even without a setpoint error... Something like this.. I'm looking at the MCP 6294 quad op amp for this

1596148768365.png
 
  • #17
Rx7man said:
To help the P term, could I put a resistor from the "set" pin directly to the PID output?
Your real problem is R2 across the capacitor that makes it forget the integral component in the capacitor.
 
  • Like
Likes Joshy
  • #18
It's not what the middle op-amp is already doing though, the middle op amp goes off setpoint error while putting a resistor from the setpoint to the output would be adding a linear component to it regardless of setpoint error.
 
  • #19
You have a good point about R2, it's probably to prevent integral windup, or in some literature they call it the reset time I think? don't think you'd want too low a value there for sure
 
  • #20
Rx7man said:
You have a good point about R2, it's probably to prevent integral windup, or in some literature they call it the reset time I think?
Correct.

You seem to be making things progressively more complex, harder to understand, and more difficult to change. You should rationalise the control program down to a simple algorithm. I expect the microcontroller has A-D inputs and a PWM output. Why do you need any analogue?

If you did it all in software the microcontroller would zero the duty cycle when it wakes up, and you could have a digital emergency stop button.

Why do you need to monitor the solenoid current? Is position insufficient? A simple RC LPF connected to the solenoid terminals could feed back to A-D, so integrity/health of the driver loop could be monitored.

You will need to tune the controller once it is running. That is best done by keeping coefficients in microcontroller EERAM. What microcontroller will you use? Can it be reloaded over a USB link or updated over CAN bus?
 
  • #21
I forgot to mention; The IRFIZ34N has an integral parallel diode that might be useful in a bridge, but a low-side MOSFET switch does not need a parallel diode. For MOSFET voltage protection it requires a freewheeling diode in parallel with the solenoid, so solenoid current does not stop flowing completely during the PWM off state. That also gives better efficiency. The diode should be a fast schottky diode, continuously rated to the maximum solenoid current.
 
  • Like
Likes Rx7man
  • #22
Baluncore said:
Correct.

You seem to be making things progressively more complex, harder to understand, and more difficult to change. You should rationalise the control program down to a simple algorithm. I expect the microcontroller has A-D inputs and a PWM output. Why do you need any analogue?

If you did it all in software the microcontroller would zero the duty cycle when it wakes up, and you could have a digital emergency stop button.

Why do you need to monitor the solenoid current? Is position insufficient? A simple RC LPF connected to the solenoid terminals could feed back to A-D, so integrity/health of the driver loop could be monitored.

You will need to tune the controller once it is running. That is best done by keeping coefficients in microcontroller EERAM. What microcontroller will you use? Can it be reloaded over a USB link or updated over CAN bus?
The main reason is I don't want to have to dedicate so much processor time to the calculations.. If you want decent response, I'd figure you'd have to do it every millisecond or so, and it's a fairly intensive operation between the ADC reads, etc.. Yeah, you'll run it on an interrupt, but there are other things that will be interrupt driven as well and managing those priorities is not going to be an easy task either
 
  • #23
Then dedicate a microcontroller to the job of control.

You can set up a real time clock interrupt at 1 kHz. The first task is to update the PID and will take less than 10 usec. Most of the time the processor is asleep.

I agree that writing time critical code in a high level language is a challenge, but it is easier to hand craft assembly code for a microcontroller RTOS kernel than to design, build, debug and tune the analogue PCBs needed for a PID.

The I/O modules are autonomous so you can order an A-D conversion, it will be ready by the next interrupt. A message on CAN bus will call when it arrives, or when it has departed. The PWM will keep running until you update the duty register. The tasks needed can all be independent of program flow.
 
  • Like
Likes Rx7man
  • #24
I've done a lot of this stuff in the past, and here is my most generally useful, crude advice.

1) P (Proportional feedback) is your friend. It is the most stable and easiest to design and use. However, it will have some DC errors left behind.

2) I (Integral feedback) is what you use to fix the DC errors. It can be slow and should be added after you have figured out the P part.

3) D (Derivative feedback) is probably unnecessary and a PIA. Only use it if you have to, and after talking with someone experienced with feedback compensation. It's the best way to make your system oscillate. I would wager that 99% of PID controllers in use have the "D" coefficient set to 0.

BTW, "PID" has always bothered me, like is a special method, gospel, or universal system. In the real world of control systems, we ignore that and talk about poles and zeros in the compensation network in whatever pattern serves your needs. For example how about an IPDPI compensation scheme, which I have done more than once.
 
Last edited:
  • Like
Likes anorlunda, Averagesupernova and Rx7man
  • #25
A couple comments.

1)
Danger, Will Robinson! Danger!
Baluncore said:
you could have a digital emergency stop button.

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
 
  • #26
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
@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
Baluncore said:
@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

  • PF1.asc.txt.txt
    4.2 KB · Views: 218
  • #29
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
DaveE said:
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
Tom.G said:
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
Tom.G said:
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
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
Tom.G said:
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
yungman said:
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
 

Similar threads

Back
Top