S7-1200 PID_Compact: Continuously Changing Setpoint Speed Sync

David Krause19 min read
PID ControlSiemensTechnical Reference
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Synchronizing two gearmotors to run at matched speed is a classic follower / leader application. When the leader's speed reference is itself moving (for example because it tracks a process variable, a recipe ramp, a load profile, or a host PLC command), the follower's PID setpoint is no longer a static numeric value. It changes every PLC scan. This reference describes how to configure the SIMATIC S7-1200 PID_Compact block to accept a continuously changing setpoint derived from a master encoder or a master drive reference, and how to wire the slave feedback path so the closed loop regulates the speed error between the two gearmotors rather than chasing a fixed RPM target.

1. Application Overview and Control Objective

The application consists of two mechanically independent gearmotors that must rotate at matched speed. The leader (master) gearmotor carries an absolute or incremental encoder; the follower (slave) gearmotor carries a second encoder. The objective is for the slave to track the master's instantaneous speed closely enough that the position offset (integrated speed error) stays within a defined mechanical tolerance. Because the master speed itself varies with the host process, the setpoint supplied to the slave PID is non-constant and can change on every OB1 cycle.

Two architecturally valid approaches exist for this application. They are functionally different and produce different tuning results, different closed-loop bandwidth, and different commissioning effort.

1.1 Architecture A: Cascade / Mirror Setpoint

The master encoder is scaled to engineering units (RPM, percent, or mm/s) and written to the Setpoint input of the slave PID. The slave encoder is scaled to the same engineering units and written to the Input input. The PID computes Output to drive the slave inverter. The controller is in absolute speed control: it tries to make the slave speed equal to the master speed. The Setpoint tag is being rewritten every cycle by the application.

1.2 Architecture B: Speed-Error Outer Loop

The master speed reference (whether the encoder scaled value, or the analog command sent to the master drive) is also routed to the slave inverter as a feed-forward command. The PID Setpoint is fixed at 0.0. The PID Input is the algebraic difference (master speed - slave speed) from the two encoders. The PID Output is added to (or subtracted from) the master speed reference to produce the final slave drive command. The PID is acting as a synchronizing trim controller; it has a fixed setpoint of zero and the Setpoint tag does not need to change at all.

Architecture B is generally preferred when the goal is synchronization, because the controller is asked only to correct a small error, not to chase the full speed command. The derivative term is much easier to tune, the integral term is naturally bounded, and the response to a sudden setpoint change on the master is unaffected by the PID dynamics. The trade-off is that the slave drive must accept a speed command built from a base reference plus a trim signal, a feature most modern inverters support.

Engineering decision: Use Architecture A when the slave is genuinely required to run at the same absolute speed as the master, and the master's setpoint is already filtered or ramped. Use Architecture B when the master speed command is already a clean reference and the slave is only asked to track it within a small tolerance window.

2. PID_Compact Block Identification and I/O Map

PID_Compact is the standard SIMATIC PID instruction shipped with TIA Portal. The block instance is created in the project tree under Technology > PID Control > PID_Compact, or by dragging PID_Compact from the Instructions task card. For S7-1200 firmware V4.x and later, the block is delivered as FB 1130, version 3.x (the exact block revision depends on the installed TIA Portal version). The instance DB exposes the following tags used in a speed-synchronization application.

Tag Direction Data Type Role in Speed Sync
Setpoint Input Real Master speed (Architecture A) or fixed 0.0 (Architecture B)
Input Input Real Slave encoder scaled to engineering units
Input_PER Input Word Optional raw analog input (0..27648) bound to a slave speed signal
Disturbance Input Real Load torque feedforward (often unused)
ManualEnable Input Bool Latch to enter manual mode
ManualValue Input Real Manual output in percent
SetpointLimit_H Static Real Upper engineering setpoint clamp
SetpointLimit_L Static Real Lower engineering setpoint clamp
InputWarning_H Static Real Process value high warning
InputWarning_L Static Real Process value low warning
Output Output Real Manipulated variable in percent
Output_PER Output Int Analog output (0..27648) for inverter frequency reference
Output_AMWR Output Real Output in physical units (PROFINET drive telegrams)
SetpointDisplay Output Real Active setpoint (HMI)
InputDisplay Output Real Active process value (HMI)
Mode InOut Int 0=Inactive, 1=Pretuning, 2=FineTuning, 3=Automatic, 4=Manual
ErrorBits Output DWord Bit-packed diagnostic flags (see Section 10)
Config.CycleTime Static LReal PID sampling time in seconds (must be a multiple of OB1)
Retain.Cycle Static LReal Sampling time retained across power cycles
Gain Static Real Proportional gain
TI Static LReal Integral action time (reset time) in seconds
TD Static LReal Derivative action time in seconds
DerivativeDelay Static LReal D-term low-pass time constant in seconds

The complete tag list and block identification are documented in the TIA Portal help under PID_Compact V1 / V2 / V3 for S7-1200. Refer to the TIA Portal V21 PID_Compact reference for the exact block revision delivered with a given TIA Portal install. See the official Siemens TIA Portal V21 documentation on PID parameters for the full parameter set, editability rules, and warnings about online parameter changes.

3. Wiring the Master Reference into the Setpoint

For Architecture A, the master encoder channel must be scaled to the same engineering units as the slave encoder channel. The two scaling blocks (NORM_X and SCALE_X in TIA Portal, or user-written FCs) must produce numerically identical full-scale values; otherwise the slave will deliberately run at a different speed than the master. A common commissioning error is to scale the master to RPM and the slave to percent, producing a 1.6x ratio that is not visible at standstill but becomes a permanent offset once the line runs.

Sample Structured Text (ST) that writes a master speed reference into the PID Setpoint tag every cycle:

// Master speed in RPM, already scaled from the master encoder
IF "HSC_Master".Status.Done THEN
    "DB_Master_Speed".RPM := "Scale_Master_Encoder"(
        NORM_X_OUT := "HSC_Master".CountValue
    );
END_IF;

// Feed master RPM into the slave PID setpoint every OB1
"Slave_PID_Compact".Setpoint := "DB_Master_Speed".RPM;

// Feed slave encoder back to the slave PID
IF "HSC_Slave".Status.Done THEN
    "Slave_PID_Compact".Input := "Scale_Slave_Encoder"(
        NORM_X_OUT := "HSC_Slave".CountValue
    );
END_IF;

Two engineering practices keep the Setpoint write clean:

  1. Assign the master scaling function to a fixed-cycle OB (for example OB30) with a known period, and assign the same period to PID_Compact.Config.CycleTime. This guarantees the Setpoint is updated exactly once per PID execution.
  2. Clamp the Setpoint value to SetpointLimit_L and SetpointLimit_H before it reaches the block. PID_Compact clamps internally, but pre-clamping prevents SetpointDisplay from showing transient noise outside the physical range on the HMI.

For an S7-1200 CPU 1214C DC/DC/DC (catalog 6ES7 214-1AG40-0XB0) or CPU 1215C, the onboard high-speed counters HSC1 through HSC6 support 24 V incremental encoders at up to 100 kHz (200 kHz on HSC1-HSC4 for differential signals). Wire each encoder's A, B, and Z (if used for homing) channels to the assigned inputs and configure the counter under Device configuration > Properties > Pulse generators (PTO/PWM) and counters. For analog output to the slave inverter, use an SM 1232 analog output module (e.g., 6ES7 232-4HD32-0XB0) or a signal board SB 1232 (6ES7 232-4HA30-0XB0) to provide a 0-10 V or 4-20 mA reference.

4. Cycle Time and Sampling Constraints

PID_Compact samples its inputs and computes its output at Config.CycleTime, which must be an integer multiple of the calling OB's cycle time. For a default S7-1200 OB1 cycle of 100 ms, set Config.CycleTime = 0.1 s. For a 10 ms cyclic interrupt OB (OB30 configured to 10 ms), set Config.CycleTime = 0.01 s.

Constraint: Config.CycleTime < 0.1 s requires the PID_Compact block to be called from a cyclic interrupt OB, not from OB1. Calling PID_Compact from OB1 with Config.CycleTime = 0.01 will produce a 100 ms effective cycle (the block will simply skip most invocations) and degrade tuning. Verify by reading Retain.Cycle online; it should equal Config.CycleTime.

For a gearmotor speed loop, the rule of thumb is that the PID sampling time should be at least 5x to 10x faster than the dominant mechanical time constant of the drive. A small gearmotor with inertia J, viscous friction B, and torque constant Kt on a current-controlled inverter has a mechanical time constant T_mech = J * R / (Kt * Kf) + J / B. For a typical 200 W gearmotor in the sub-500 W class, this constant is in the 30-200 ms range. A PID_Compact cycle of 10-20 ms is appropriate. For larger gearmotors (kW class), 20-50 ms is sufficient.

Gearmotor Class Mechanical τ Recommended PID_Compact Cycle OB to call from
< 500 W 30-100 ms 10 ms OB30 (10 ms)
500 W - 2 kW 100-300 ms 20 ms OB30 (10 ms or 20 ms)
2 kW - 10 kW 300 ms - 1 s 50 ms OB1 (100 ms) with cycle multiplier 1, or OB30 50 ms
> 10 kW > 1 s 100 ms OB1 (100 ms)

Working example: a 1024 PPR incremental encoder on a 3000 RPM gearmotor with a 10 ms PID cycle produces:

  • Encoder frequency at full speed: f = 3000 / 60 * 1024 = 51,200 Hz
  • Counts per PID cycle: N = 51,200 * 0.01 = 512 counts
  • Minimum measurable speed change per cycle: 1 / 512 = 0.2% of full scale

This resolution is adequate for a percent-level speed control loop. For sub-percent accuracy, increase the PID cycle to 20 ms or upgrade the encoder to 2048 or 4096 PPR.

5. Pretuning, Fine Tuning, and the Continuously Changing Setpoint

The TIA Portal PID tuning wizard supports two automatic modes: pretuning (cold start) and fine tuning (warm start). The tuning algorithm intentionally applies step changes to the Setpoint to identify the process reaction curve. When the Setpoint is being written by application code on every cycle, the wizard cannot inject its own steps, and it will report a tuning fault (ErrorBits bit set, tuning aborted).

Recommended procedure:

  1. Disconnect the Setpoint write from application code. Hold the Setpoint at a representative operating point (typically 50% of full speed).
  2. Run PID_Compact pretuning by writing Mode = 1. The block walks the process through several step changes and populates Gain, TI, and TD with identified values.
  3. Accept the computed parameters.
  4. Switch the Setpoint write back to the master encoder feed. The PID is now operating on a moving setpoint with the gains identified at a single operating point.
  5. For better tracking across the full speed range, run fine tuning (Mode = 2) at two additional operating points (e.g., 25% and 75% of full scale). PID_Compact averages the results into the Gain, TI, and TD tags.

If the application forbids holding the Setpoint stationary, alternative strategies exist:

  • Run fine tuning only. Fine tuning tolerates small ongoing disturbances and adjusts the existing parameters rather than re-identifying the process from scratch.
  • Run pretuning with the master drive stationary, then re-tune empirically in automatic mode by commanding known ramp profiles and observing response.
Siemens guidance: Change PID parameters only when Mode = 0 (Inactive). Writing Gain, TI, or TD while Mode = 3 (Automatic) is technically possible from the instance DB but causes the block to apply the change without re-initializing internal integrators, which produces an output bump. See the official Siemens TIA Portal V21 documentation on PID parameters in the advanced settings.

6. PI vs PID: Why the D-Term is Often Left Disabled

A derivative term computes the rate of change of the error. On a speed synchronization loop, the error itself is the rate of change of position. Differentiating it amplifies the noise already present in the encoder signal. A single bad encoder count from electrical noise produces a derivative spike large enough to saturate the output for one or more PID cycles, which then disturbs the slave drive unnecessarily.

Practical recommendations for a gearmotor sync loop:

  1. Start with TD = 0.0 (D-term disabled) and tune Gain and TI for a critically damped response to a step disturbance.
  2. If the response is too sluggish and a small amount of D-action would help, enable TD with a non-zero DerivativeDelay (typical 1-5 s for a 10 ms cycle, 5-20 s for a 100 ms cycle). DerivativeDelay applies a first-order low-pass to the D-term; larger values reduce derivative kick at the cost of D-term speed.
  3. Cap the output slew rate. PID_Compact supports output scaling (Config.OutputScaling.UpperPointIn, UpperPointOut, LowerPointIn, LowerPointOut) but does not expose an explicit slew-rate limiter. If derivative-induced bumps are observed, slew-rate limit the Output_PER value in a downstream FB before it reaches the analog output module.

7. Output Limits, Anti-Windup, and Bumpless Transfer

When the manipulated variable hits an output limit (the inverter reaches its maximum speed reference) and the error persists, the integral term in a PI controller continues to accumulate. When the error finally reverses, the integrator must unwind before the controller responds. PID_Compact applies anti-windup automatically: it freezes the integrator when Output saturates and resumes accumulation only when Output comes back into the active range. No additional configuration is required for the standard anti-windup behavior.

The default output limits are 0.0% and 100.0% (Config.OutputScaling). For a bipolar drive (forward and reverse), change the lower point to -100.0%. The InputWarning_H and InputWarning_L tags are independent of output limits and can be set narrower to alarm the HMI if the process value approaches a physical limit.

Mode constants for PID_Compact:

Mode Name Behavior
0 Inactive Output held at 0% (or last value if Config.OutputScaling.bRunInMode0 = TRUE)
1 Pretuning Tunes parameters from cold start
2 FineTuning Tunes parameters in warm state
3 Automatic Closed-loop control with Setpoint as target
4 Manual Output controlled by ManualValue; integrator tracks for bumpless transfer back to Mode 3

For an application with a moving setpoint, the block should be placed in Mode = 3 (Automatic) for the duration of normal operation. Mode 4 (Manual) is used during commissioning only. Switching from Mode 4 to Mode 3 is bumpless: PID_Compact copies the current manual value into the integrator so the first automatic computation produces the same Output that the manual mode was producing.

When the application needs to gate the control (for example, interlock the slave drive to a safety chain), do not use Mode 0 unless the slave can coast to a stop safely. Prefer Mode 4 with ManualValue = 0 if a controlled zero hold is required, or use a hardwired enable input to the inverter and keep PID_Compact in Mode 3 with a Setpoint of zero so the integrator does not wind up.

8. Practical Commissioning Sequence

  1. Wire the master encoder to a fast counter input (onboard or signal module). For S7-1200, HSC1-HSC6 are supported depending on the CPU. Confirm HSC configuration in the device configuration under Properties > Pulse generators and counters.
  2. Wire the slave encoder to a second HSC.
  3. Create two scaling FCs: one for the master, one for the slave. Verify that both produce the same engineering unit at the same physical RPM by commanding a known speed and reading both values in a watch table.
  4. Insert a PID_Compact instance, assign it to OB30 (or OB1 if cycle greater or equal 100 ms is acceptable).
  5. Configure SetpointLimit_L and SetpointLimit_H to the physical RPM range of the gearmotor (e.g., -3000 to +3000).
  6. Configure InputWarning_L and InputWarning_H to alarm levels (e.g., plus or minus 5% of full scale).
  7. Set Mode = 4 (Manual). Write ManualValue = 0. Verify the slave drive receives 0% reference.
  8. Step ManualValue to 10%, 25%, 50% and verify the slave follows. Use this to confirm the polarity of Output and the direction of the drive. Reverse the sign of the output scaling if the direction is wrong.
  9. Set Mode = 0 (Inactive). Apply the Setpoint write from application code and verify SetpointDisplay on the HMI matches the master speed reference.
  10. Run pretuning (Mode = 1) at a fixed Setpoint, as described in Section 5.
  11. Return Mode = 3 (Automatic). Verify the slave follows the master through a slow ramp, then through a step change in master speed.
  12. Iterate Gain and TI for desired response: increase Gain until you see 5-10% overshoot on a step, then reduce by 30%. Reduce TI until the response is critically damped.

9. Verification Checklist

Check Method Pass Criterion
Setpoint tracking Apply ramp to master; observe SetpointDisplay SetpointDisplay equals master speed plus or minus 1 LSB
Closed-loop error Command step in master; observe SetpointDisplay - InputDisplay Steady-state error < configured tolerance
Output saturation Force Setpoint to SetpointLimit_H; observe Output Output clamped to 100% (or OutputScaling upper point)
Anti-windup Hold Setpoint at limit for 30 s; release Output returns to active range within 1 s of error reversal
Cycle time Read Retain.Cycle online Equals Config.CycleTime
ErrorBits Monitor ErrorBits in watch table All bits 0, value equals 16#0000_0000
Mode transitions Toggle Mode 4 to 3; observe Output Output does not step (bumpless)
Encoder noise Log InputDisplay at standstill Peak-to-peak < 2x encoder resolution in RPM
Derivative activity Plot Output with TD = 0 vs TD > 0 TD > 0 produces visible noise spike; reduce TD or increase DerivativeDelay

10. PID_Compact Error Bits (ErrorBits)

The ErrorBits tag is a DWord bitmask indicating diagnostic conditions. The exact bit assignment depends on the block version, but the canonical set for PID_Compact V2 / V3 is:

Bit Hex Mask Meaning Remediation
0 16#0000_0001 NoError (informational; 0 if any other error present) —
1 16#0000_0002 ConfigurationInProcess Wait; clears when configuration completes
2 16#0000_0004 ConfigurationError Check SetpointLimit, InputWarning, OutputScaling values
3 16#0000_0008 FbStartCalledTooOften (PID called before cycle elapsed) Verify OB cycle and PID_Compact cycle time alignment
4 16#0000_0010 FbInInactiveMode (writing tags while Mode = 0) Move to Mode = 3 before writing tags
5 16#0000_0020 FbInPretuning (writing tags while Mode = 1) Wait for pretuning to complete
6 16#0000_0040 FbInFineTuning (writing tags while Mode = 2) Wait for fine tuning to complete
7 16#0000_0080 FbInAutomatic (writing tags while Mode = 3) Switch to Mode = 0 before editing parameters
8 16#0000_0100 FbInManual (writing tags while Mode = 4) Switch to Mode = 3 to allow Setpoint updates
9 16#0000_0200 InvalidMode (Mode < 0 or Mode > 4) Clamp Mode to valid range
10 16#0000_0400 SetpointLimitsInverted (SetpointLimit_L greater or equal SetpointLimit_H) Swap limit values
11 16#0000_0800 InputLimitsInverted (InputWarning_L greater or equal InputWarning_H) Swap warning values
12 16#0000_1000 InvalidInputScaling (LowerPointIn greater or equal UpperPointIn) Verify SCALE_X block parameters
13 16#0000_2000 InvalidOutputScaling (LowerPointIn greater or equal UpperPointIn) Verify output scaling parameters
14 16#0000_4000 InvalidSamplingTime (Config.CycleTime < 0.001 s) Increase cycle time to at least 1 ms
15 16#0000_8000 GainOutOfRange (Gain < 0) Verify Gain is positive
16 16#0001_0000 IntegralOutOfRange (TI < 0) Set TI to a positive value or 0.0 to disable I-term
17 16#0002_0000 DerivativeOutOfRange (TD < 0) Set TD to 0.0 to disable D-term
18 16#0004_0000 SamplingTimeTooShort (Config.CycleTime < OB1 cycle) Increase Config.CycleTime or use faster cyclic OB

Bit names are illustrative; verify the exact mapping in the TIA Portal help for your block version. In production, monitor the bitmask and alarm on any non-zero bit.

11. Alternative Hardware Paths for Tighter Synchronization

For very tight synchronization requirements (printing, packaging, or material-handling lines where the integrated position error must stay below a few millimeters), PLC-based PID_Compact is usually not the right tool. The PLC scan period, the HSC update latency, and the analog output update latency together produce a closed-loop bandwidth that is rarely above 20-30 Hz, whereas a digital synchronization card operates at the inverter's current loop rate (typically 1-4 kHz).

11.1 SEW-Eurodrive DRS11B Synchronous Operation Card

SEW-Eurodrive offers the DRS11B Synchronous Operation Card for MOVIDRIVE B and MOVIFIT FC inverters. The card reads the master encoder signal and computes the slave speed command directly in the inverter firmware, with synchronization accuracy and encoder interface parameters defined in the manufacturer's datasheet. Refer to the official SEW DRS11B documentation for the exact accuracy class, encoder interface, parameter set, and wiring diagram.

11.2 ABB Frequency Input as Speed Reference

ABB ACS355, ACS580, and similar general-purpose drives accept a frequency input (typically 0-16000 Hz) as a speed reference. The master encoder can be wired directly to the slave drive's frequency input, bypassing the PLC entirely. The slave drive's own internal speed controller closes the loop on the slave encoder. This eliminates the PLC from the fast path and gives a closed-loop bandwidth limited only by the drive's current loop. It is the simplest solution for applications where the gearmotor pair must track a master reference with reasonable accuracy and the only adjustment needed is a small scale-factor trim.

Selection rule of thumb: tolerance of a few percent of speed, or position offset of a few centimeters at typical line speeds, is workable on the S7-1200 PID_Compact path. Tighter requirements warrant budgeting for a digital synchronization card from the inverter vendor.

12. Frequently Asked Questions

Can the S7-1200 PID_Compact block accept a setpoint that changes every PLC cycle?

Yes. The Setpoint tag is a Real input and is read by the block on every execution. There is no internal filter that slows the response to a moving setpoint; the controller responds at the rate of Config.CycleTime. For best results, assign Config.CycleTime to a cyclic interrupt OB and keep it 5x-10x faster than the mechanical time constant of the drive.

Is it better to use Architecture A (encoder as setpoint) or Architecture B (error as input, setpoint = 0)?

For synchronization, Architecture B is generally preferred because the controller only corrects a small error and the dynamics are easier to tune. Architecture A is appropriate when the slave must hold a specific absolute speed target derived from the master. See Section 1 for the full decision matrix.

Should I enable the D-term (TD) of PID_Compact for a speed sync loop?

For most gearmotor applications, leave TD = 0.0 and use PI control. The D-term amplifies encoder noise and produces output spikes. If derivative action is required, set DerivativeDelay to 1-5 s (for a 10 ms cycle) to filter the D-term. See Section 6.

Why does pretuning fail when the master speed is changing?

The pretuning algorithm injects step changes into the Setpoint to identify the process. If application code is also writing the Setpoint every cycle, the wizard's steps are masked by the application. Disconnect the application write, hold the Setpoint at a representative operating point, and run pretuning. Then reconnect the Setpoint write. See Section 5.

How do I synchronize two gearmotors faster than 20-30 Hz closed-loop bandwidth?

Use a vendor-specific synchronization card (SEW DRS11B, ABB frequency input, and similar) that closes the loop inside the inverter firmware at the current loop rate. The S7-1200 PID_Compact path is limited to the PLC cycle time and the analog I/O update latency, which together cap the closed-loop bandwidth at roughly 20-30 Hz.

Back to blog