AustralIan
Member
I rolled my own PID once, because I needed a PID which was based on conveyor ticks and not seconds.
One hard thing I noticed, was dealing with bouncing off the walls:
Say for example you are running steady at 99%CV.
You increase your error by 0.1, and (assuming no filter, guessing at your derivative gain, and also guessing your loop update rate) your derivative term causes a 10% increase in CV. Now the next scan, your error has not changed, so you decrease your CV by 10%. But... your PID clipped to 100% in the previous scan, so you are now running steadily at 90%CV! A similar effect can be seen by the proportional term, if your PV has any ripple.
For me the solution was to insist on a filter to the PV.
Also, use LREALs if available.
You could start with the source code for OSCAT BASIC FT_PID (or FT_PIDW or FT_PIDWL) instruction, which are written in ST, but maybe that overcomplicates it, as they put I and D in seperate Function Blocks.
Here is some code to get you started.
according to our friends at www.dictionary.com, velocity can also mean more generally 'the rate of speed at which something happens'.
So because the velocity PID calculation calculates firstly the required change in CV, velocity is as good a term to describe it, as rose is for describing what an elevator just did.
One hard thing I noticed, was dealing with bouncing off the walls:
Say for example you are running steady at 99%CV.
You increase your error by 0.1, and (assuming no filter, guessing at your derivative gain, and also guessing your loop update rate) your derivative term causes a 10% increase in CV. Now the next scan, your error has not changed, so you decrease your CV by 10%. But... your PID clipped to 100% in the previous scan, so you are now running steadily at 90%CV! A similar effect can be seen by the proportional term, if your PV has any ripple.
For me the solution was to insist on a filter to the PV.
Also, use LREALs if available.
You could start with the source code for OSCAT BASIC FT_PID (or FT_PIDW or FT_PIDWL) instruction, which are written in ST, but maybe that overcomplicates it, as they put I and D in seperate Function Blocks.
Here is some code to get you started.
Code:
IF NOT Initialized THEN
Initialized := TRUE;
E_nminus2 := E;
E_nminus1 := E;
END_IF
E := SP-PV;
IF Auto THEN
CV := CV + Kp * (E - E_nminus1)
+ Ki * (E)
+ Kd * (E - 2.0 * E_nminus1 + E_nminus2);
END_IF
CV := MIN(100.0, MAX(0,CV));
E_nminus2 := E_nminus1;
E_nminus1 := E;
trolling
according to our friends at www.dictionary.com, velocity can also mean more generally 'the rate of speed at which something happens'.
So because the velocity PID calculation calculates firstly the required change in CV, velocity is as good a term to describe it, as rose is for describing what an elevator just did.
Last edited: