Sign in to follow this  
Followers 0
Xterri

Pseudo PID

5 posts in this topic

Hello, I've got an old PLC which does not come with any PID loop capability. Trying to control a small heater (nothing critical), but in the absence of an PID controller in the CPU I must write a "pseudo", time-controlled PID. Does anyone have a sample code to accomplish this? What I have in mind is a time/percentage controlled feature, where as the temperature gets closer to the set point the heater turns on less time, etc. Thanks.

Share this post


Link to post
Share on other sites
Xterri, How about Sliding Mode Control...... Check this thread out.... Sliding Mode Control Thread

Share this post


Link to post
Share on other sites
that is great I was reading up about this all yesterday and it looks realy goood. I now have a lot of work to do to modify all my 300 plus on/off temp controller. Thanks ... I think

Share this post


Link to post
Share on other sites
I only have the experience of using pid blocks on ge plc,however,i can provide you a pid programme in c language.Maybe it can help you develop a pid block by yourself . Good luck. ==*/ ??#include <string.h> ??#include <stdio.h> ??/*==================================================================================================== ?? PID Function ?? ?? The PID function is used in mainly ?? control applications. PIDCalc performs one iteration of the PID ?? algorithm. ?? ?? While the PID function works, main is just a dummy program showing ?? a typical usage. ??=====================================================================================================*/ ?? ??typedef struct PID { ?? ?? double SetPoint; // Desired value ?? ?? double Proportion; // Proportional Const ?? double Integral; // Integral Const ?? double Derivative; // Derivative Const ?? ?? double LastError; // Error[-1] ?? double PrevError; // Error[-2] ?? double SumError; // Sums of Errors ?? ??} PID; ?? ??/*==================================================================================================== ?? PID calculation ??=====================================================================================================*/ ?? ??double PIDCalc( PID *pp, double NextPoint ) ??{ ?? double dError, ?? Error; ?? ?? Error = pp->SetPoint - NextPoint; //error ?? pp->SumError += Error; // integral ?? dError = pp->LastError - pp->PrevError; // derivative ?? pp->PrevError = pp->LastError; ?? pp->LastError = Error; ?? return (pp->Proportion * Error // proportional term ?? + pp->Integral * pp->SumError // intergral term ?? + pp->Derivative * dError // derivative term ?? ); ??} ?? ??/*==================================================================================================== ?? Initialize PID Structure ??=====================================================================================================*/ ?? ??void PIDInit (PID *pp) ??{ ?? memset ( pp,0,sizeof(PID)); ??} ?? ??/*==================================================================================================== ?? Main Program ??=====================================================================================================*/ ?? ??double sensor (void) // Dummy Sensor Function ??{ ?? return 100.0; ??} ?? ??void actuator(double rDelta) // Dummy Actuator Function ??{} ?? ??void main(void) ??{ ?? PID sPID; // PID Control Structure ?? double rOut; // PID Response (Output) ?? double rIn; // PID Feedback (Input) ?? ?? PIDInit ( &sPID ); // Initialize Structure ?? sPID.Proportion = 0.5; // Set PID Coefficients ?? sPID.Integral = 0.5; ?? sPID.Derivative = 0.0; ?? sPID.SetPoint = 100.0; // Set PID Setpoint ?? ?? for (;;) { // Mock Up of PID Processing ?? ?? rIn = sensor (); // Read Input ?? rOut = PIDCalc ( &sPID,rIn ); // Perform PID Interation ?? actuator ( rOut ); // Effect Needed Changes ?? } ??} ?? ??

Share this post


Link to post
Share on other sites
I would NOT use that PID Stefan. Where did you find it? 1. No time scaling for update or scan time.. The response of this PID is highly scan dependent as the scan rate affects Ki and Kd. 2. It is better to accumulate output instead of error. Why? 3. No output limiting. 4. No integrator windup limiting. 5. Temperature controller PIDs normally have the differentiator and sometimes the proportional terms in the feed back loop. Why? I call these I-PDs when the P and D terms are in the feedback loop. How would this PID handle integrator windup or output saturation? How would it respond to a step change in the setpoint? What happens is the scan time is changed from 1 ms to 2 ms? Where is the PWM? The Sliding Mode Control is On/Off Control. Did you check out the Sliding Mode Control thread listed above. It has a nice spread sheet done by Sleepy Wombat.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0