MS-II Closed Loop Boost Control - PID
#61
![Default](https://www.miataturbo.net/images/icons/icon1.gif)
I can see that being helpful for CL boost. However the way I wrote the PID code integral windup is not an issue. I am adding the PID math output to the previous output. This means that I need to take the derivative of the ideal PID form leaving me with an I term that does not wind up. Addionally, as long as I pick my output start point relatively well, It works similarly to other more traditional PID algorithms. In addition, I further modified the PID math so that the P term is not dependent on change in error but change in boost (rpm for idle). In the idle code this makes the P term much more responsive to small changes in rpm due to increased load. In tbe boost code it helps keep overshoot at a minimum. However it does not act exactly like other PID code in that the P term alone will not necessarily get you close to the target.
For idle I would need 2 feedforward tables (cold vs hot air/clt), a curve that linearizes the valve response and the PID numbers if I wanted to add the feedforward table. However I do not really think it would help much if at all compared to the current method, and it would be a lot more complicated to tune. Early in the idle code I did use feedforward, but the valve position that gives a certain rpm varies widely depending on air temp. It did not work well at all. I am leaving the idle code alone for now. As I said in that thread, getting fuel right (no oscillation in AFR) and using the idle advance feature can largely reduce the RPM drop when engaging more load. I am also adding feedforward for the AC button and e-fan to that code (should already be in 3.0.3). That code works and I am sure I can help resolve any tuning issues.
For boost, I am willing to call it a work in progress. My planned changes to this are (in order of what I think is most necessary to improve the algorithm):
1) switch to a type-b loop so that changes in target are handled more quickly by P and I combined instead of just I.
2) Add an "initial condition" table (the open-loop duty table) which sets the initial output for my PID loop to work from.
3) In combination with 2, add a setting which disables PID and just uses the open-loop table until you are <user-settable> kpa from the target.
As far as the way the code works now, I already have a 3d target table based on tps and rpm, and I have the PID vars.
These modifications were all things I was thinking about to improve the algorithm after talking on the phone with wes kiser. However, I would like to get Braineack's setup working before I make any changes. I am 100% confident that given a few more tuning iterations, his boost would have matched the MBC graph (with a fraction of a second ramp to the target).
For more info on how I wrote my PID code, check out: Three Types of PID Equations
Braineack: Just let me know when you are ready. You will have a PM shortly with my phone number.
To explain the behavior in your logs, when boost was dropping off and the duty was dropping too, that was the code trying to close the wastegate and generate more boost. It looks to me like you just needed an I term closer to 50-60% to get it to close fast enough and far enough to hold boost without going overboard and causing overshoot.
Ken
For idle I would need 2 feedforward tables (cold vs hot air/clt), a curve that linearizes the valve response and the PID numbers if I wanted to add the feedforward table. However I do not really think it would help much if at all compared to the current method, and it would be a lot more complicated to tune. Early in the idle code I did use feedforward, but the valve position that gives a certain rpm varies widely depending on air temp. It did not work well at all. I am leaving the idle code alone for now. As I said in that thread, getting fuel right (no oscillation in AFR) and using the idle advance feature can largely reduce the RPM drop when engaging more load. I am also adding feedforward for the AC button and e-fan to that code (should already be in 3.0.3). That code works and I am sure I can help resolve any tuning issues.
For boost, I am willing to call it a work in progress. My planned changes to this are (in order of what I think is most necessary to improve the algorithm):
1) switch to a type-b loop so that changes in target are handled more quickly by P and I combined instead of just I.
2) Add an "initial condition" table (the open-loop duty table) which sets the initial output for my PID loop to work from.
3) In combination with 2, add a setting which disables PID and just uses the open-loop table until you are <user-settable> kpa from the target.
As far as the way the code works now, I already have a 3d target table based on tps and rpm, and I have the PID vars.
These modifications were all things I was thinking about to improve the algorithm after talking on the phone with wes kiser. However, I would like to get Braineack's setup working before I make any changes. I am 100% confident that given a few more tuning iterations, his boost would have matched the MBC graph (with a fraction of a second ramp to the target).
For more info on how I wrote my PID code, check out: Three Types of PID Equations
Braineack: Just let me know when you are ready. You will have a PM shortly with my phone number.
To explain the behavior in your logs, when boost was dropping off and the duty was dropping too, that was the code trying to close the wastegate and generate more boost. It looks to me like you just needed an I term closer to 50-60% to get it to close fast enough and far enough to hold boost without going overboard and causing overshoot.
Ken
#62
Boost Czar
![](/mt2011/images_td/ranks/supporter1.gif)
![](/mt2011/images_td/ranks/admin.png)
Thread Starter
iTrader: (62)
Join Date: May 2005
Location: Chantilly, VA
Posts: 79,688
Total Cats: 4,113
![Default](https://www.miataturbo.net/images/icons/icon1.gif)
Just an update. I appears that during my initial testing, one of the wires for my solenoid ripped out of the body. After repairing and trying this again it seems to be working.
Have the table set for 201kPa, and its averaging 195, so I should lower the P a tiny bit. I ended up having to bring it up to 180%, and judging by the high DC% numbers, I think I need increase the Hz it runs at from 19.5Hz to 26Hz (unless because I'm running inverted the DC% numbers logged are actually in reverse?).
here's a fourth gear log from this morning:
Have the table set for 201kPa, and its averaging 195, so I should lower the P a tiny bit. I ended up having to bring it up to 180%, and judging by the high DC% numbers, I think I need increase the Hz it runs at from 19.5Hz to 26Hz (unless because I'm running inverted the DC% numbers logged are actually in reverse?).
here's a fourth gear log from this morning:
![](http://www.boostedmiata.com/gallery2/d/10091-1/MSII_PID_EBC.png)
#63
![Default](https://www.miataturbo.net/images/icons/icon1.gif)
It's looking pretty good. What PID numbers did you settle on. I plan on using yours as a jump point to adjust until I can get on DIY's dyno for tuning. Hopefully I'll have an appointment for dyno time by the end of May. This engine swap has taken forever. OF course it's turned into a: new engine, trans, suspension, and computer swap.
#64
Boost Czar
![](/mt2011/images_td/ranks/supporter1.gif)
![](/mt2011/images_td/ranks/admin.png)
Thread Starter
iTrader: (62)
Join Date: May 2005
Location: Chantilly, VA
Posts: 79,688
Total Cats: 4,113
![Default](https://www.miataturbo.net/images/icons/icon1.gif)
180
0
0
Don't use my numbers and just do this to tune:
0
0
Don't use my numbers and just do this to tune:
- Set Integral and Differential Gains to 0% - To make tuning the Proportional gain easier, set the Integral and Differential gains to 0%.
- Set Proportional gain to 150% and slowly lower - While tuning Proportional gain, higher numbers mean slower boost climb and lower final boost. For safety, start with a very high gain (150% should be sufficient). Find the RPM that typically spools quickly, and fully and quickly depress the accelerator. Note how much boost is reached. If boost overshoots the target, increase the Proportional gain. Otherwise, reduce the Proportional gain and try again. Do this until boost reaches the target with little or no overshoot.
- Tune the Integral Gain - The next step after the target is reached consistently is to tune the Integral gain. Starting from the RPM used to tune the P-gain, fully depress the accelerator and watch the boost as the engine climbs through the RPM range. As the engine accelerates through the rev range, the boost will probably creep away from the target. Keep increasing the I gain until the controller adequately maintains the target with minimal oscillation.
- Tune the Derivative Gain - If overshoot cannot be tuned out with the P gain on a quick acceleration, increase the D gain until the overshoot is minimized. Care must be taken when increasing the D gain as too much D gain can over-dampen the effects of the P and I gains.
#65
![Default](https://www.miataturbo.net/images/icons/icon1.gif)
180
0
0
Don't use my numbers and just do this to tune:
0
0
Don't use my numbers and just do this to tune:
- Set Integral and Differential Gains to 0% - To make tuning the Proportional gain easier, set the Integral and Differential gains to 0%.
- Set Proportional gain to 150% and slowly lower - While tuning Proportional gain, higher numbers mean slower boost climb and lower final boost. For safety, start with a very high gain (150% should be sufficient). Find the RPM that typically spools quickly, and fully and quickly depress the accelerator. Note how much boost is reached. If boost overshoots the target, increase the Proportional gain. Otherwise, reduce the Proportional gain and try again. Do this until boost reaches the target with little or no overshoot.
- Tune the Integral Gain - The next step after the target is reached consistently is to tune the Integral gain. Starting from the RPM used to tune the P-gain, fully depress the accelerator and watch the boost as the engine climbs through the RPM range. As the engine accelerates through the rev range, the boost will probably creep away from the target. Keep increasing the I gain until the controller adequately maintains the target with minimal oscillation.
- Tune the Derivative Gain - If overshoot cannot be tuned out with the P gain on a quick acceleration, increase the D gain until the overshoot is minimized. Care must be taken when increasing the D gain as too much D gain can over-dampen the effects of the P and I gains.
Thanks again
#66
![Default](https://www.miataturbo.net/images/icons/icon1.gif)
Braineack: that is a pretty good method for tuning boost on ms2. On MS3 it might change a little due to the change I made to the P term, but I'm not sure exactly how to explain it yet. I think the gist would be that the P term is more sensitive and responds to target changes, so you'll probably be able to lower both the P and I terms, and D will be required. Wes Kiser over at the msextra forums was telling me that the new MS3 boost control is able to make the boost climb a lot faster now.
As far as the duty being 70% goes, I'd say if it's working, leave the frequency alone. Just keep up the tuning and get the I and D terms tuned in.
Ken
As far as the duty being 70% goes, I'd say if it's working, leave the frequency alone. Just keep up the tuning and get the I and D terms tuned in.
Ken
#67
mkturbo.com
![](/mt2011/images_td/ranks/supporter1.gif)
![](/mt2011/images_td/ranks/admin.png)
iTrader: (24)
Join Date: May 2006
Location: Charleston SC
Posts: 15,189
Total Cats: 1,685
![Default](https://www.miataturbo.net/images/icons/icon1.gif)
Braineack: that is a pretty good method for tuning boost on ms2. On MS3 it might change a little due to the change I made to the P term, but I'm not sure exactly how to explain it yet. I think the gist would be that the P term is more sensitive and responds to target changes, so you'll probably be able to lower both the P and I terms, and D will be required. Wes Kiser over at the msextra forums was telling me that the new MS3 boost control is able to make the boost climb a lot faster now.
As far as the duty being 70% goes, I'd say if it's working, leave the frequency alone. Just keep up the tuning and get the I and D terms tuned in.
Ken
As far as the duty being 70% goes, I'd say if it's working, leave the frequency alone. Just keep up the tuning and get the I and D terms tuned in.
Ken
PS. Expect lots of beer.
#70
![Default](https://www.miataturbo.net/images/icons/icon1.gif)
So I helped shuiend get his CL boost on ms3 tuned on Saturday. It seems to work pretty well. I told him I could smooth out the boost a little more but he said he was happy with it the way it is now. I've attached that run's datalog for those who want to see it.
It overshot by about 4 kPa as it reached the target. I could've tuned that out with a bit more D term I think, and then the oscillations later were probably because of a P term that was slightly too high, but all in all it looks good.
![](https://www.miataturbo.net/attachments/megasquirt-18/16354d1271283834-ms-ii-closed-loop-boost-control-pid-boostctl.png)
Ken
It overshot by about 4 kPa as it reached the target. I could've tuned that out with a bit more D term I think, and then the oscillations later were probably because of a P term that was slightly too high, but all in all it looks good.
![](https://www.miataturbo.net/attachments/megasquirt-18/16354d1271283834-ms-ii-closed-loop-boost-control-pid-boostctl.png)
Ken
#71
![Default](https://www.miataturbo.net/images/icons/icon1.gif)
i cannot WAIT to try this, these datalogs look fantastic! my MS2 is having boost control and some other options added to it right now, switching from B+G to extra code at the same time obviously..
with a basic EBC (profec B spec II) and MBC i had the same annoying issue of spooling to 22-23 psi, falling off to 18-19 around peak torque, and slowly climbing back to 22-23 by 7k. this is with an external wastegate. i even get the same basic curve when running wastegate boost, but it is less pronounced at lower boost (1 bar spring).
with a basic EBC (profec B spec II) and MBC i had the same annoying issue of spooling to 22-23 psi, falling off to 18-19 around peak torque, and slowly climbing back to 22-23 by 7k. this is with an external wastegate. i even get the same basic curve when running wastegate boost, but it is less pronounced at lower boost (1 bar spring).
#80
![Default](https://www.miataturbo.net/images/icons/icon1.gif)
finally got my valve working, hooking up the vac hoses tomorrow and giving this a shot ![](https://www.miataturbo.net/images/smilies/smile.gif)
what are you all using for a frequency setting on the DIY valve? their website says 19.5-40hz which technically gives me three options (19.5, 26, 39). The valve seems to be quieter with higher frequencies, not that that really matters.
![](https://www.miataturbo.net/images/smilies/smile.gif)
what are you all using for a frequency setting on the DIY valve? their website says 19.5-40hz which technically gives me three options (19.5, 26, 39). The valve seems to be quieter with higher frequencies, not that that really matters.