I'm thinking of writing my own PID instruction for an AB PLC, because I'm constantly annoyed by how much I have to "help" the inbuilt PID instruction work the way I want. I know a few others have rolled their own PID instructions (and I'm sure Peter Natchwey could write one in his sleep) and am looking for (a) some general tips and things to watch out for from those who have done it before, and (b) some specific advice on calculating the derivative component.
Proportional gain is easy:
Integral gain is also fairly straightforward. Assuming I make my units minutes/repeat, I perform the following calculation every loop update cycle:
...and add that to the P component.
The derivative I'm less certain of. For the purposes of this exercise, let's assume I'm using the derivative of the PV, not the error. My thinking is that every loop update cycle I perform the following calculations:
...which gives me a rate of change in PV Units per second, and then:
...which is then added to the P and I components.
Is it really as simple as that?
In this example, what are the units of my derivative gain? Seconds?
I appreciate any insights and assistance with the math - my career path did not include any university courses, just an electrical apprenticeship and a lot of learning-by-doing. So when it comes to the theoretical math behind the concept, I have a lot of gaps in my knowledge
Proportional gain is easy:
Code:
P = Error * Kp
Code:
I = Error * Loop Update Time in ms / 60000
The derivative I'm less certain of. For the purposes of this exercise, let's assume I'm using the derivative of the PV, not the error. My thinking is that every loop update cycle I perform the following calculations:
Code:
Rate of Change = (PV this scan - PV last scan) / Loop Update Time in s
Code:
D = Kd * Rate of Change
Is it really as simple as that?
In this example, what are the units of my derivative gain? Seconds?
I appreciate any insights and assistance with the math - my career path did not include any university courses, just an electrical apprenticeship and a lot of learning-by-doing. So when it comes to the theoretical math behind the concept, I have a lot of gaps in my knowledge