Boost control code mods

Testing and development of Megasquirt 3

Moderators: jsmcortina, muythaibxr

Post Reply
elaw
Super MS/Extra'er
Posts: 2926
Joined: Fri Oct 16, 2009 6:20 am
Location: Wilmington, MA

Boost control code mods

Post by elaw »

(Warning: this is going to be long!)
Well... I think it's time to "come out of the closet" with some mods I've made to the MS3 code. To the devs: if you'd be interested in looking at code or further explanation of what I've done, I'm happy to help in any way I can. And if you don't want to touch it with a 10-foot pole, that's fine too! :lol:

The backstory is that although I had good success with a different engine in the past, I've never been able to get the MS3 boost control to work well on my current engine. Try as I might, I could never find a "balanced" point where gain was high enough that the boost wouldn't overshoot but low enough not to oscillate. So... I set about implementing my own boost-control scheme. Although I do want to make clear that when I say "my own", some of the ideas incorporated are not my own! I'll elaborate on that later.

I started with the 1.2.3 code since that's the most recent for which source is available, and did 4 things:
1 & 2) Made the PID an "ideal" PID (more or less - see below), and made the "initial values" table into a bias table. Both of those ideas are from the current MS3 code.

3) Took an idea from the scheme used in Saab's Trionic system and changed where the P, I, and D values come from. Instead of being fixed numbers, each now comes from a small lookup table which has RPM on the X axis and the absolute value of boost error (ABS(MAP - boost target)) as the Y axis.

Here's why I think that is beneficial. Due to its nature, the "gain" of the turbo-wastegate system varies with engine RPM. At least on my car, no matter what you do with the wastegate, you ain't gettin' no boost at 1000 RPM. So at that RPM the "gain" of the wastegate is essentially zero. At a somewhat higher RPM, around 2750 on my car, the turbo is just barely capable of making enough boost to exceed target, so the wastegate starts to have some "gain" (ie influence over the turbo) but not very much. But as RPM increases the turbo is capable of making more boost and making it faster, so the "gain" of the WG is increased. In my view the "gain" of the WG essentially gets multiplied by the gain of the PID controller, so making the PID gain variable over RPM provides a means of offsetting the varying WG "gain" over RPM to maintain better control of the system.

Having the P, I, and D numbers variable based on boost error essentially allows you to vary the nature of the controller based on conditions. With that feature, when boost is far from target, you can effectively make the controller a PD controller - the P terms brings boost to near the desired level quickly, and the D term controls overshoot - the I term is more or less irrelevant. When the boost is closer to the target, the feature allows you to bring in more I term to make the boost follow the target accurately, reduce P term to compensate for the increased I, and reduce D so the boost duty doesn't overreact to small variations in MAP.

I should add that the above is strictly my "educated guess" interpretation of the design philosophy behind something that was reverse-engineered - I could be completely wrong! But what I will say is that it works well, at least for me.

4) The third change I made was to control "integrator windup". For those not familiar with the concept, here's an example using numbers from my car. Say you're driving at steady-state on a flat surface at 2000 RPM, and floor the throttle. Boost target will go to say 225 kPa, and the turbo will start making boost but not much - a moment after you open the throttle MAP will be about 125 kPa. Since MAP is > 100 kPa, PID boost control will kick in and the integrator will start integrating. Since boost is way below target, the integrator value will rise quickly.

Now look at the situation a couple of seconds later. RPM will be, say, 2500. MAP might be 175 kPa, still well below target, but it's rising faster now as the turbo is starting to really spool. With MAP below target, the integrator value is still increasing.

A couple of seconds after that, at maybe 2750 RPM, the turbo is spooling like crazy and MAP reaches the set target of 225 kPa. At this point the boost controller should be well into opening the wastegate, except... the now-huge integrator value is still telling the controller boost is too low, and the wastegate stays shut (or not open as far as it should be). The result? Boost overshoot. The boost must go above target so the integrator value can be reduced before proper control will be achieved. I know in many cases adding a bunch of "D" term to open the wastegate when boost is rising fast can help with this, but IMHO that's a "band-aid" and brings other issues with it.

So the solution I came up with, in a nutshell, is don't run the integrator when doing so will be useless or counterproductive. With the mods I made to the code, when boost PID is first entered, the integrator is disabled and stays at zero. The integrator only gets enabled after the following conditions are met: both boost target and MAP are above a programmable threshold, ABS(boost error) is < 50 kPa, and D value is < 5. Or in English: when boost target and actual are both in the controllable range (above WG spring value), boost is close to target, and not changing too quickly.

Once those conditions are met, the integrator will continue to run until boost actual or target drops below the set threshold then it gets disabled and zeroed.

I'll continue in a separate post, but here's a log and screenshot showing the results:
Log.png
I think I still need to reduce the D term a bit, but it's working pretty darn well (and I'll take a slight undershoot vs. an overshoot any day).

Oh and one other thing I did that helps tremendously: the code now logs *all* the boost PID-related values. Measured value, multiplier term, and multiplied value for P, I, and D, as well as the end PID calculation and bias value. Also bit 1 of status8 shows whether the integrator is enabled or not.
Last edited by elaw on Fri Jul 11, 2014 5:57 am, edited 1 time in total.
Eric Law
1990 Audi 80 quattro with AAN turbo engine: happily running on MS3+MS3X
2012 Audi A4 quattro, desperately in need of tweaking

Be alert! America needs more lerts.
elaw
Super MS/Extra'er
Posts: 2926
Joined: Fri Oct 16, 2009 6:20 am
Location: Wilmington, MA

Re: Boost control code mods

Post by elaw »

To go with the above, a few screenshots...
Boost control menu:
MS3EL boost menu.png
Boost PID settings window, with new settings at the bottom of the left column:
MS3EL boost settings.png
Note there's also a programmable limit for the integrator - also following the theme of avoiding the integrator trying to make corrections that are not useful.

The "P" table - I and D are similar:
MS3EL boost P.png
The X and Y bins are shared among the P, I, and D tables as it saves memory and I couldn't really think of a reason not to.

Before anyone asks... I will not give out my code without first getting input from Ken and James as I'm not sure if I'm permitted to do that. Also the code contains some changes that are not boost related (mostly to how EGO correction is handled at certain times) so that would have to be discussed.
Eric Law
1990 Audi 80 quattro with AAN turbo engine: happily running on MS3+MS3X
2012 Audi A4 quattro, desperately in need of tweaking

Be alert! America needs more lerts.
muythaibxr
Site Admin
Posts: 8230
Joined: Thu Oct 14, 2004 12:48 pm

Re: Boost control code mods

Post by muythaibxr »

This is something I have thought about for a while, but wanted to avoid as much as possible with the goal of keeping the number of settings reasonable.

I keep thinking we're missing a trick if we need this many settings. So if it works for you I am glad, but I would hate trying to document this for your average joe tuner in a tuning shop that's trying to get you in and out quickly.

Maybe we can brainstorm on the phone sometime this weekend if you have time (and I still have 4 of your SD cards that I lost and found again recently, so I'll need to send those back too or pay you for them).

Ken
Megasquirt is not for use on pollution controlled vehicles. Any advice I give is for off road use only.
elaw
Super MS/Extra'er
Posts: 2926
Joined: Fri Oct 16, 2009 6:20 am
Location: Wilmington, MA

Re: Boost control code mods

Post by elaw »

Ken,
Sounds good! Although I'm wicked busy this weekend... I might have time to talk Sunday night if you're around.

I'm definitely with you on the KISS approach... my philosophy too is that if you haven't found a simple solution to a problem, you probably haven't found the right solution. But I do know that (I think more than one) OEMs do use various forms of variable P/I/D. And integrator windup is a known issue even with more "conventional" control systems where the PID runs much closer to steady-state vs. this application where it's constantly being activated and deactivated and the amount of authority the controller has varies dramatically depending on operating conditions.

As far as tuning being difficult, at the highest level that's completely true - there are many more settings. But on the other hand, if the "difficulty" you're experiencing is finding a compromise P value because one value works at low RPM and a very different value works at high RPM, the ability to tune with more granularity is beneficial.

It seems like a sensible approach if any/all of this was implemented would be to have a "regular/advanced" selectable tuning mode or something like that.

But one way or another, I'd like to put in a huge plug for making the PID variables loggable. Logging MAP/target boost/boost duty you can see *what* the controller is doing, but not really *why* (or maybe "how"). Being able to see the component variables that make up boost duty I think helps tremendously to knowing what to adjust to correct issues.
Eric Law
1990 Audi 80 quattro with AAN turbo engine: happily running on MS3+MS3X
2012 Audi A4 quattro, desperately in need of tweaking

Be alert! America needs more lerts.
muythaibxr
Site Admin
Posts: 8230
Joined: Thu Oct 14, 2004 12:48 pm

Re: Boost control code mods

Post by muythaibxr »

I am with you on the logging for the PID algos, just had not gotten to it myself yet.
Megasquirt is not for use on pollution controlled vehicles. Any advice I give is for off road use only.
tpsretard2
Master MS/Extra'er
Posts: 662
Joined: Thu Feb 14, 2008 4:59 am

Re: Boost control code mods

Post by tpsretard2 »

have you tried changing the code in open loop mode to use map insted of tps.

This is just to test. i use a generic pwm output and it works better than all the option there are now. not saying your approach will not work, it should work the best out of all. however it is VERY complicated due to the amount you need to set.

Also when spending hours for your self it is one thing, when doing it for a client you are going to get looked at very strange when you give them a LARGE bill for you time to just setup boost control.

There is a reason other ecu's do it the way i suggested. some with a few other little additions to make it better, but it is all very simple in comparison.

Even if you do not let the public have it, you should try my suggestion to see how it works.
elaw
Super MS/Extra'er
Posts: 2926
Joined: Fri Oct 16, 2009 6:20 am
Location: Wilmington, MA

Re: Boost control code mods

Post by elaw »

I actually did try that, and was able to make it work but not as well as I wanted.

I think your scheme basically amounts to a "P-only" controller that has variable bias and gain over RPM (both being dependent on the PWM values you program). It's a very sensible solution, but my setup didn't respond that well to it.

I think a big part of my problem is a noisy MAP signal (at 20 PSI, the needle on my mechanical boost gauge is just a blur covering about a 4 PSI range), and that creates issues with both P and D terms in a PID controller. The I term responds more slowly so using it heavily and going light on P and D works better for me.
Eric Law
1990 Audi 80 quattro with AAN turbo engine: happily running on MS3+MS3X
2012 Audi A4 quattro, desperately in need of tweaking

Be alert! America needs more lerts.
bcrx7
Helpful MS/Extra'er
Posts: 110
Joined: Sun May 02, 2004 5:37 pm
Location: Vancouver, BC

Re: Boost control code mods

Post by bcrx7 »

Eric,

I really like this and will follow what you are doing! It will work good on a small engine with a large turbo as boost is not instant at low RPM!
1984 Mazda RX-7 GTM Class (BP Engine + BW-EFR 8374 Turbo Full COP/Sequential on MS3+MS3x)
1986 Toyota 4Runner (22RE running on MS2-Extra 3.2.1)
tpsretard2
Master MS/Extra'er
Posts: 662
Joined: Thu Feb 14, 2008 4:59 am

Re: Boost control code mods

Post by tpsretard2 »

I have never herd of a map being so unstable. Thats crazy.

Your current aproch is amazing and will likely be the ultimate. However i would think a simpler way would also need to be kept.
muythaibxr
Site Admin
Posts: 8230
Joined: Thu Oct 14, 2004 12:48 pm

Re: Boost control code mods

Post by muythaibxr »

TPSretard: Did you ever try the 1.4 code? The method you use only helps a small subset of the people who want boost control. As soon as you want different targets, the idea you are using stops working.

Everyone else? I have been looking for people to test the 1.4 code and I have gotten very little feedback. I would like to get more before I do something as complicated as what elaw has implemented (even as an advanced option).
Megasquirt is not for use on pollution controlled vehicles. Any advice I give is for off road use only.
Matt Cramer
Super MS/Extra'er
Posts: 17507
Joined: Thu Apr 16, 2009 8:08 pm

Re: Boost control code mods

Post by Matt Cramer »

muythaibxr wrote:I keep thinking we're missing a trick if we need this many settings. So if it works for you I am glad, but I would hate trying to document this for your average joe tuner in a tuning shop that's trying to get you in and out quickly.
I know at least one other ECU company (Holley) monitors the pressure at the wastegate actuator. Often, the intake pressure tracks well with this, but they claim a PID loop to the actuator pressure is more stable than a PID tied directly to manifold pressure.

Their version of closed loop control over commanded boost uses a table of actuator pressure vs manifold pressure. It looks up what actuator pressure is supposed to deliver the target pressure and uses a PID loop to control that pressure. Then it uses a second PID loop on top of that to adjust the commanded actuator pressure. I know, two nested PID loops sounds quite complicated, but perhaps two stable PID loops work out better than one in some cases.
Matt Cramer -1966 Dodge Dart slant six running on MS3X
elaw
Super MS/Extra'er
Posts: 2926
Joined: Fri Oct 16, 2009 6:20 am
Location: Wilmington, MA

Re: Boost control code mods

Post by elaw »

Yeah, there definitely are an amazing number of boost-control schemes out there! I know back in the early days, both Saab and Audi had the wastegate connected to the *exhaust* rather than the intake manifold! No electronic controls, of course, just a KISS piece of stainless tubing between the two.

I can see where controlling WG pressure would have some pluses, and also some minuses. For one thing, the pressure to the WG is coming from a PWMed solenoid valve - so if you teed a sensor into the line from the solenoid to the WG I suspect you'd see a lot of pressure pulsations. I'd think either a ton of averaging would be required, or you'd have to have/make another port on the WG actuator so you could measure the chamber pressure directly.

The other thing that I think would be a problem is that, depending on your turbo, pressure in the diaphragm chamber is not the only thing trying to open the wastegate. If you have a small turbine housing on the turbo and are running high boost, you can get a lot of pressure in the exhaust manifold. I've heard of exhaust:intake pressure ratios around 1.5 being common, so if you're running 20 PSI boost you might have 30 PSI in the exhaust manifold. Put 30 PSI up against a WG valve face that's one square inch, and you now have 30 pounds of pressure from the exhaust trying to open the wastegate... even if the boost signal going to the wastegate is zero! The tough part is accounting for that pressure when controlling the wastegate... especially if you're like me and prefer to use a soft spring in the WG.

Geez... where's an electric-motor-actuated wastegate without all these weird factors when you need one? 8)
Eric Law
1990 Audi 80 quattro with AAN turbo engine: happily running on MS3+MS3X
2012 Audi A4 quattro, desperately in need of tweaking

Be alert! America needs more lerts.
jsmcortina
Site Admin
Posts: 39612
Joined: Mon May 03, 2004 1:34 am
Location: Birmingham, UK
Contact:

Re: Boost control code mods

Post by jsmcortina »

elaw wrote:Geez... where's an electric-motor-actuated wastegate without all these weird factors when you need one? 8)
Something similar here http://www.msextra.com/forums/viewtopic ... 25&t=54744

James
I can repair or upgrade Megasquirts in UK. http://www.jamesmurrayengineering.co.uk

My Success story: http://www.msextra.com/forums/viewtopic ... 04&t=34277
MSEXTRA documentation at: http://www.msextra.com/doc/index.html
New users, please read the "Forum Help Page".
elaw
Super MS/Extra'er
Posts: 2926
Joined: Fri Oct 16, 2009 6:20 am
Location: Wilmington, MA

Re: Boost control code mods

Post by elaw »

Aah... I have been lusting after a VNT turbo forever!

But it seems most of the ones readily/cheaply available are on the large side and would take forever to spool on my 2l motor.

I did read a Honeywell article that mentions having variable vanes on the compressor as well as the turbine... just to complicate things even more!
Eric Law
1990 Audi 80 quattro with AAN turbo engine: happily running on MS3+MS3X
2012 Audi A4 quattro, desperately in need of tweaking

Be alert! America needs more lerts.
bcrx7
Helpful MS/Extra'er
Posts: 110
Joined: Sun May 02, 2004 5:37 pm
Location: Vancouver, BC

Re: Boost control code mods

Post by bcrx7 »

muythaibxr wrote:TPSretard: Did you ever try the 1.4 code? The method you use only helps a small subset of the people who want boost control. As soon as you want different targets, the idea you are using stops working.

Everyone else? I have been looking for people to test the 1.4 code and I have gotten very little feedback. I would like to get more before I do something as complicated as what elaw has implemented (even as an advanced option).
Unfortunately I am not at a stage were the car is fully ready for high boost. Still sitting in the shop and waiting for a few parts to finish brake and rearend. I will test it as soon as I have brakes and can go to the dyno!
1984 Mazda RX-7 GTM Class (BP Engine + BW-EFR 8374 Turbo Full COP/Sequential on MS3+MS3x)
1986 Toyota 4Runner (22RE running on MS2-Extra 3.2.1)
tpsretard2
Master MS/Extra'er
Posts: 662
Joined: Thu Feb 14, 2008 4:59 am

Re: Boost control code mods

Post by tpsretard2 »

i got it working to a point, the 1.4 code is definitely A LOT better.

If i have it setup in rode trim i can get it very close, but in higher gears it still over shoots. with the als on it is almost pointless.

The turbo is very mismatched for my car and the resrtictor dos not help. If i unplug the host of the wastegate. i can accelerate first gear and get about 16psi. 2nd gear is only about 18-20, 3rd i start to get good boost will hold 25 4th, 5th and 6th is then clear passed 30.

the map signal is also very noisy with the ALS on as there are a lot of reversions from the turbo as there is no blow off valve, part throttle the turbo surges badly from 3,000rpm to the limiter when off or part throttle.

Most cars i can get it setup, fine, my biggest problem is people not wanting to pay me to do it as it just takes to long, so most i just use a copy that i compiled my self with boost in open loop mode changing tps to map. If they are willing to pay or if it is a car that is part of the shop i will use the 1.4 code as is, as cost is no object at this point.
lotushiast
MS/Extra Newbie
Posts: 30
Joined: Mon Sep 10, 2007 4:16 am
Location: COLOGNE/GERMANY

Re: Boost control code mods

Post by lotushiast »

Is it possible to use this electrical wastegate actuator as in this link?
http://www.ebay.co.uk/itm/FORD-MONDEO-T ... 259252639f

Thanks Harald.
muythaibxr
Site Admin
Posts: 8230
Joined: Thu Oct 14, 2004 12:48 pm

Re: Boost control code mods

Post by muythaibxr »

Matt Cramer wrote:
muythaibxr wrote:I keep thinking we're missing a trick if we need this many settings. So if it works for you I am glad, but I would hate trying to document this for your average joe tuner in a tuning shop that's trying to get you in and out quickly.
I know at least one other ECU company (Holley) monitors the pressure at the wastegate actuator. Often, the intake pressure tracks well with this, but they claim a PID loop to the actuator pressure is more stable than a PID tied directly to manifold pressure.
Right, but do any factories set things up this way? How do people change their plumbing, etc... to handle this?
Their version of closed loop control over commanded boost uses a table of actuator pressure vs manifold pressure. It looks up what actuator pressure is supposed to deliver the target pressure and uses a PID loop to control that pressure. Then it uses a second PID loop on top of that to adjust the commanded actuator pressure. I know, two nested PID loops sounds quite complicated, but perhaps two stable PID loops work out better than one in some cases.
Yeah, that sounds painful to tune too.

Ken
Megasquirt is not for use on pollution controlled vehicles. Any advice I give is for off road use only.
elaw
Super MS/Extra'er
Posts: 2926
Joined: Fri Oct 16, 2009 6:20 am
Location: Wilmington, MA

Re: Boost control code mods

Post by elaw »

lotushiast wrote:Is it possible to use this electrical wastegate actuator as in this link?
http://www.ebay.co.uk/itm/FORD-MONDEO-T ... 259252639f

Thanks Harald.
Hmmm... that's intriguing!

There doesn't seem to be much info out there about it... although I suspect it's made for variable-geometry turbos and not a conventional wastegate. VGTs are easier to control with a servo than poppet- or flapper-type wastegates are.
Eric Law
1990 Audi 80 quattro with AAN turbo engine: happily running on MS3+MS3X
2012 Audi A4 quattro, desperately in need of tweaking

Be alert! America needs more lerts.
Post Reply