MOULDLKnowledge BaseElectrical Knowledge Base3D Model DownloadsMembership
中文版Model Store »
Knowledge Base › Electrical Knowledge Base › How do you use the PID_Compact function block on an S7-1200?
HomeModels
Table of contents

On this page

PLC & Programming (100 articles)

Quick Reference

  • PLC & Programming
  • Electrical & Electronic Basics (monthly)(每月更新中)
  • Electrical Control & Drawings (monthly)(每月更新中)
  • Drives & Actuators (monthly)(每月更新中)
  • Sensors & Detection (monthly)(每月更新中)
  • Industrial Communication & Networks (monthly)(每月更新中)
  • HMI & Host Systems (monthly)(每月更新中)
  • Industrial Robots & Motion Control (monthly)(每月更新中)
  • Mechatronic System Integration (monthly)(每月更新中)
  • Fault Diagnosis & Standards (monthly)(每月更新中)

How do you use the PID_Compact function block on an S7-1200?

PID_Compact is a closed-loop control block built into the S7-1200. It packages the PID arithmetic, output clamping, manual/automatic switching and self-tuning, and works with a technology object. It is easier than writing a PID by hand, but it has many settings and wrong ones are harder to trace than no PID at all. The sections below follow the order in which it is used.

1. What PID_Compact is

PID_Compact brings the fiddly parts of closed-loop control into one instruction: proportional, integral and derivative terms, output limits, manual and automatic switching, and self-tuning. It keeps its state in an instance data block and is bound to a technology object, and you call it with that instance block. Understand this and every later setting has a place to sit.

2. Configuring the technology object

Before use, create a PID object under Technology objects and set the measured-value input, the output channel, the control direction and the sample time. The control direction matters: for heating and pressurising, where a larger output should raise the measured value, the direction is the opposite of cooling or vacuum, and choosing it the wrong way makes the loop diverge. The sample time should match the program call cycle.

3. Modes and how to call it

The block has manual, automatic, pretuning and fine-tuning modes. Run in automatic normally; tune using pretuning and fine-tuning; switch to manual to give the output directly during commissioning. It must be called once per cycle from a fixed place. Putting it inside a conditional branch skips the call and leaves the state wrong.

4. What the parameters mean

Proportional gain, integral time and derivative time set the speed of response and the overshoot: a smaller integral time means stronger integral action and faster removal of steady-state error, but too small causes oscillation; derivative action damps overshoot and speeds up the response. The output limits should match the real range of the actuator, such as 0-100% for a valve or the full analog range.

5. Self-tuning and manual tuning

Pretuning applies a fixed output and watches the response to obtain a rough set of parameters; fine-tuning adjusts them near the setpoint. Tuning needs a process that allows disturbance, so a hazardous or disturbance-sensitive process should be given parameters by hand or tuned with the machine stopped. Once tuning is done, fix the parameters and record them.

6. PID_Compact states and handling at a glance

State or symptomMeaningCommon causeAction
Initial stateNot yet enabledNot enabled or call misplacedCheck enable and cyclic call
PretuningRough parameters being foundTuning interruptedKeep the process steady and tune
Fine-tuningParameters being trimmedLarge disturbance near setpointAllow small disturbance
AutomaticNormal closed-loop controlSuitable parametersWatch curve and overshoot
Manual modeOutput given by handCommissioning or contingencyMatch value before returning to auto
Output saturatedOutput at a limitWrong range or setpointCheck actuator range and setpoint
Alarm: sampling or parameter errorConfiguration problemTechnology object set incorrectlyCheck each configuration item
Alarm: excessive disturbanceTuning failedProcess variation beyond limitsReduce disturbance and retry
No outputBlock not workingNot called or not enabledCheck call location and enable bit

7. Notes

The trick with PID_Compact is to get the order right: create the technology object, call the block, then tune the parameters. Skip any step and the symptoms afterwards point in the wrong direction. When giving parameters by hand, start with a smaller proportional gain and a longer integral time, then tighten gradually.

8. References

The programming and data types of closed-loop control follow GB/T 15969.3, Programmable controllers, Part 3: Programming languages (equivalent to IEC 61131-3). The safety requirements for actuators and process equipment follow GB 5226.1 and the equivalent international standard IEC 60204-1. The exact block parameters and alarm codes are as stated for the CPU version and technology object in use.

9. Points to watch

⚠️ Three common traps:
1. Choosing the control direction backwards, so a larger output moves the measured value further from the setpoint and the loop diverges until the output saturates;
2. Calling the block inside a conditional branch, so it does not execute in some conditions and the loop runs intermittently;
3. Not recording or fixing the tuned parameters, so a fresh download overwrites them with defaults and the control quality is "sometimes good, sometimes bad".

Tune and commission only where the machine allows disturbance, and keep a record of the parameters. Before going to automatic, confirm the actuator direction and range in manual.

Related reading

Related 3D models: Ready to build it? Download free 3D models & CAD drawings at MOULDL »
MOULDL · Electrical Knowledge Base · free self-study reference for electrical & automation engineers, 3D CAD models at MOULDL