PID Engine RPM Controller

Hi Guys,

I'm building an engine speed controller using a 16 bit microcontroller for a gasoline engine. I have a 1.8 degree resolution stepper motor coupled to the throttle plate which moves the throttle angle to the target position.

The objective is to regulate the speed of the engine to one fixed setpoint in terms of RPM. I'm measuring the engine speed with a magnetic pickup and calculating RPM in the microcontroller. My stepper motor driver simply works by setting a direction and number of steps which is generatred from the micro.

I'm trying to set up a good PID control loop. I have implemented some code, but am a bit confused over some of the algorithm options. I'm considering using a velocity form (incremental). Basically, the engine speed is the feedback which is subtracted from a reference RPM and fed to the PID controller. The output of the controller would be throttle angle (I think?). The throttle angle then results in a certain engine RPM for a given load (highly non-linear of course).

The problem I'm having is a conceptual one as to how to treat the stepper motor and the associated input to the "plant". I understand that a stepper motor is a "self integrating" device, but I don't have a good intuitive feel for what that means in real-life.

Is the proper way to implement?:

- Use an incremental algorithm to calculate my *change* in throttle angle for each sample period.

- Take this delta, and translate it to stepper motor steps (and direction) based on the change in throttle angle.

- Update this calculation each sample period

The unknowns to me are:

- Can I use a positional algorithm instead of incremental by taking the PID output and subtracting the last position to generate a delta and send that to the stepper? I have tried implemented the algorithm as positional and simply send the PID output (after translating to # of steps) and send that directly to the stepper - this seems to function but do I wind up with an extra, unwanted integration? In this scenario I interpreted the output of the PID as a delta position as opposed to absolute position, and to my surprise is seems to function reasonably well.

- I am presently running the stepper motor at a fixed speed and always microstepping to 1/8 step. I could conceivably play with both the step speed and the step resolution in real time to create acceleration. Would this be of any benefit.

- I've read about Three-Position Pulse Output type algorithms, which seems to be similiar to what I'm doing - how does this apply?

- My PID sampling period is 30ms. With the current stepper speed, I would take upwards of 200ms for it to travel its entire stroke. This means my actuator would not be finished positioning when the next PID loop rolls around. Is this a problem?

Thanks for any feedback,

Paul

Reply to
Paul W.
Loading thread data ...

This means that the motor output is some form of an integral of it's input. For the stepper motor itself this is a bad analogy -- you've got two phases, four or six wires, you're microstepping, etc. An ideal DC motor is a better model -- you give it a voltage, it goes that speed, therefore its position is the integral of the drive.

If you have some other process that's driving the stepper, and you just tell it the number of steps, then your stepper-driver combo is "self integrating".

This should work depending on a number of things (if you want to be recognized as an engineer practice saying "it depends" in answer to every question).

I assume that what you send to the stepper is a desired number of steps? The difference between outputting an angle vs. an angle delta is that you have that extra integration. So you need to ask if it's unwanted. If the motor needs that derivative term to be stable it probably is, but if you want a type-II loop it probably isn't.

It would also be nice if you know what your throttle position is, for diagnostics if nothing else.

Probably not.

I'm not familiar with the term -- it sounds specific to one type of actuator.

Yes, you'll have integrator windup in your PID. My article

formatting link
touches on integrator windup and gives the most popular method of avoiding it, but doesn't go in depth. I suspect you'll find it useful anyway.

Additional Comments:

  • Stepper motors -- blech.
  • A throttle position feedback would be a good idea.

  • You _really_ want some safety built-in, at least a solenoid that kicks the throttle to idle if your power cuts out, better yet a back-up rev limiter (you can get these on your ignition if it's not already there).

--
Tim Wescott
Wescott Design Services
 Click to see the full signature
Reply to
Tim Wescott

Hi Paul,

Why would a stepper be self integrating in this application? A stepper is an almost instant and pretty digital control when it comes to engines. A step and thus throttle change of 1.8 degrees happens in microseconds whereas the reaction of the engine takes a whole lot longer because of the flywheel and other delay causing elements. So the natural lowpass filter in the actuator section is going to be the engine. Well, maybe unless it was a souped up version from a Ferrari Testarossa :-).

One method to arrive at customary loop responses is to look at a good governor solution. Most stationary engines have governors, for example generators where the output voltage isn't supposed to stray more than 5% or so from spec. This doesn't mean they are all good though. I have just used a wood splitter that had a terrible governor which even caused the engine to bang once in a while.

Regards, Joerg

formatting link

Reply to
Joerg

Okay.

Yes, which could cause problems- if it can't be tuned properly at both extremes of load you'll likely have to add throttle position feedback or load feedforward to deal with the nonlinearity.

Your controller inputs are SP and PV, your output is change in "throttle angle" (or whatever actually results from the stepper motor steps) per Ts.

You don't really have a PID controller if the output is slew-rate limited, but it doesn't sound like this will happen much in normal operation.

I don't think it does. I've used things like this in controls such as heat/cool controls on extruders where some zones are run close to adiabatic (the heat from plasticizing is close to the heat loss, so you may need heating or cooling), but your setup sounds very symmetrical and I don't see much reason for that kind of thing unless you're trying to deal with problems (eg. "hunting") caused by mechanical backlash in the throttle linkage (and the best way to deal with that is to eliminate it).

Probably not except at startup or sudden load increases you might get overshoot/undershoot on the RPM (but 0.2s is not really very long compared to the time constant of the plant, which is more important than the sample time). You'll probably have trouble calculating the

2nd derivative of the RPM, BTW, without some filtering. You might try and see if just a PI controller will work well enough. Windup should not be a problem because you are using a velocity controller.

Best regards, Spehro Pefhany

--
"it's the network..."                          "The Journey is the reward"
speff@interlog.com             Info for manufacturers: http://www.trexon.com
 Click to see the full signature
Reply to
Spehro Pefhany

Tim Wescott wrote in news: snipped-for-privacy@corp.supernews.com:

Yes, correct.

Yes, I believe it does require the derivative term to maintain stability.

When you say "extra integration", do you mean the integration in the PID loop plus the integration in the motor?

I'm looking at a throttle position sensor to confirm this. Although I can know throttle position indirection by keeping track of all the deltas. Assuming the motor doesn't mis steps, then it would always be correct (and he hasn't missed any steps that I know of).

Its where the output is either UP/DOWN/STOP for example, where UP might drive a fixed speed motor opening a valve.

Do you mean that when the position output exceeds the number of steps that can be completed within one sample period is considered windup? In this case, the actuator is not really saturated on an absolute basis, only per sample period.

Yes, I have overspeed/underspeed shut down which cuts the fuel.

Thanks,

paul

Reply to
Paul W

Spehro Pefhany wrote in news: snipped-for-privacy@4ax.com:

Yeah, I must implement some form of gain scheduling, or perhaps even a characterizer to linearize the system.

Ts = Sample Period?

When you say "or whatever actually results from the stepper motor steps", do you mean the case where the motor has reached its maximum number of steps per sample period?

That's what I'm wondering, should my output be absolute throttle angle, or should it be *change* in throttle angle?

Not sure I follow what you're saying. Are you saying that even though the motor is bandwidth limited, it likely doesn't matter compared to the response time of the engine?

I could probably speed up the stepper motor so that it always completes the change in throttle within one PID period.

I'm pretty sure I need derivative, it requires it for stability from my experiments.

You mentioned 2nd derivative, I assume you mean that first derivative is that of the normal PID term, and the 2nd is because it is a velocity algorithm?

Can I implement a software low pass filter to supress high frequency noise?

Thanks,

Paul

Reply to
Preppy

"David Powell" wrote in news:vZ4zc.2155$ snipped-for-privacy@news.indigo.ie:

Got it! Thanks.

Is this true for both the positional and velocity algorithms?

Do you mean the response time of the engine speed to changes in throttle? I don't really know, but is relatively slow in microcontroller terms - probably well over a second at least.

Yes, as best I can.

Instantly, upon application of higher electrical current (we are driving a generator).

Tried that, but it seems to want D for stability.

Thanks!

Paul

Reply to
Preppy

I've implemented valve motor control in a PID temperature controller, which would seem similar. I'm not sure I understand why you need to worry about throttle angle - it's just the output actuator within a closed loop. If you're measuring engine RPM, surely the throttle angle must do whatever it takes to maintain the measured variable (RPM)? What am I missing?

Re delays in your actuator - most real-world processes are laggy, so I shouldn't worry too much unless your I term is inappropriately short.

Steve

formatting link
formatting link

Reply to
Steve at fivetrees

Yes.

I mean that stepper motor steps could be nonlinear wrt throttle angle. For example, if you have a spring return and a linkage so that it shuts off if the stepper motor loses power..

The output of a velocity controller is the rate of change of the controller output, so, given fixed sample time, you can think of it as (proportional to) steps (maybe fractional, maybe + or -) per second and also per sample time.

That's my guess.

Think of the bandwidth of the controlled system (throttle to loaded engine shaft) first, and use a sample time that is appropriate to that (not too fast, not too slow).

Correct- to get the I in PID you need the second derivative of the error term with the velocity algorithm.

Certainly, given the usual caveats of digital filtering.

Best regards, Spehro Pefhany

--
"it's the network..."                          "The Journey is the reward"
speff@interlog.com             Info for manufacturers: http://www.trexon.com
 Click to see the full signature
Reply to
Spehro Pefhany

Ditto, that. I started a project to control huge steam and gas valves using pneumatics. The pneumatic cylinder was controlled by a pneumatic stepper valve. There were problems with the stepper valve shifting to a safe position when power was lost. Also, there were problems getting the initial position set properly. I wouldn't trust steppers valves for anything important.

I bowed out. We did have position feedback for the pneumatic cylinder that was controlling the flow control spool, but when stuff happened, the only sure way I had to make sure the main flow control properly shut or open was to just give the stepper motor on the pneumatic valve a bunch of steps in one direction or the other depending on whether the valve was to fail shut or closed. Well what happens if our controller loses power? We can't make the valve fail in either direction because without power we cannot step the stepper motor. The pneumatic stepper valve would also fail to a neutral postion which would let the main flow control valve move at all.

Peter Nachtwey

Reply to
Peter Nachtwey

You do. Your system has two lags at least. The valve and the motor. This requires a PID for best response.

Shame on those that suggest that just a PI would do.

A second deriviative should be considered if there are many lags.

Yes. The corner frequency should be much higher than the plant frequency so the filter has little affect on the response. I like to use the geometric mean between the same frequency and the plant frequency. I have used up to a four pole Butterworth filter.

One more suggest. As Tim suggested, the integrator WILL wind up. To avoid this, do NOT ramp the set point up faster than what the stepper can respond. In fact, you may want to ramp the RPM as slow as possible. This way the the rate limited stepper will not be a factor.

Peter Nachtwey

Reply to
Peter Nachtwey

Hi Paul,

Yep a stepper motor set up like this is effectively an integrator, ie when you move it to a new position it stays there, it's doesn't return to a zero position when you stop stepping. Most position control systems are integrators by their very nature, ie you tell them to move to a new position they do, and in general it doesn't take much to hold them there.

In this case you would limit the amount of integral gain in your PID controller, as the system has 2 integrators there's a risk it could go unstable :o(

What is the response time of your throttle?? are you trying to maintain a certain engine speeds over a wide range of engine loads?? how quickly can the load change?? you may be able to get away with just a PI controller...

Dave

Reply to
David Powell

In my prototype, I am outputing the positional PID algorithm and translating to a certain number of steps and applying that directly to the stepper motor. i.e. I am treating that output of the PID as if it were a delta, rather than absolute position.

It seems pretty clear to me, based on the comments of all the guys that what I've wound up with is an integrator (the motor) after the PID controller. I can implement the velocity algorithm, but I'm trying to figure out what impact my first attempt has on the response. Does that imply that my "extra" integration is effectively cancelling out the derivative?

Thanks,

Paul

Reply to
Paul W.

Yes. Following a derivative with an integrator cancels the derivative.

--
Tim Wescott
Wescott Design Services
 Click to see the full signature
Reply to
Tim Wescott

Hi,

I had a bit of a re-think last night, the "D" term might be required for stability.

If the engine speed starts to drop off quickly ( say due to an increase in load ) the D term will detect this and cause the output to increase.

Again you have to a bit carefully with the amount of "D" you add in.

Dave

Reply to
David Powell

Excuse me if I am wrong, but

Doesn't the input and output have to be linear (or linearizable) and be able to convert to 0 to 100% to work? And that the System Dynamics have to be stable to be tunable?

Neil

Reply to
Neil Kurzman

Do you think any real system fits both (or even either) of those criteria?

Best regards, Spehro Pefhany

--
"it's the network..."                          "The Journey is the reward"
speff@interlog.com             Info for manufacturers: http://www.trexon.com
 Click to see the full signature
Reply to
Spehro Pefhany

-- snip --

In this case the input and output are both linearizable (no real world systems are linear in the end -- if nothing else they break when you set bombs off next to them, which is not a linear phenomenon).

A system doesn't have to be stable for it to be stabilizable (I assume this is what you mean by "tunable"). Take your average Saturn-V booster with an Apollo crew capsule on top -- this is basically a semi-flexible inverted pendulum with markedly insufficient aerodynamic stabilization. Without control the best that you could hope for is that the thing would be in one piece when it hit the ground, more realistically it would have buckled in the middle someplace before the pieces hit earth. Yet with appropriate sensors and automatic control the think can shoot a couple of men to the moon.

--
Tim Wescott
Wescott Design Services
 Click to see the full signature
Reply to
Tim Wescott

I guess that without actuator position feedback the linearization of the output would have to be mechanical in nature. Not that would necessarily be a problem- a cam and follower can create an arbitrary montonic function, at least in theory.

I think it's even worse than that with the Saturn V- more like two stacked inverted pendulums (still a controllable system). Smaller rockets are not so flexible.. so strapping a whack of smaller rockets together like the Russians did gets around the old bending-in-the-middle-and-exploding issue.

Best regards, Spehro Pefhany

--
"it's the network..."                          "The Journey is the reward"
speff@interlog.com             Info for manufacturers: http://www.trexon.com
 Click to see the full signature
Reply to
Spehro Pefhany

-- snip --

Do you even need to explicitly linearize it? Unless you're really whacking the throttle around the engine's response to throttle changes is going to be monotonically non-decreasing if not linear, even to pulses to the throttle stepper. Assuming that you can sacrifice performance to ease of control system design you should be able to just de-tune the controller to make it all work.

--
Tim Wescott
Wescott Design Services
 Click to see the full signature
Reply to
Tim Wescott

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.