Introduction
A PID function block helps control machines by adjusting outputs to keep things like temperature or speed steady and close to a target.
PID( IN: REAL; // Process variable (measured value) SP: REAL; // Set point (desired value) Kp: REAL; // Proportional gain Ki: REAL; // Integral gain Kd: REAL; // Derivative gain OUT: REAL; // Control output RESET: BOOL; // Reset integral term TIME: TIME; // Sample time );
TempPID( IN := Temperature, SP := 100.0, Kp := 2.0, Ki := 0.5, Kd := 1.0, OUT => HeaterPower, RESET := FALSE, TIME := T#1s );
MotorPID( IN := MotorSpeed, SP := 1500.0, Kp := 1.5, Ki := 0.3, Kd := 0.2, OUT => MotorVoltage, RESET := ResetSignal, TIME := T#100ms );
PROGRAM PID_Control VAR Temperature : REAL := 90.0; SetPoint : REAL := 100.0; HeaterPower : REAL := 0.0; ResetPID : BOOL := FALSE; SampleTime : TIME := T#1s; Kp : REAL := 2.0; Ki : REAL := 0.5; Kd : REAL := 1.0; PID_FB : PID; END_VAR // Call PID function block PID_FB( IN := Temperature, SP := SetPoint, Kp := Kp, Ki := Ki, Kd := Kd, OUT => HeaterPower, RESET := ResetPID, TIME := SampleTime ); // Simulate temperature increase Temperature := Temperature + HeaterPower * 0.1; // Output heater power END_PROGRAM
PID function block in process control?pid1 in a PLC program?name : Type;.pid1.Kp := 2.0; pid1.Ki := 0.5; pid1.Kd := 0.1; pid1.SetPoint := 100; pid1.ProcessVariable := 90; pid1(); Output := pid1.ControlOutput;
Output after this code runs once?pid1.Kp := 1.5; pid1.Ki := 0.3; pid1.Kd := 0.05; pid1.SetPoint := 50; pid1.ProcessVariable := 55; Output := pid1.ControlOutput; pid1();
ControlOutput to update output.Output is assigned before pid1() is called, so output is stale or invalid.pid1() after reading output -> Option DPass the test and this pattern moves unknown