Product Finder
Click Here To Subscribe

What on earth is PID control, and why is it in my decoder?!

Posted by on Jan 30, 2015 in Tips Decoders and Installations, Tony's Tips |

Detlef’s Explanation of PID’s

It would appear a brief primer on PID control is in order.  PID refers to the control mechanisms used in a control loop.  A control loop is a system that will automatically adjust a control variable to a set point.  Think cruise control on your car.  The speed is the process variable (PV), the speed setting is the set point (SP) and the gas pedal is the control variable (CV) (Not to be confused with CV’s!).  Go up a hill, the car slows, the cruise control detects a deviation from the set point, and responds by adding gas.  Vice versa when coming down the hill.

PID refers to “Proportional/Integral/Derivative”.  The proportional control refers to the most basic form of automation.  Simply put, the more the deviation from setpoint, the more the control variable is changed.  In our cruise control example, if you set your speed on the flats and you come to a hill, there would be a slight difference between your target speed and the actual speed since the offset is what the controller is looking for to add gas.

Problem: The trouble with just proportional control is there will always be an offset between the set point and the process variable.  Ever notice on some cruise controls that there are a few mph’s (kmh’s) between your set point and the actual speed when going up or down a hill?  “Integral” fixes that by detecting the offset.  It says, “Hey, we have pumped up the gas for a minute now and we still are not at the speed setting… let’s add more gas.”  Integral just looks at the duration that the offset has occurred and corrects that to bring it to zero.  Some more modern cruise controls have that feature.

Finally, derivative (probably the most difficult to understand).  It can be thought of the time constant or the responsiveness of the control loop.  Let’s go back to our cruise control example.  Say you are cruising along and come up to a hill.  How fast does that cruise control respond to the change in grade?  What if the hill comes up fast instead of gently?  If the controller takes a long time to respond, you may drop 10-15 mph (kmh) before the cruise control picks up on it.  Not a very good cruise control.  I had one like this and I ended up doing a lot of ‘anticipating’ of hills and just manually goosed the gas until it figured out there was a hill.  Same when cresting over the top.  If it is not responsive, the gas will be mashed down and the car will just keep accelerating until the controller sees the huge offset the other way.  On the other extreme, a highly responsive derivative control will tend to overshoot.  A slight hill, and the car would just take off…and then cut the gas as it overshoots.  You get the idea.  Derivative refers to the math function where you can calculate the slope of the curve.  And that is in essence what the program is doing.  It is looking at the rate of change of the speed and anticipating the control change needed.  It can be very finicky and difficult to set.

So back to our TSU’s.  Kp is control-speak for the proportional control factor.  This is CV 209.  Think of it as how much an offset between the BEMF and the actual motor speed has an effect on the speed control (our basic cruise control).  Ki is control-speak for integral, and this is controlled by CV 210.   These two factors are the most important in getting BEMF control to work.  CV213 and 214 are of course the derivative controls, and define how fast the decoder will respond to an offset between the set point and the process variable.  CV213 is the sample period for looking for the rate of change.  CV214 is the factor this rate of change has on the PID control loop. I suspect these are probably OK at their default settings, but I would be interested to know if playing with them helps our slow speed performance at all.  CV212 can be thought of as the output: all this PID control gets burped out of CV212.  Just like the master sound volume and then all the submixer volumes, 212 defines how much effect this PID control loop has on the actual motor control.  Zero this out and your decoder motor output is just like its running on an old power pack.  The more you put into 212, the more the motor will respond to the PID control.  255 have the motor 100% controlled by the PID control loop.

A few thoughts on this:

*  Some people are recommending that CV212 be left at 255.  This train of thought comes from trying to get the decoder to ‘lock’ in the speed, regardless of whether the train is going up or down grades or pulling long trains.  I like to have to add more or less throttle, depending on the load, so I have set mine to between 80 and 120 and get a blend of classical motor control and BEMF control.

*  This is also why a lower CV212 setting works better for MU’ing locos.  If your locos are not 100% speed matched across the entire speed range, there will be some times when lokies will push and pull each other.  If CV 212 is set too high, the pulling or pushing will slightly change the BEMF…and the PID control loop will detect this…AND TRY TO CORRECT the offset… and slow or speed up the motor more!  Make sense?  More bucking/dragging of engines.  Not good.

*  Notice the number of times setting procedures state ‘until jerkiness’ or ‘until oscillation’ stops or starts.  What is going on there is that the procedure is trying to tighten up the control loop responsiveness unit we get to the point the controls are just about to overshoot, but then back away from that point.  Back to our cruise control analogy, we want to have that controller nail our speed, but not to the point where it is constantly hunting up and down a half mile per hour (kmh).  That would not only make for an uncomfortable ride, but would be hard on the engine as well.  As such, we will ALWAYS have some offset between the set point and process variable… the question is how close can we get without it hunting.

All this can hurt our brains, but if you are a glutton for more punishment, check out Wikipedia’s page on PID control; it has a pretty good write up on the ideas and includes snazzy charts and graphs:

http://en.wikipedia.org/wiki/PID_controller

Thus ends our control theory class for today.

Regards, Detlef