PID controller
Couldn't load pickup availability
Description
The FB_PID_Controller function block implements a complete PID controller with anti-windup protection and control output limiting. The code is clearly structured and ready for use in the Siemens TIA Portal – ideal for precise control applications in industry, laboratories, or training.
Note: All modules are designed exclusively as a learning and optimization basis and are not approved for live operation. System modules, in particular, must be finally tested and commissioned by qualified personnel before productive use.
How it works
Calculation of the control value
Once RegelFreigabe
is active:
- Error = Setpoint – Actual value
- Integral += Error × Cycle Time
- Differential = (Error – ErrorOld) / Cycle Time
-
StellwertRaw
= Kp × Error + Ki × Integral + Kd × Differential
Limit to OutputMax
If StellwertRaw > AusgangMax
:
-
Stellwert
= OutputMax - Integral -= last integral step (anti-windup)
-
StatusText
= "Limited to Max"
Limit to OutputMin
If StellwertRaw < AusgangMin
:
-
Stellwert
= OutputMin - Integral += last integral step (anti-windup)
-
StatusText
= "Limited to Min"
Normal operation
If StellwertRaw
is within the allowed range:
-
Stellwert
= Control valueRaw -
StatusText
= “Regulation active”
Save error
At the end of each cycle: FehlerAlt
= current error.
Control inactive
If RegelFreigabe
is not set:
-
Stellwert
= 0 -
StatusText
= "Regulation inactive"
Technical details
- Inputs/Parameters: Setpoint, Actual Value, Kp, Ki, Kd, Cycle Time, OutputMin, OutputMax, Control Enable
- Internal variables: Error, ErrorOld, Integral, Differential, ControlValueRaw, StatusText
- Special features: Anti-windup via integral correction; limiting via IF/ELSIF
Possible applications
- Temperature, pressure, flow or level controls
- Speed and position controls
- Didactic examples in laboratory and training
compatibility
- Siemens S7‑1200 & S7‑1500
- TIA Portal from V13
- Recommended: TIA Portal V16+ for HMI & PLCSIM
Scope of delivery
You will receive a fully commented .scl
file with:
- Declaration of all inputs and outputs
- Internal PID control algorithm with anti-windup
The download link is available immediately after purchase.
Support
I would be happy to help you fine-tune your control parameters, integrate them into HMI layouts, or add additional functions such as auto-tuning or alarm messages.
Contact me via shop message or email.