S7-1200 Motor Synchronization with HSC Encoders and MC_GearIn

David Krause14 min read
S7-1200SiemensTechnical 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

1. System Overview

Two-motor speed synchronization on a SIMATIC S7-1200 requires three coordinated functions: encoder pulse acquisition through high-speed counters (HSC), velocity measurement in user program, and a motion command that drives the follower axis. When the requirement is "speed_1 == speed_2", the simplest implementation is two independent TO_PositioningAxis objects commanded by MC_MoveVelocity. When the requirement is high-accuracy phase-locked speed tracking at varying setpoints, the implementation must use position synchronization via MC_GearIn (electronic gearing), where the master axis position increments drive the follower axis.

This reference covers the closed-loop architecture where Motor 1 (master) is governed by a potentiometer and Motor 2 (follower) is governed by an analog voltage reference to its drive. Both motors have incremental rotary encoders wired into the S7-1200 HSC inputs. The PLC reads the actual velocity of Motor 1 from HSC1 feedback and either mirrors it as a velocity setpoint or uses it as the master position stream for the follower axis.

Position-based synchronization (gearing) is the only approach that guarantees zero steady-state velocity error and tracking accuracy better than the HSC measurement quantisation. Pure velocity-command mirroring has a sample-time dependent lag of one PLC scan.

2. Hardware Prerequisites

Component Specification Notes
S7-1200 CPU CPU 1214C DC/DC/DC or CPU 1215C, firmware V4.2 or higher Motion Control is supported from FW V4.0 onward. V4.4+ is recommended for MC_GearIn enhancements.
Encoder type Incremental quadrature, 24 V HTL or 5 V TTL depending on CPU CPU 1214C DC/DC/DC onboard HSC supports 24 V single-ended or differential (with SM 1221 DI module).
Encoder resolution 100, 360, 500, 1000, 1024, 2048, 4096 PPR Higher PPR improves speed resolution and gearing smoothness. Avoid PPR that yields non-integer distance-per-revolution.
Drive for Motor 2 Analog-input VFD or servo drive, e.g., SINAMICS V20, G120, S110 Analog input 0-10 V or 4-20 mA; setpoint update rate at least 1 ms.
Analog output for Motor 2 SM 1232 AQ 2x14 bit or onboard AQ (CPU 1215C) Used to command drive velocity; resolution determines speed granularity.
Analog input for Motor 1 pot Onboard AI (CPU 1214C has 2 AI) or SM 1231 AI4 Read scaled 0-10 V pot.

Verify that both drives accept an analog reference and that the drive parameter for analog input scaling matches the PLC engineering units (e.g., 0-10 V = 0-1500 rpm).

3. Encoder Wiring and HSC Channel Assignment

The S7-1200 onboard HSC supports up to six high-speed counters (HSC1-HSC6) depending on CPU model. Each HSC accepts an incremental encoder on a dedicated pair of digital inputs and supports quadrature counting modes (1x, 2x, 4x).

HSC Channel Default Input Assignment Count Mode Max Frequency (per phase)
HSC1 I0.0 (A), I0.1 (B) Quadrature 4x 100 kHz (CPU 1214C), 1 MHz on 1217C
HSC2 I0.2 (A), I0.3 (B) Quadrature 4x 100 kHz
HSC3 I0.4 (A), I0.5 (B) Quadrature 4x 100 kHz
HSC4 I0.6 (A), I0.7 (B) Quadrature 4x 100 kHz
HSC5 I1.0 (A), I1.1 (B) Quadrature 4x 100 kHz
HSC6 I1.2 (A), I1.3 (B) Quadrature 4x 100 kHz

Wire Motor 1 encoder to HSC1 inputs (I0.0 = Phase A, I0.1 = Phase B) and Motor 2 encoder to HSC2 inputs (I0.2 = Phase A, I0.3 = Phase B). For long cable runs in electrically noisy cabinets, use shielded twisted-pair cable with shield grounded at the cabinet entry panel only.

Enable the HSC channels in TIA Portal under Device Configuration > CPU > Properties > High-Speed Counters (HSC):

  • Enable HSC1: Type = Counting, Counting mode = Quadrature 4x, Initial count value = 0
  • Enable HSC2: Type = Counting, Counting mode = Quadrature 4x, Initial count value = 0
When HSC inputs are configured, the corresponding digital inputs are reserved and cannot be used by the standard process image. Use symbolic I/O access only through the HSC IDB (instance DB) or CTRL_HSC_EXT extended instructions.

4. Encoder-Based Velocity Calculation

Raw HSC count values are integer positions, not velocities. Velocity must be calculated in the user program by sampling the counter value over a fixed window. The standard Siemens idiom is to read the HSC count at a cyclic interrupt OB (e.g., OB30 at 50 ms or 100 ms), compute the difference, and divide by the sample time and pulses-per-revolution.

Formulas for converting HSC counts to engineering units:

n_rpm[rev/min] = (DeltaCount * 60000) / (PPR * SampleTime_ms * QuadratureFactor)

v_mm_per_s    = (DeltaCount * (DistancePerRev_mm * 60)) / (PPR * SampleTime_ms * QuadratureFactor)

omega_rad_per_s = (DeltaCount * 2 * PI) / (PPR * SampleTime_ms * 0.001 * QuadratureFactor)

Where QuadratureFactor = 4 for quadrature-4x mode and SampleTime_ms is the cyclic OB period. Example: PPR = 1024, sample time = 100 ms, 4x mode, observed DeltaCount = 1024:

n_rpm = (1024 * 60000) / (1024 * 100 * 4) = 60000 / 400 = 150 rpm

The HSC IDB exposes Count (DINT, signed 32-bit) and NewCount flag in the instance data block. Always use a local L-tag to capture Count at the start and end of each OB30 cycle to avoid mid-scan race conditions.

5. Motion Control Architecture Selection

Three architectures are viable. The selection depends on the required tracking accuracy and whether the master speed is constant or varies.

Architecture Description Steady-State Velocity Error Phase-Locked at Variable Speed CPU Scan Load
A. Open-loop analog mirroring Pot -> AI -> AQ directly to drive 2, no PLC involvement in control High (drift, offset) No None
B. Closed-loop velocity following Pot -> MC_MoveVelocity on Axis_2; HSC1 velocity as outer trim Low (one scan lag) Approximate Low
C. Electronic gearing Axis_1 (virtual master from HSC1) -> MC_GearIn -> Axis_2 Zero (position-locked) Yes Medium

For two motors running with a constant speed set by the operator, Architecture B is sufficient and easiest to commission. For any application where the master ramps up/down or where angular phase must be preserved (printing, cutting, conveyor-to-conveyor transfer), Architecture C is required.

6. Technology Object Configuration

Per the S7-1200 Motion Control Function Manual, create two TO_PositioningAxis objects in the project tree:

Parameter Axis_1 (Virtual Master) Axis_2 (Follower)
Axis type Real, linear or rotary Real, rotary (recommended)
Drive interface No drive; encoder-only via TO_ExternalEncoder linked to HSC1 Analog drive (PTO not used)
Encoder interface External encoder on HSC1, count value from IDB External encoder on HSC2 (optional for monitoring)
Pulses per revolution 1024 (match encoder) 1024
Distance per revolution 1000 (1 user unit = 1 mm equivalent) 360 (1 user unit = 1 degree)
Max velocity 3000 mm/s equivalent 3000 deg/s
Max acceleration 10000 mm/s² 10000 deg/s²
Velocity tolerance 5% 5%
Position tolerance 100 units 5 units
Homing Passive homing via MC_Home, triggered on first Z-pulse Passive homing via MC_Home

Because Axis_1 has no drive and no PTO output, define it as a "virtual axis" by linking it to an external encoder only. The TO_ExternalEncoder technology object must be added first under Technology > External Encoder; bind it to HSC1 with the same PPR. Then in Axis_1 configuration, set Encoder connection to this external encoder.

7. Speed-Mode Implementation with MC_MoveVelocity

Architecture B uses two independent motion commands, each driven by the analog pot:

  1. Read pot from AI0 (0-27648 raw = 0-10 V) and scale to Velocity_setpoint in user units/s using NORM_X and SCALE_X.
  2. In OB1 (or OB30 for deterministic rate), call MC_MoveVelocity on Axis_1 with Velocity = Velocity_setpoint. Execute = Run_enable AND MasterEnable.
  3. Mirror Velocity_setpoint to MC_MoveVelocity on Axis_2 with the same velocity value. Output to drive 2 via analog AQ.
  4. Read actual velocities from each axis' ActualVelocity tag in the Axis DB.

SCL example for Axis_2 command:

IF "Run_Enable" AND "Master_Enable" THEN
    IF "MC_MoveVelocity_2_Done" OR "MC_MoveVelocity_2_Error" THEN
        "MC_MoveVelocity_2"(
            Axis := "Axis_2",
            Execute := TRUE,
            Velocity := "Velocity_Setpoint_RPM",
            Direction := 2,           // 2 = current direction
            CurrentVelocity := 0,
            Position := 0,
            Aborting := TRUE
        );
    END_IF;
ELSE
    "MC_Halt_2"(
        Axis := "Axis_2",
        Execute := TRUE,
        Deceleration := 5000
    );
END_IF;

This open-loop velocity mirroring is accurate to about ±1% under steady state. The lag during ramp is one PLC scan. For higher precision, layer a closed-loop trim:

// Sample every 100 ms in OB30
"v1_actual" := "MC_Axis_1".ActualVelocity;
"v2_actual" := "MC_Axis_2".ActualVelocity;
"v_error"   := "v1_actual" - "v2_actual";

// Integral trim, apply to AQ2 offset
"v_integral" := "v_integral" + ("v_error" * "Ki" * 0.1);
"v_integral" := LIMIT(-500.0, "v_integral", 500.0);
"AQ2_output" := "V_setpoint_scaled" + "v_integral";

Tune Ki starting at 0.05 and increase by 50% until the velocity error settles within ±2 rpm under step load changes.

8. Closed-Loop Synchronization with MC_GearIn (Electronic Gearing)

When the operator turns the pot, the master velocity ramps. To maintain phase lock, the follower must execute MC_GearIn against the master:

  1. Home both axes (or use passive homing on power-up).
  2. Start the master with MC_MoveVelocity.
  3. Call MC_GearIn on Axis_2 with Axis_1 as the master, RatioNumerator = 1, RatioDenominator = 1, Acceleration = 10000, Deceleration = 10000.
  4. The follower position will increment by 1 user unit per master unit. Use RatioNumerator/RatioDenominator for ratio scaling.

SCL snippet:

IF "Gear_Enable" AND NOT "MC_GearIn_Busy" THEN
    "MC_GearIn_DB"(
        Master := "Axis_1",
        Slave  := "Axis_2",
        Execute := TRUE,
        RatioNumerator := 1,
        RatioDenominator := 1,
        Acceleration := 10000.0,
        Deceleration := 10000.0,
        Aborting := TRUE
    );
END_IF;

MC_GearIn is available on S7-1200 firmware V4.2 and higher; refer to the S7-1200 Motion Control V5 manual for full parameter description and graph behaviour.

The follower axis ActualVelocity equals Master.ActualVelocity * (RatioNumerator/RatioDenominator) under steady state by definition of gearing; there is no steady-state error to trim. Dynamic error depends on the IPO cycle (4 ms for S7-1200) and drive-following-error bandwidth.

9. Drive Configuration for Analog Setpoint

Configure the drive accepting the AQ signal to operate in speed-control mode with analog input as primary setpoint:

Drive Parameter (Example V20) Setting
P0700 = 2 Command source = terminal
P1000 = 2 Frequency setpoint = analog input 1
P0756 = 0 Analog input type = unipolar 0-10 V
P0757 = 0, P0758 = 0, P0759 = 10, P0760 = 100 Input scaling: 0 V = 0%, 10 V = 100%
P1080 = 0, P1082 = 50 Min/max frequency in Hz
P1120 = 2, P1121 = 2 Ramp-up and ramp-down = 2 s (must be ≤ PLC ramp)

For SINAMICS G120 with CU240E-2, the equivalent parameters are in the SINAMICS G120 Parameter List (P15 free function blocks, P2250 technology controller selector). Set P2250 = 0 (analog setpoint), P1500 = 0 (analog main setpoint) to bypass any internal ramp generator that could fight the PLC.

10. S7-1200 CPU Scan Budget

Motion Control on S7-1200 uses a fixed interpolator (IPO) cycle of 4 ms. The user program must complete within the cyclic OB1 budget; for two axes plus HSC reads plus analog processing, expect:

OB1 Task Element Typical Execution Time
MC_MoveVelocity + MC_GearIn runtime ~1.5 ms per call
HSC read (2 channels) < 0.1 ms
AI/AQ scaling + PID trim < 0.2 ms
OB1 overhead ~0.5 ms
Total ~4 ms (CPU 1214C @ 90% utilization budget)

Keep OB1 cycle time below 8 ms. Use OB30 at 50 ms for the velocity-trim PID loop rather than OB1, so jitter from MC blocks does not perturb the integral term.

11. Commissioning Procedure

  1. Wire both encoders; verify pulse integrity with a hand-crank and the HSC IDB online Count value.
  2. Download the hardware configuration. Go online and confirm both HSC channels show "OK" in Online > Diagnostics.
  3. Configure both axes; commission Axis_2 with drive in jog mode to verify direction and scaling.
  4. Perform passive homing of both axes using the encoder Z-pulse as the homing marker. Verify Axis.XIST1 returns to 0 at the marker.
  5. Enable the master with MC_Power and MC_MoveVelocity at 100 rpm. Confirm Motor 1 spins.
  6. Enable MC_GearIn on Axis_2. Confirm Motor 2 accelerates to match. Monitor Axis_2.ActualPosition and Axis_1.ActualPosition; the ratio should hold exactly.
  7. Apply pot step changes (0%, 50%, 100%) and verify synchronous ramp.
  8. Run a 30-minute soak test; log both ActualVelocity values to a data block for trending.

12. Verification and Diagnostics

Add a watch table with the following tags to verify synchronization during commissioning:

Tag Expected Steady-State Value
Axis_1.ActualVelocity = pot setpoint ± 0.5 rpm
Axis_2.ActualVelocity = Axis_1.ActualVelocity ± 0.5 rpm
Axis_2.ActualPosition - Axis_1.ActualPosition Constant (offset only)
Axis_2.StatusWord.Error = 0
AQ2_output (V) Tracks Master.AQ1 within 0.05 V

Use the TIA Portal Traces function with a 100 ms recording rate on both ActualVelocity tags. Plot the difference to visualize drift. Drift above 0.5% indicates drive-side ramp or scaling error; drift above 1% indicates an encoder pulse-loss or HSC wiring issue.

13. Troubleshooting Matrix

Symptom Likely Root Cause Corrective Action
Both motors stay at 0 rpm MC_Power not executed, or Axis.StatusWord.Operational = 0 Execute MC_Power; check Enable_Positive and Enable_Negative both TRUE
Motor 2 runs in reverse Encoder direction inverted, or drive direction command reversed In Axis_2 configuration, invert encoder direction; or swap A/B phase wires at HSC2
Velocity oscillates ±10% IPO cycle too long, or drive-side ramp conflict Set drive ramp to 0 (P1120/P1121) and rely on MC ramp; verify OB1 cycle < 8 ms
Following error during ramp Master accelerates faster than follower drive can follow Increase drive torque limits, or slow master acceleration in MC_MoveVelocity
HSC count stuck at zero Encoder not powered, or HSC channel not enabled in device config Check 24 V at encoder; verify HSC1/HSC2 = "Enabled" in Properties
MC_GearIn returns ErrorID 16#8001 Axis_2 not homed Execute MC_Home on Axis_2 before MC_GearIn
Velocity drift of 0.5-1% over 10 minutes Drive parameter P0758/P0760 scaling not exact, or pot reference voltage unstable Recalibrate analog input scaling; use regulated 10 V reference
Master direction reversal causes follower to jerk MC_MoveVelocity.Direction bit flips; no smooth transition Use Direction = 2 (current direction) and MC_MoveVelocity with Aborting = TRUE

14. Edge Cases and Field-Proven Caveats

  • Encoder Z-pulse for homing: Without homing, the gear ratio holds but the absolute phase relationship is unknown. If the application requires a known phase (e.g., blades aligned), wire the encoder Z signal to an HSC marker input or a fast digital input and trigger MC_Home with Mode = 3 (passive homing on Z-pulse).
  • Loss of encoder feedback: HSC retains the last count but velocity calculation becomes 0. Add an underflow/overflow check using CTRL_HSC_EXT with upper/lower limits; raise a drive fault on violation.
  • Drive stop category: Ensure the drive is configured for STOP category 1 (controlled ramp-down) not category 0 (coast) when MC_Halt is issued. Category 0 on the master with the follower still geared will saturate the follower drive.
  • Power-up sequencing: Always power the master first, home it, then engage the follower with MC_GearIn. Reversing the order causes an immediate large following error on engage.
  • Firmware versions: MC_GearIn behaviour changed slightly between FW V4.2 and V4.4 (Abort handling on master stop). Review the firmware release notes on the Siemens Industry Online Support portal before commissioning.

15. Alternate Controller Notes

For applications where the S7-1200 scan budget is insufficient (e.g., above 4 axes or 1 ms IPO requirement), migrate to a SIMATIC S7-1500 with a 1 ms IPO cycle or to a SINAMICS S120 drive pair with DCC (Drive Control Chart) doing the gearing at the drive level. The latter eliminates the PLC entirely and reduces velocity tracking error to below 0.01%.

For cost-sensitive single-axis duplication where only speed (not phase) must match, a simple analog passthrough from drive 1 output to drive 2 input is acceptable and removes the PLC from the control loop entirely. The PLC then serves only for start/stop and monitoring.

How do I synchronize two S7-1200 motors where one has a pot and the other an analog drive?

Read the pot via AI0, scale to a velocity setpoint, and apply it via MC_MoveVelocity to both TO_PositioningAxis objects. For high accuracy, instead use MC_GearIn to bind the follower (Axis_2) to the master (Axis_1, fed from HSC1), so phase lock is maintained by position synchronization rather than velocity-command mirroring.

Which HSC inputs on S7-1200 should I use for two incremental encoders?

Use HSC1 (I0.0 = A, I0.1 = B) for the master encoder and HSC2 (I0.2 = A, I0.3 = B) for the follower encoder. Configure both in quadrature 4x counting mode in TIA Portal under Device Configuration > High-Speed Counters. The CPU 1214C supports six HSC channels at up to 100 kHz per phase.

Can I use MC_GearIn without physically homing the axes?

No. MC_GearIn requires both master and slave axes to be homed (referenced). For incremental encoders, use MC_Home with Mode = 3 (passive homing on Z-pulse) at power-up, or assign an absolute value reference. Without homing, the gearing engages but the absolute phase is undefined and following-error monitoring may fault.

What is the best PID tuning approach for closed-loop speed sync on S7-1200?

Use OB30 at 100 ms for the velocity-trim PID, with Kp = 0 first (pure integral). Increase Ki from 0.05 in 50% steps until velocity error settles within +/- 2 rpm under a step load. Add Kp only if a static offset remains. Avoid placing the PID in OB1 where MC runtime jitter perturbs the integral.

Why does the velocity oscillate between the two motors even with MC_GearIn?

With MC_GearIn, steady-state velocity error is theoretically zero. Oscillation usually means the IPO cycle is too long (above 4 ms), the drive internal ramp is fighting the PLC ramp, or the analog output scaling has a non-linearity. Disable drive ramps (P1120/P1121 = 0), verify OB1 cycle is below 8 ms, and recalibrate the AQ scaling.

Back to blog