# Variable Cam Control Tuning: Step 3 PID Tuning

## Step 3 PID Tuning

### 32.34

00:00 | - The next step of our process is arguably the most important which is our PID algorithm tuning. |

00:06 | Essentially the better we can get our PID control, the more accurately the cams are going to be able to track the target so it's really essential to put in some time here and make sure that we've got really good control. |

00:19 | Now we do have the benefit here of starting from a base map that Haltech have provided and this is quite often the case with engines that are supported by the manufacturer with cam control however it's always a good idea to still test the settings and see if first of all we're getting good control and secondly if we can get some benefit here. |

00:41 | Let's just dive into our software and we'll have a quick familiarisation with what we're dealing with here. |

00:47 | So in our cam control menu structure over here on the left hand side under our ECU navigator, we can see that we've got a few settings we're going to need to deal with. |

00:57 | First of all, click her on our intake 1 base duty cycle table and this is a 2D table here relative to our engine coolant temperature which really is inferring our oil temperature which is the important part as far as the cam control system is concerned. |

01:14 | So we can see here we've got our base values, when the engine is cold down at 37% duty cycle, stepping up to 40% duty cycle. |

01:22 | We will be testing here from a hot engine temperature. |

01:26 | Of course once we've done that and we've established what works at a hot running temperature, you can always come back and refine these with the colder temperature settings as well, making sure that you've got good control. |

01:39 | Moving down we've got the same settings for our intake 2, intake cam 2 base duty cycle. |

01:45 | Then we've got our proportional, our integral and our derivative gains so we can see here, our base values from our base map, gives us an indication at least of the magnitude of values we're going to need in the Haltech ESP software so at the moment we've got values across the board here of about 650, for our integral gain here 60 and for our derivative gain, we've also got 50-60. |

02:10 | Essentially we've got exactly the same values repeated there in our exhaust cam PID setup so we're going to go through that process. |

02:20 | Just one thing I will bring your attention to here is down the bottom here we have the parameter here called target scale, we'll click on that. |

02:29 | It's not particularly intuitive as to what this does but essentially what it does is allows us to set the cam control relative to a parameter. |

02:41 | In this case we've got coolant temperature selected there and we can see we've got 2D table with coolant temperature values of 30, 40 and then 41°. |

02:49 | Essentially how this works is it's just a multiplier for the numbers in our cam target table and what I'm using it for here is essentially to disable cam control below 40° engine coolant temperature. |

03:02 | Essentially when the engine is cold and a lot of ECUs will do this in a variety of different ways but this is the workaround we have here. |

03:10 | So this will mean that basically we take the numbers in our cam control target table and we multiply them by this scaler. |

03:18 | Obviously at 30 and 40°, value of 0 there, we're going to get no cam target change. |

03:23 | 41°, 100% in our scaler so we're going to be targeting our full cam target table value. |

03:31 | So just wanted to mention that there before we get into our PID tuning. |

03:34 | What we'll do now is we'll get our engine up and running and while I'm doing this, we'll just power it up for the moment and what we'll see here is the cam control target angle values saying here, we'll just expand this so we can actually see it, saying uncalibrated. |

03:53 | So this is what we're going to see before we actually start the engine and while I start the engine I just want you to just watch these 2 boxes and this is the way Haltech calibrates the offset for the cam targets or the cam angle I should say that's being measured. |

04:08 | So there's no work for the actual tuner to do here so let's just start the engine and watch what happens. |

04:17 | So what we see is initially after startup the 2 boxes there go from uncalibrated to calibrating and then finally they read 0 so basically as the engine starts up and the engine synchronises, the ECU basically establishes what the base position for our cam is and sets that to 0. |

04:37 | Now I actually have found that this can potentially be problematic in the Haltech software because again we've got no control over this and what we will find is that if we start the engine from completely cold, we'll go through that calibration process, we'll set the cam target or cam position to zero and then as we allow the engine to warm up we'll typically find that once we're up to full operating temperature, we will see the base number sitting there at maybe 3-4° so there's a bit of variation as the engine heats up. |

05:08 | Now we naturally will see some of this anyway but the important thing to consider here is that if we are still targeting 0° and the minimum value that our cam position can actually reach is maybe 2-3° we run the risk of integral windup so as we go through this we'll just talk a little bit further about this and how we can deal with it. |

05:29 | Anyway we're up and running now and our 2 cam targets are sitting at 0 so pretty much doing what we'd expect. |

05:36 | What we're going to do is now look at our first step which is calibrating our base duty cycle table. |

05:44 | Before we can do this, the first step is to go through our PID gains and set these to 0 so let's head to our proportional gain first. |

05:52 | And all I'm going to do is 0 these in the running position in terms of coolant temperature we've got and the reason for this is that obviously this is the area the engine's operating in at the moment which is what we're going to be tuning but it'll also give us these values to the left just as a reminder of what the base values from Haltech were so let's set those to 0 for our proportional, the same for our integral and then finally our derivative gain so this will mean that we've got no closed loop control which is important for this step of the process. |

06:25 | So what I'm going to do is just bring our RPM up, we want to do this up at maybe 2000, 2500 RPM so we've got good oil pressure so I'm just using the throttle at the moment, we're not actually running the car on the dyno just to do that and while I'm doing that we'll just also get the fan up and running so we don't have any overheating problems. |

06:44 | Now in order to actually make the cam control do anything, we do need to target at least some cam angle so we'll just enter a value of 10° in our cam target. |

06:56 | So we can see setting the target angle there to 10°, we can see that our cam intake bank 1 and bank 2 output have jumped to the values of the base table and while I'm talking here we can see our green trace here in our time graph which is our cam intake 2 angle has slowly incremented up there and it's currently sitting at its maximum value of 49° give or take. |

07:20 | Given that we've now got about a 50° variation between bank 1 and bank 2, our engine understandably isn't sounding that healthy, it's not running particularly nicely but there's absolutely no chance of any damage here so I'm not concerned about this, we're sitting at 2500 RPM, I'm barely touching the throttle, there's no load on the engine. |

07:39 | Worth mentioning and I'll deal with this in a bit more detail shortly but at the moment we are using closed loop fuel trim so our closed loop wideband air/fuel ratio control has kicked in and we've got our short term fuel trim there picking up any variation between our target air/fuel ratio and our measured and of course when we've got such a bank to bank variation it's going to be struggling to do a really good job there. |

08:00 | Anyway let's go through this process, we'll jump back to our intake base duty cycle bank 1 and what we want to do here, that is the white line on our time graph, we're just going to increment the values there until we see our white line start to move so we'll go from 39 to 40 and 41, 42, we're expecting that probably somewhere around about, oh in this case 43% we see the line starts to advance there so I've come back down to 42 and we can see that 42 we're starting to drop, 43 we're advancing, come back down to 42, we're retarding again so basically 43% is where we're first starting to advance, looking at what actually holds us pretty consistent, 42%'s probably pretty close to the money there, when we go to 43 we do see that we do quite sharply start advancing the cam so we'll set our values there for our intake cam bank 1 at 42. |

08:56 | Let's go across to our intake base 2 duty cycle and we will highlight the values there, bring ourselves back up again to 2500 RPM so we're at a pretty consistent RPM for both of our tests. |

09:11 | So we can see at the moment, 39% in our base table is probably actually pretty close to the money here, let's just reduce that a little bit and we'll go down to 38, we can see that we drop away quite sharply there. |

09:22 | So we'll go from 38 to 39 then up to 40. |

09:27 | So 40% duty cycle that's where we first really start to see the intake cam on bank 2 advance, go back down to 39% duty cycle we see that it does retard back so we're really sitting around that 39.40% mark there. |

09:44 | We will leave that value at 40%, looks like that's about where we want to be so that's set our base duty cycle. |

09:54 | Remembering again, it's a 2D table so we can come back and do this at colder temperatures but the process is exactly what we've just looked at. |

10:03 | So at this point we've got our base duty now we can move into our proportional, integral and derivative gains. |

10:09 | So what we're going to do in order to do this is actually get ourselves up and running on the dyno and we want somewhere around about maybe 2500 RPM, somewhere where we do have a reasonable amount of oil pressure so let's just get ourselves running at that point now. |

10:25 | Alright so in our instance we're up to about 2800 RPM. |

10:28 | It's not super critical, as long as we're definitely not sitting in the idle range where we can expect poor oil pressure. |

10:35 | So what we want to do now is come first of all into our proportional gain so we know that our numbers here probably are going to be around 650. |

10:43 | Now again the 2 ways we can test this, we can leave the base values in there and just test our PID control, see how good our control is and maybe start to refine it. |

10:53 | Here we'll just show you the process of starting from scratch which really is what we looked at inside the body of the course so what we'll do is we'll start with a value of 100 for our proportional gain, we'll leave our derivative and our integral at 0 and while I've been talking we can see in our time graph the 2 banks are starting to converge down on our target there of 10°. |

11:17 | Let's go across to our target and what we want to do when we are doing this PID tuning is we want to do a step test and we want to make a significant change in our target so we can assess how well the system will control. |

11:33 | But we also want to be mindful if we step for example between 0° and 30°, that's OK because the cam control system can overshoot mechanically, we know we've got almost 50° of variation there so it can overshoot which is important, we want to be able to see if there is an overshoot there or oscillation. |

11:55 | But if we then retard the cam from 30° back down to 0, that's essentially on the mechanical stop so we don't get the ability to see that overshoot so let's just step from 10° up to 30 and see what we've got, so we see our red line increment straight away, we've got quite a variation bank to bank and we can see that they don't really settle on our target too nicely so not particularly good control there. |

12:21 | We'll go from 30 back down to 10°, see what we've got there, again really lethargic control there and nowhere near our target. |

12:31 | Let's go back to our proportional gain now and we'll simply double that value. |

12:37 | And we'll come back to our target angle and we're going to step from 10 up to 30°. |

12:44 | So we can see, still pretty lethargic control but better nonetheless. |

12:50 | We can see that we've still got a variation bank to bank there, our green bank 2 is actually sitting pretty close to our target, our bank 1 though a little bit off. |

13:01 | Given we've got that variation, we've obviously gone through the process there of setting our base duty cycle and the proportional, integral and derivative gain works on that base duty cycle. |

13:10 | We can just test and see if we can get a bit of an improvement there so let's come back to our intake base 1 duty cycle here and let's try increasing the base duty cycle from 42% there to let's say 43% so we know that increasing the duty cycle has the effect of advancing the cam so we can see that that's actually brought the 2 much closer together, we can try another 0.5% change there and we can see that the 2, pretty close there so I'm going to leave that there and we'll continue with our PID control but if we've got a bank to bank variation sometimes that can be beneficial. |

13:46 | Just to go back and try fine tuning your base duty cycle, remember when we went through that base duty cycle, it's not particularly specific, as soon as the cam starts moving, we see it start to take off so there's a range there of 1-2% where we can set that base duty cycle and it's basically going to give us reasonably good control. |

14:06 | Let's head back to our proportional gain and we'll again try doubling our value from 200 up to 400 and you can see as soon as I do that we see our measured cam position does track closer to our target, still not on it but a lot closer, let's come back up to our target angle and we'll step from 30° back down to 10. |

14:29 | Looking at both banks there, track much nicer than they were before. |

14:32 | Still got relatively lethargic control though, little bit slow to reach the target, slight error still remaining, we'll step back from 10-30° and also worth noting here is you can see that when we advance the came, the control is quite a lot faster than when we retard it and that's not particularly unusual to see. |

14:52 | We're getting good improvement there, still no overshoot or oscillation so we'll go a little bit further with our proportional gain so again we'll make our next change by doubling and we'll go back and make our step change again so let's see what our response is like, so we'll step down to 10°, OK so we see that there is now a little bit of variation bank to bank, not too bad, actually very slight amount of overshoot but again not too bad. |

15:19 | We'll step from 10 up to 30 and see what we've got. |

15:22 | Again we see we've got that slight overshoot, more prominent there on cam 2. |

15:27 | That advance there, it's probably about as good as we'd expect and it is worth mentioning here that that time graph in the ESP software does seem to work at a relatively low refresh rate, maybe only as low as 4 Hz or 5 Hz so when we're trying to do something like this where we want to really track the response quickly, this does make it a little difficult, you can always export a log of your data at a high frequency and analyse that but for our purposes, it's going to be sufficient. |

15:56 | So at this point we've got a little bit of overshoot, let's just see what happens if we go a little bit further, so if we go and double this again we're almost certainly going to get into the situation where we've got oscillations. |

16:07 | So let's just prove that, we'll go back and step back down to our 10° target. |

16:13 | And we see we've completely lost control there particularly on bank 2. |

16:19 | Important to mention here that sometimes our PID tuning will be a compromise because we don't have individual control for the PID algorithm on bank 1 and bank 2. |

16:29 | So we'll go back here, our last setting was 800, we had a slight overshoot so we're probably pretty close to the mark there, let's just try a value of 1000 though and we'll see what that gives us. |

16:41 | We've still got a bit of overshoot, oscillation I should say going on there, particularly with bank 2 so what we might need to do is just change our target and see if we get control, we haven't, so probably we're just going to go back to where we were with our value of 800 which did seem to give us reasonable control there, we'll get back to a point where the bank 2 is controlling before we go any further. |

17:08 | Alright so 800, we did have that slight overshoot and generally what I'll try and do here, I'll keep that overshoot and see if we can fix it with a little bit of derivative gain so we've got our proportional set at 800, probably going to be pretty close to the mark there, let's start by adding 20 to our derivative gain and I'm basing this on the fact that our base map had values of 50 so again just guides us on the magnitude but doesn't really matter, we're going to be doing the same doubling our gains and seeing the result so at the moment we're sitting within our cam target at 30°, let's go back to 10° with our step change and see what we've got. |

17:47 | So pretty good there, not a lot of overshoot to speak of, we'll go back to 30 which is where we did see that overshoot and that actually looks like it's pretty well taken care of it. |

17:59 | We'll go back down to 10°, we've still got a very small variation bank to bank in our tracking but it's looking pretty sharp from that perspective so let's try a little bit more derivative gain. |

18:10 | We need to be mindful of our derivative gains because if we add too much it's going to actually slow the response but we'll double that, we'll go to 40 and just see the effect, come back to our angle, step change again, back down to 10. |

18:22 | Pretty good control there, still got the error remaining but that's what our integral will tidy up, we'll go to 30°. |

18:31 | Now we've got no overshoot at all so that's looking pretty good. |

18:34 | No real need to go any further with our derivative in this case, we've got no overshoot to speak of, if I add more derivative, almost certainly we're just going to end up making our control a little bit more lethargic. |

18:46 | Let's add some proportional gain in here and see if we can get rid of that remaining error so again we've got base values here that were 60%, sorry 60 it's a raw number. |

18:56 | So that gives us a bit of a guide so let's start again by adding a value of 20 and we'll come back to our target and make our step change. |

19:05 | Come back down to 10°. |

19:09 | Still got some error there, if we look at our actual raw values here, sitting 8.5, 8.8° so we've got an error of over a degree which is a little further away than what I'd like. |

19:21 | Let's just step back up to 30° and see how that works. |

19:26 | Bit better when we step up but we're still about a degree of error so let's try increasing our integral gain there, so we'll step up from 20 to 40, come back to our target table, we'll step back down to 10°. |

19:42 | Right nice crisp response there and we can see that our error now just a little bit under a degree, about 0.7, maybe 0.8 of a degree so closer, still not quite right, let's step up to 30° just to confirm our response there. |

19:57 | And we can see actually pretty close there, within 0.5° when we step up to 30. |

20:02 | Let's just go a little further with our integral gain though. |

20:04 | If we go too far with the integral gain, we're going to get that same situation where we have too much proportional gain, we'll get an oscillation so let's try going to a value of 80, come back to our test angle, we can see we're sitting really nicely on our target there at 30°. |

20:18 | We'll step back down to 10. |

20:24 | And we're within about 0.5° there so I'm pretty happy with that. |

20:28 | We'll step up to 30° and again pretty sharp control so probably no more gains to be had there. |

20:38 | This can be a bit of an iterative process, particularly between the proportional and derivative gains because of course the proportional gain, the more we use the faster the response but the more likely we are to end up with overshoot so we can use the derivative gain to help break that or dampen that effect so can be a little bit of tooing and froing between those 2 but at this point with the gains that we've just programmed in, I'm pretty comfortable with the amount of control that we've got there, everything's working really nicely. |

21:06 | Before we do move on and cover the exhaust tuning, I just want to briefly cover the closed loop fuel control. |

21:13 | I've already mentioned this but I'll just go a little bit more into detail. |

21:16 | So of course as we change our cam position we are going to be affecting the volumetric efficiency of the engine and we want a way of quickly dealing with this wherever possible so that we don't need to keep switching backwards and forwards between our fuel table, or VE table in this case and our cam target tables. |

21:33 | So we're using our closed loop control and we can access this by coming up to our functions and if we scroll down through our functions here we have o2 control which I'll click on and in this case we've got a single wideband here, so this is in the post turbo downpipe and we've got the ability to set our maximum and minimum trim so basically how much control that the system has. |

22:01 | In this case we've got plus or minus 20%. |

22:04 | That should be sufficient, more than sufficient for a tuned engine but in some cases, particularly while we are doing our cam control tuning, can be beneficial to actually increase that somewhat so let's just for the sake of our purposes, set this to a maximum of plus or minus 30%. |

22:22 | For our closed loop control we also need to make sure that it's going to function when we want it to so here we've got some lock outs so in this case we've got the ability to lock it out below 10°C engine coolant temperature, below 750 RPM or above 7500 and it also won't function if our rate of change of throttle is greater than 25%. |

22:46 | We can also enable a maximum throttle position or manifold pressure but in our case I want this active all the time so you may want to come and change these parameters once the engine is tuned but this is really powerful to help us with our closed loop cam control tuning. |

23:03 | Alright so we've dealt with our intake, we're going to essentially go through the exact same process with our exhaust starting with our base duty cycle. |

23:12 | Now I have set up a separate tuning page here for our cam PID for the exhaust, it's a rinse and repeat of what we've already seen here with obviously the exhaust parameters. |

23:23 | We'll move on now with our exhaust cam PID tuning and it's a rinse and repeat of what we've already looked at. |

23:30 | We'll start in our software here by setting our proportional, integral and our derivative gains to 0 in the current operating temperature area. |

23:38 | Again we've got the existing values to the left of those so we can see what the base or default values were. |

23:45 | We're going to start with our base duty cycle so in order to tune that what we're going to have to do is just set some target values in here so we'll set those values in the range that I'm going to operate in to -10° and we'll just bring the RPM up here using the throttle pedal. |

24:01 | Again the cams straight away, blue line in this case, bank 1, has gone to maximum retard. |

24:10 | So not a problem there, we'll go to our exhaust bank 1 base duty cycle. |

24:15 | And we see we've got a value of 50% in there, let's actually just start by setting that table to 0 and we see that our exhaust cam straight away goes to maximum advance, the rest position. |

24:28 | So what we'll do is we'll just step this table here in 1% increments until we start to see that movement occur just like we did on the intake. |

24:36 | Again I'm not really expecting anything until about maybe 40-50% so let's see where we first start seeing that cam begin to retard. |

24:47 | Come up to 47% now we just start to see that movement, so 46% holding us reasonably steady so we'll leave that at 46% and we'll come across to bank 2 and repeat that process. |

25:02 | Currently that's sitting at 50% and we've got no movement so we'll just move from there and see where we first start to see that green line move which is about 53%. |

25:11 | So come back, 52 we're actually still retarding there so go back to 51 is about where we see it hold steady, actually about 50%. |

25:22 | So 50% we are advancing again so we'll set the value there for our base duty on bank 2 to 51%, it may need a little bit of tweaking as we go but that'll be a pretty good starting point. |

25:37 | Alright let's move on and deal with the PID control tuning for our exhaust cam and essentially this is just going to be a rinse and repeat of what we've already done so let's get started. |

25:47 | We'll begin by heading across to our proportional gain and we'll set that to 0 followed of course by our integral gain and our derivative gain. |

25:56 | Again I'm only adjusting the values in the temperature zones we're working in and we'll just leave those other values there as a bit of a guide to what the base numbers were. |

26:06 | Alright so we're now going to set our base duty cycle and to do this again we're going to need to set our cam angle to something non 0, in this case -10° is enough and we're just going to bring our RPM up again around that 2500 to 3000 RPM vicinity and what we're going to do is we'll start with our exhaust base 1 duty cycle table and we're going to just advance this or increase this up until we start to see the cam actually move. |

26:37 | Again probably expecting this to happen somewhere close to 50% so we'll speed things up a little bit here an just find the point where we first start to see movement, OK 52% we saw the cam swing pretty aggressively so we'll just come back to 50. |

26:52 | Looks like this one really is happening pretty close to 50%, maybe 51%. |

27:00 | Maybe split the difference and we'll call this 50.5 for the time being. |

27:04 | Alright so let's do the same on our bank 2 and again we're probably expecting that will be similar somewhere around about 50% so let's just increase our duty cycle reasonably quickly up to that point. |

27:18 | Coming up through 47, 48, 49 and again 50% we actually do see that move, come back down. |

27:25 | 49%, we are advancing again. |

27:32 | And 50% so both of these really close to the same number and both really close to 50% so we'll leave those for the time being. |

27:42 | Let's move on and we'll start our proportional, integral and derivative gain tuning so let's get ourselves up and running on the dyno at 2800 odd RPM so we can do that now. |

27:54 | Alright we're up and running here so we'll start by heading off to our proportional gain and we know that we did have a number of about 600 in there so we should be there or there abouts but lets start with a value of 100 to start with and we'll do to our target angle table and we'll set our angle from -10 to -30 and watch how our cam position tracks. |

28:16 | Pretty much exactly what we expect, slow response and a lot of error, let's head back to our proportional gain and we'll double our value, going up to 200 and we'll step back to our target angle table and repeat that step process here looking at our results. |

28:34 | Alright so looking at our results, better, much faster response but we've still got a bit of error there. |

28:39 | Let's see if we can get that a little bit tighter, we'll double that again up to 400 and see what our results are, again back to our target table, step back to -10°. |

28:49 | Pretty good results there, reasonably fast to respond, still a bit of error there but to be expected at this stage, let's go to -30 and see what we get there, we see a little bit of an overshoot essentially there from bank 2 in green but we've still got that error prevailing as well. |

29:09 | Let's just try going a little bit further. |

29:11 | I feel like with the results we just saw we're probably at least in the ballpark with 400, let's double that and we'll do to 800 and see what happens so let's step back to -10 and OK so we're seeing an oscillation there exactly what I'd expect so 400, we're probably in the ballpark, let's go a little bit further than our last value, let's try 500 and see what that gives us. |

29:36 | Again we'll come back to our angle target and we'll step back down to -30. |

29:44 | See a pretty sharp response there, no oscillation, let's go back to -10. |

29:51 | Again no real overshoot there, little bit of oscillation potentially from our exhaust cam 2 so let's just try adding a little bit of derivative at that point so again we know that our base values were around about 50 so to speed things up here, let's start with a value of 20 for our derivative. |

30:10 | And we'll go back to our angle, step to -30. |

30:15 | And pretty close there, no real overshoot, no real oscillation so let's try back to -10. |

30:24 | Everything's looking pretty good there so what I'm going to try doing now is adding in a little bit of integral gain and see if we can get ourselves a little bit closer to the mark in terms of getting rid of that remaining error so just come to our integral gain here and again we see the base value was 50, let's again start with a value of 20 there for our integral gain and we'll do our step change again from -10 to -30. |

30:52 | Still got a significant error there, we'll go back to -10. |

30:59 | Lot closer where we're at 10° but still got some error there so let's go back to our integral gain and we'll double that value to 40. |

31:07 | Again our step change here, and again we're looking for hopefully an error of maybe plus or minus about 0.5°, I'd be pretty happy with that, let's go to 30. |

31:19 | Pretty good here, we're at least within a degree anyway, let's step back to -10. |

31:28 | Looking pretty good there, just a slight oscillation around that target of 10°. |

31:33 | Let's just try a little bit more integral gain, I feel like we're pretty close to the mark there so rather than doubling this I'm just going to add another 20 to this. |

31:41 | We don't really need to add a massive amount of integral, we're pretty close to our target there, let's come back to our target table and we'll step back to -30. |

31:53 | And this time right on our target within that 0.5° vicinity, -10. |

31:59 | And again we're pretty well right on our target there. |