Our VIP Package gets you every single course at 80% off the individual price. For a limited time, save an additional $100 with coupon code 100VIP. Learn more

Variable Cam Control Tuning: PID Optimisation

Watch This Course

$149 USD

-OR-
Or 8 weekly payments of only $18.63 Instant access. Easy checkout. No fees. Learn more
Course Access for Life
60 day money back guarantee

PID Optimisation

29.58

00:00 - In this module we're going to take a practical look at how to go about tuning the PID gains for a cam control system.
00:07 As we've already mentioned, this is really the backbone of the cam control system, if we don't have our PID control algorithm dialled in accurately we've really got no hope of the cam control system being able to achieve our targets quickly and accurately.
00:22 For the demonstration today we are going to be using the Ecumaster EMU Black ECU fitted to our Subaru STi and of course every ECU will look a little bit different, the particular parameters and the layout of the software is going to be a little bit different clearly.
00:38 However the reality is that the way the PID control algorithm is implemented and the way we go about tuning and optimising the independent gains is really the same regardless of what system you're doing it on.
00:52 Now I know that the theory that we've already talked about in the body of the course can be a little bit daunting for those who aren't familiar with PID control systems and it can be a little bit difficult to get your head around, even with our real world analogy thrown in there to make things a bit easier to understand.
01:08 Actually seeing this being put into action though in this particular module is going to make things hopefully a lot more clearer and you'll be able to follow this process in your tuning to get the cam control system dialled in quickly.
01:21 Now while we're using the Ecumaster EMU software here for our demonstration I will quickly walk through a couple of the idiosyncracies with different systems as well and we'll start by having a quick look at our Ecumaster software here.
01:37 So I'm on a logging tab at the moment, we've got a log set up on the right hand side and I am looking at the variable valve timing pre configured log.
01:46 I have changed this around a little bit just for clarity for our demonstration while we are running with the Ecumaster ECU on our STi the intake cam control only, so both of the intake cams.
01:58 We're going to only look at tuning one cam so here we have our cam angle 1.
02:04 Actually at the moment we can see that it's sitting at its maximum of 49°.
02:08 Don't worry, you'll understand why that's the case in a moment.
02:11 In purple we have our cam target so that cam target, coming from this table over here.
02:17 So again this is just going to make things a little bit clearer because we won't have cam, intake cam 2 in the mix there but of course the process we're looking at here, you're just going to rinse and repeat this for however many cams you are controlling.
02:31 Down at the bottom, just so we can see exactly what is going on, we've got our cam 1 intake valve control actuator control duty cycle so we can see that occurring there as well.
02:42 Now over on the left hand side we've got a number of parameters, we're going to go through some of these as we look at them but we've got our KP, KI and KD proportional, integral and derivative gains so I've actually got these zeroed out before we start.
02:56 Now why I wanted to look at these though is generally with most ECUs you're going to end up with a base map or base file from the ECU manufacturer for a cam control engine.
03:05 Generally this is probably going to be a pretty good starting point and in most instances the PID gains that they provide in these base maps may be absolutely fine.
03:14 If nothing else though, they're going to at least give you an idea of the sort of range or suitable range that you're likely to need for that particular ECU and the range of numbers that we use for the P I and D gains will vary from one ECU to another so you can't take the gains that we're going to develop here for Ecumaster, apply these to MoTeC or AEM or Link or any other system and expect perfect results.
03:41 They are very dependent on how the particular ECU manufacturer has implemented the PID control algorithm.
03:48 To illustrate these numbers in the Ecumaster software, let's just bring up our cam 2 parameters, obviously cam 2 the other intake cam, we'll double click on that and we can see here that we've got a proportional gain of 25, an integral gain of 0.25 and a derivative of 1.25.
04:07 So just so we can see some perspective from different systems, let's just head across to Haltech's ESP tuning software for a moment.
04:14 We won't get too involved in anything here other than the fact we've got our proportional, our integral and our derivative gains so if we click on proportional you can see they're using values in the range of about 650.
04:27 If we click on the integral, we can see we've got numbers around 60 and then with our derivative we can see numbers around about 50 so clearly if we had applied what we've learned from the Ecumaster software to the Haltech, we're unlikely to get a good result.
04:42 The reason it's important to take note of these base numbers is it's going to allow us to understand what sort of ballpark we need to be in to get good control.
04:52 So again if we look at our proportional gain here, 650, if we come from the Ecumaster tuning platform, let's pop back to that for a moment and you can see we've got our proportional gain sitting at 25.
05:04 If we're trying to apply those numbers, we're just not going to have sufficient proportional element to our PID control to give us good control and it's going to take us a very long time to get there so heading back to our Haltech for a moment, 650 may not be the exact number we need we're going to probably be at least starting using numbers of 100-200 and then doubling from there so it's important to understand, one last example here we'll just pop across to MoTeC's M1 tune software, this is a base map for a Toyota GT86.
05:37 We're looking at the cam control for the inlet camshaft and we've got the proportional, integral and derivative gains here.
05:45 You can see a value of 1500 for the proportional, 2800 for integral and 60 for the derivative.
05:54 So very very different numbers so again just to reinforce, don't think that you can take the numbers from one system and then apply them to another.
06:01 OK let's head back to our Ecumaster software and we'll dive in a little bit deeper.
06:05 At this stage the fundamentals of our cam control setup have already been configured.
06:10 Just a couple of things that I want to touch on here, the first is our cam offset.
06:15 So this is important that we've got this dialled in correctly and this just simply zeros out the cam control system so that we are seeing 0° advance when the cam is not being driven or is in the most retarded positon and we can see if we go across here, at the moment that's exactly what's happening, we've got our duty cycle which is the cam 1 valve duty cycle down here, that's sitting at 20% which is our current minimum value and we can see that our cam position's moving around very slightly, it's never going to be rock solid but we're basically sitting on our target of 0.
06:49 We also want to make sure that our maximum amount of advance and retard, advance or retard has been set and this doesn't have to be rock solid right now, we can adjust this as we go and actually physically measure the maximum amount of travel that the cam does give us.
07:05 Coming down here as well we've got our output frequency which from the default map here is set to 100.
07:11 Generally a little bit lower than I would normally set but we'll see how this controls and we may make some adjustments.
07:18 The key aspects for our demonstration here, we've got our steady state position which is our open loop duty cycle.
07:27 So at the moment I've just got this set to 20%.
07:29 We've also got our KP, KI and KD which we've got set at 0 so at the moment we are in open loop mode which is where we want to start.
07:38 We've also got the ability to adjust our integral limit, our deadband and there's also a start delay which is less relevant.
07:46 The integral limit is there to help us avoid integral windup which we're going to demonstrate and the deadband as we've discussed in the body of the course, basically if we are within 1° of our target, the ECU will accept that as being on our target and won't try and drive the system any further.
08:03 Alright so let's get ourselves started.
08:05 What I'm going to do is we'll just get ourselves up and running here, maybe between 2000 and 3000 RPM just to give us enough oil pressure and we also want to make sure that before we do this test or our PID setup, we want to make sure that our engine is in fact up to operating temperature and more importantly that we've run the car long enough to get good temperature into the oil given of course that the cam control system is oil driven, it's important that the oil is under what we'd consider at least close to our normal operating conditions.
08:35 Let's get ourselves up and running now.
08:37 Alright we've got ourselves operating at about 3000 RPM here and our time graph is operating and what we can see straight away is our purple line here for our cam target, that's increased now to 8° and you can see the reason for this is we're now interpolating between our 60 and 88 kPa columns there in our cam target maps so we're not quite on 14° but we're interpolating between.
09:03 The green line though, our actual measured cam position still sitting at 0, simple reason being that we do have our PID gains zeroed out so the current system is doing nothing to try and drive us towards that target so what we're going to do now is start by setting up our steady state position duty cycle and to do this we're starting at the minimum value I can enter there of 20% and we're just going to use the up arrow key and I'm going to increment that and we're going to be watching that green line to see when that starts moving.
09:34 Generally we're going to be close to 50% duty cycle when we can expect the cam positon to move but there's still a range there of probably within normally plus or minus about 5% duty cycle so let's just step ourselves up here, coming up through 35, 38, 39, 40% duty cycle so we can see that incrementing on that brown line at the bottom, so there's still no movement from our green line and we'll come up through 43, 44, OK so we can see now with 44% duty cycle our cam timing has started to move and I've actually just decremented that back down to 43%.
10:11 So 44% is about the point where we start to see some level of movement.
10:16 So let's just pause this graph and we'll have a quick look at it for a moment.
10:21 So this point here, this is where we started to see that cam actually advance so right before it started moving, we can see that our value there is 44% and that's when it started to increment up, we're now into 45, it's started to move a little bit more sharply and you can see that on the other side of this little saw tooth shape here, this is where I started reducing that back down to 43% and it dropped so let's just get our time graph up and running, our logger up and running again.
10:52 So once we've found that point there, 44% duty cycle, give or take we can basically play with the cam timing the same way that the ECU does so 45%, start to see it rise so if I go a little bit higher you can see it rises much sharper.
11:07 Likewise if we pull the cam position back, the duty cycle back down, the cam position will come back as well.
11:15 So the point of this is we're trying to find that position where we just first start to see movement and for us looks to be about 44-45% duty cycle.
11:25 I'm going to call that 45% so that's the first part of our job done.
11:30 It is worth mentioning that while we go through that process, we've got quite large swings in our cam timing.
11:37 While I've been talking there we can see we've gone through to maximum which, about 50, 51°, it's a good time to come down and fill out the maximum value here.
11:47 This obviously now is different to our other bank of cylinders.
11:51 Chances are the engine's not going to run terribly nicely while that's happening but it's important to mention we're at relatively low RPM, I've got very little load on the engine so I'm not going to be risking damaging the engine, it is worthwhile though just keeping an eye on your air/fuel ratio and making adjustments if necessary.
12:11 Alright we'll move on now and we'll start having a look at our PID gains.
12:16 Before we do that though, I will just mention our minimum and maximum duty cycle.
12:19 So we can see here, our maximum duty cycle set to 90, minimum to 5%.
12:24 Now generally we're not going to need such dramatic swings in our duty cycle to actually get good cam control.
12:32 We want to make sure that these are set within the linear range of the actuator's ability to control as well.
12:40 Generally I'm going to be somewhere around about a minimum of 10-20%, a maximum of 80-90% and that's going to give us reasonably good control and again if we've got everything set up correctly and we're asking for sensible cam targets or changes in cam targets, we're not going to see the swing out to those extremes anyway so we'll set those to 90% and 10% for the time being.
13:05 Right we'll come down to our KP, KI and KD and we already know that the sort of values we're likely to see for our proportional gain, somewhere in the region of maybe 25, 30, in this particular ECU.
13:22 Before we make these changes though what I'm also going to do is just come up to our cam target table and we'll set the values all to 0° in the cells that I'm tuning or the cell that I'm running in as well as the surrounding cells so we've got no interpolation.
13:36 This is important for our step change which is going to come next.
13:40 So let's start by entering a value of 10 for our proportional gain.
13:44 Straight away you can see what's happened there is that our cam timing has dropped down onto our target, we'll just pause that for a moment, we're very close to our target.
13:53 We're targeting 0 of course and our cam positon being measured is 1.5° so pretty close so that's the first step there but what we want to do now is ask for a cam timing change.
14:05 Let's come into our cam target table here.
14:09 And when we're doing this we want to ask for a reasonable step change, probably at least a 20° step change so let's do that now, we'll enter a value of 20°, see what happens.
14:18 Now we can see we got response there, we'll just let everything step across a little bit and we'll pause it for a moment.
14:25 So we can see that our response is pretty good, we've come up but there has been a little bit of a slow rise up in particular as we've got close to our target we can see that the cam position has actually smoothed off a little bit and it's actually overshot as well and it hasn't ended up right on our target, pretty close but that's sort of what we can expect to see when our proportional gain isn't right, we'll get our time logger back up and running here and what we want to do now is make another step change.
14:59 So generally with the intake cam here I'll probably be stepping 20° and I'll be going between 10° and 30° so let's come back down to 10° and the reason I want to go between 10 and 30 is it allows us to see the overshoot above and below our targets.
15:16 For example if we were going between 0° and 20°, when we step from 20 down to 0 the system mechanically can't undershoot or sorry overshoot and go past 0 into the negatives whereas if we go between 30° and 10°, as we step from 30 down to 10 we might see the cam timing dip below 10 before catching up so it gives us a really good opportunity to see exactly what's going on there.
15:41 Alright so our first change made there and we've got a reasonable result there, little bit slow in our response and we're also not quite perfectly on our target.
15:51 However that's just the start so what we'll do now is we'll make our next change, we're going to double our proportional gain element, we're going to go from 10 to 20 and we're going to step from 10° up to 30° again.
16:05 So we'll press enter and we'll assess our result.
16:08 It actually looks pretty good so let's just pause that for a moment and we'll have a look at exactly what's happened.
16:16 Let's start by zooming in so we've got a better idea of what's going on here.
16:18 So we can see the moment that our cam target has stepped here, we can see that the green line there, it does step up towards our target, it's still a little bit slower than I expect we can get.
16:32 We've got this tiny overshoot although in reality it's actually done a pretty standup job.
16:35 We've gone to 31° and then it's settled back right on our target.
16:39 We can also see here what the actual duty cycle's doing so we can see that immediately we step to a maximum value of 70 to get a quick movement initially and then as we get closer to the target we step back towards our steady state position.
16:55 And that's just that proportional gain in action, we can see that the further away we are from our target the larger the result of that proportional gain, the bigger the duty cycle change and as we get closer to our target, our duty cycle comes back.
17:09 Alright let's get our time graph, our logger working again and we can now make a further change.
17:17 I was actually pretty happy with that but let's try a value of 30 here and again we'll make our step change, we'll go from 30 back down to 10° here and let's see what we get.
17:28 OK let's pause that.
17:30 So here we can see we've got pretty quick response but we can see we've now got this undershoot and then we've got a quick oscillation so we've got 1 single oscillation there so we're not too bad there and we can also see the cause of that oscillation is the reversal of our duty cycle there.
17:48 So this is an indication we've probably gone a little bit far with our proportional gain but we can drag some of this back by using a derivative for our braking effect so all's not quite lost just yet.
17:59 What we're going to do though is just get a bit of an example of what's happening when we have gone too far with our proportional gain so let's come down here and we'll double this again to 60 and now we're going to enter our step value of 30°, press enter.
18:16 Right so now we've lost control of the system, you can see if I pause this, we've got this oscillation in both the green line here for our cam, measured cam angle and you can see that the reason for this is that duty cycle is just all over the place.
18:31 So basically 30, we're probably there or there abouts, we've got that slight overshoot or undershoot, not too bad and we'll see if we can correct some of that with our derivative gain.
18:43 So let's get our logger back up and running and we'll come back down and we'll enter our value of 30 so basically as we've discussed in the body of the course, a good place to start is to make significant changes to your proportional gain, there's no danger of damaging anything here but we want to find the working range for our particular system so a good way of doing this is to double our values, that way you'll really quickly creep up on that area where we lose control.
19:08 So back down to 30, we're going to leave it there for the moment and what we're going to do is start, we're going to actually move out of order here, we'll skip our integral component and we're going to come back to that, we'll actually work on our derivative now.
19:22 So let's start by adding a derivative component of 5 here.
19:24 So on its own right now that's not going to show us any result whatsoever.
19:29 Remember that works in the respect of the rate of change of error.
19:35 So what we're going to do is make our step change again, we're going to enter a value of 10 and what we want to do is just analyse what happens when we get that first change, are we going to still get that overshoot and oscillation, so let's press enter and see what we get.
19:52 Alright so that's actually looking pretty good there, let's pause that again.
19:55 We've got pretty quick response given the scaling that I'm using here for this logger.
20:01 Remembering it's important to be realistic, we're not going to get instantaneous response and I am asking for a really large cam change, cam angle change of 20° instantaneously, it's not going to be possible for it to track that perfectly.
20:15 So that's important to understand there so we've got pretty quick response there, we do have a slight overshoot there so we've got a target of 10° and we've actually gone down to 5.5° so 4.5° overshoot, we quickly pull back to that, it's got rid of that continued oscillation that we had initially before we added in that derivative gain so now we can basically go back and forwards between our derivative and our proportional gains to see what will give us the best result.
20:44 I'm going to leave my proportional where it stands at the moment and we're going to try increasing our derivative gain a little bit further, we're going to go up to a value of 10.
20:54 Again we'll step back up from 10° to 30 and we can see there, pretty good result all things being considered, we'll pause it and have another quick look here.
21:04 Can see we've got a very small overshoot there.
21:06 We go up to about 32° peak but not a particularly significant overshoot in the big scheme of things and straight away we're back onto our target.
21:17 So I'm actually pretty happy with this.
21:19 If we continue to add derivative gain, what we're going to actually do is end up adversely affecting our response because the derivative will be acting there to kind of slow down our results and we don't obviously want that.
21:33 If we zoom in on our graph here we can also see the effect of that derivative gain.
21:38 Let's have a look at the shape here of the duty cycle and what we want to look at here is obviously in response to the cam change and the error that is then created, we get a very strong positive value there, 81% duty cycle and then as we get closer, obviously the proportional gain element is reduced because our error is getting smaller but what we can actually see here is that the derivative gain actually comes in.
22:06 If we look at the point that I'm at right now, we are still below our target, we're 28.06° measured cam angle with a target of 30 but if we look at what's happened to the duty cycle it's actually already reversing, it's already trying to slow that cam down because it's sitting at 43% duty cycle, remembering that's actually less than our steady position duty cycle so that's the effect of the derivative gain and it continues to pull back here as I move across there.
22:37 At the point that we hit our target, the cam actuator duty cycle's been pulled all the way down to 40% so that's the derivative gain in action and we can't get that slowing effect without that derivative gain.
22:51 Alright let's get our time graph back up and running here so at this point we've got our proportional and our derivative gains pretty well dialled in and we're getting pretty good control even without any integral element.
23:02 However we're going to have a look at that integral element now, remembering that's going to help remove that remaining error so at the moment we've got that value sitting at 0.
23:11 Remembering from our base values we're probably expecting numbers here of somewhere around about 1-2 so let's start with a value there of 1 and as soon as I do this we can actually see that we see a bit of a movement in our cam timing.
23:25 It's moving around here under steady state conditions but lets do our step change here, we'll go from 30° back down to 10 and we'll see how well everything tracks.
23:38 So let's just pause everything for a moment, have a look at that.
23:42 So we can see here that as our cam position has tracked down, it's overshot our target, it's gone down to a minimum value of 5.5° there so 4.5° error.
23:52 Pretty quickly pulled that back up and it's sat down around 8.5-9° and then our integral element has moved that back onto our target and we're sitting within 1° of our target of 10° essentially.
24:07 Remembering again our deadband there of 1° means that as long as we're within 1° of our target the ECU thinks that we're on target so I won't try and do a better job.
24:16 So let's have a look at what happens here if we increase our integral element from 1 to 2.
24:21 So we'll get our graph, our logger back up and running and again we're going to step from 10° to 30°, we'll press enter and we can see that we've got that very small overshoot and we're straight onto our target, we're oscillating very slightly around the target but we are quite tight on our resolution there so it's making it look a little bit worse than what we would normally be seeing.
24:47 That's probably a pretty good place to be so let's have a look at what happens when we go too far with our integral.
24:54 So we'll enter a value of 10 here and just like our proportional, straight away you can see that that gives us that oscillation so again this just helps us find the working range that we can use for our integral gain.
25:06 So I'm just going to come down here and enter that back to a value of 2 so we've got our proportional, our integral and derivative values that are working and giving us pretty good control.
25:16 Let's just try a few more steps and we'll go back to 10°.
25:21 We'll now make some smaller step changes because as I mentioned, 20° is a larger step charge than we ideally would want to see instantaneously so let's make a 10° change, we'll go from 10° up to 20, we'll have a look at our response, Got a little bit of an overshoot there so there may be the ability to play a little bit further with a combination of our proportional and our derivative gains but certainly the response and the amount of overshoot and how quickly that is resolved, this is going to give us really good control and our cam system will work.
25:53 Let's try a smaller change again, we'll try 25°.
25:57 Nice and quick response there, let's pull that back down to 50°.
26:00 It's important to see how our cam position is responding with both advance and retard commands.
26:06 So this seems to be doing a pretty good job.
26:08 A couple of other things that we want to mention here.
26:10 So our integral gain does work in conjunction with our integral limit so we do want to make sure that our integral limit isn't so tight that it's clamping the integral element's ability to do its job.
26:22 This integral limit is there so help prevent integral windup but if we are targeting sensible values then the integral windup is not going to be a concern.
26:33 So at this point we've got our PID gains dialled in, we've got good control over the cam position, everything's tracking quite nicely, and hopefully this illustrates the process that we do want to go through.
26:48 As you can see with cam control as well, it is actually really easy to make adjustments to those PID gains because we can sit here under steady state conditions and just command an instantaneous change like this and the system will respond so in this way, PID control tuning on a cam control system is significantly easier than the likes of a boost control system on a turbocharged engine.
27:11 For the last part of our demonstration, we'll have a quick look at what occurs when integral windup is happening.
27:18 To do this, we're just going to be targeting a cam angle that we can't achieve so let's come back into our cam target table here and we'll enter a value of 60°.
27:29 So straight away we can see our cam angle target goes up to 60 that's our purple line and we can see that our cam position is sitting at the maximum we can achieve there, it's about 51° maximum.
27:43 We can also see at the moment because of the integral windup our cam duty cycle is sitting at 90% so it's trying hard to drive us towards that unachievable goal because the cam control solenoid is sitting or the cam wheel I should say, is hard against the mechanical stop so now what we're going to do is we're going to target a realistic value that we can get to.
28:06 So we'll change that from 60 down to 30 and what we want to do is have a look at our response so we'll just pause that and we can see that the cam target doesn't change initially and we can also see how slow the response is, how slowly our duty cycle drops back down, we don't get that instantaneous result even though at the moment we're sitting with a target of 30° and we're still at 51° so a big error there and we can see how lethargic this is, how it sort of tracks along at the existing cam target and then slowly sort of drops down towards our new target.
28:45 So just to see what that looks like if we didn't have integral windup occurring, let's do that again but this time what we'll do is we'll target 50° which we know we can get to, nice quick response up to our 50° target, we'll now enter a value of 30 the same that we had before and we'll see how quick our response is.
29:06 So it might seem like a subtle difference but you can see how much quicker we get down onto our target there and if we are targeting realistic values this is the sort of response we should be able to get, nice and crisp, straight onto our target with no latency in that value, latency in that control.
29:25 That's all going to add up to a system that's going to respond quicker and more accurately to our target changes.