AutomateDirectUSAMotion LibraryShop the parts catalog

How-to

Synchronizing a servo motor and encoder through an S7-1200 PLC

Servo and stepper motion Published 9 min read

Short answer

You never synchronize a servo motor's own encoder from the S7-1200: the drive aligns it at commissioning. The PLC's job is the outer loop only — read an external encoder on a high-speed counter, scale it to engineering units, and trim an analog speed reference to the drive while the current and speed loops stay inside the drive.

On this page
  1. Two jobs hiding in one question
  2. Align the motor encoder inside the drive first
  3. Choose the architecture the S7-1200 closes well
  4. Wire the external encoder to a high-speed counter
  5. Worked example: scaling a 1024-line encoder on a 100 mm roll at 0.5 m/s
  6. Close and tune the outer loop
  7. Prove the chain end to end
  8. Questions asked

The S7-1200 does not synchronize a servo motor with its own encoder — no controller does that job from outside the drive. The alignment between the encoder's zero mark and the motor's electrical phases, the commutation offset, is measured and written once inside the servo drive at commissioning, and the PLC never sees it. What the PLC can synchronize is everything beyond the drive: an external encoder mounted on the load, read by a high-speed counter, scaled to engineering units, and used to trim an analog speed reference so the load holds the setpoint. The drive keeps the fast current and speed loops; the PLC closes the slow outer loop around them. This article separates the two jobs, walks the drive-side alignment, then builds the PLC side end to end with a worked scaling example.

Two jobs hiding in one question #

The word synchronize covers two different jobs with different owners, and mixing them up is why PLC-side changes never fix drive-side faults.

Job What it lines up Who owns it Where it is set
Commutation alignment The encoder zero against the motor's electrical phases The drive and motor, as a matched pair The drive's commissioning routine
Outer closed loop The load position or speed against the setpoint, via a user-mounted encoder The S7-1200 program: high-speed counter, scaling, PID, analog output Your PLC project

A servo is a power amplifier, a motor and a feedback element matched as one set, and the drive aligns that feedback element to itself independently of any controller. Decide which job you need before writing code: an axis that misbehaves the moment it is enabled needs drive-side commissioning, and no PLC program will repair it. If the load has to follow a setpoint measured at the load itself, you need the second job, and that is the one built below.

Align the motor encoder inside the drive first #

The commutation offset is the angle between the rotor pole position and the encoder's zero-degree pulse. On one drive family it is determined once with the P160 command, 'Electrical commutation offset'; another drive exposes a CommutationOffset parameter spanning 0 to 359 degrees that compensates for motor misalignment. On motors with encoder memory the angle was measured at the factory and written into the electronic nameplate, so loading the motor data into the drive is the entire procedure.

  1. Wire the motor power and feedback cables to the drive as the drive manual shows, with the PLC disconnected from the command path or the drive in its local commissioning mode.
  2. Select the motor and encoder type in the drive's commissioning software; where the pair carries an electronic nameplate, load the data from the motor rather than typing it.
  3. Where no stored angle exists, run the drive's own phasing or encoder-offset routine.
  4. Jog the motor from the drive tool at low speed in both directions.

A passing jog turns smoothly both ways, the drive's speed feedback matches the commanded speed, and the no-load current is low and similar in both directions. A large current asymmetry or a fault on enable points at the offset or the feedback wiring. If the motor or its encoder was replaced, the pairing has to be relearned — the same job as commissioning a replacement servo encoder with motor ID data.

Choose the architecture the S7-1200 closes well #

Two structures work, and the choice decides everything downstream.

Drive closes everything. The drive runs its own current, speed and position loops from the motor encoder, and the S7-1200 supplies an analog speed or torque reference or a drive-defined command. No PLC encoder exists in this path and none is needed.

PLC closes an outer loop. An external encoder measures the load — a conveyor belt, a table, a take-up roll. The PLC compares the scaled measurement with the setpoint and corrects an analog speed reference through its PID function, while the drive stays in speed mode so its inner loops remain fast.

Keep the current and speed loops inside the drive: a PLC cycle is far slower than a drive's current loop, and lifting those loops into the PLC ends in instability. Closed-loop control with the PLC commanding the drive by analog signal is supported on the S7-1200 from FW4.1 (TIA Portal V13 SP1); on other command paths you design the loop structure yourself. Prove the reference path before building anything: force a fixed voltage at the analog output and confirm the drive follows it in the right direction at a scale you can compute — load speed equals the reference fraction times the drive speed at full-scale reference.

Wire the external encoder to a high-speed counter #

The external encoder is read by a hardware high-speed counter, never by an ordinary digital input scanned in the program cycle — a scan misses pulses at any practical shaft speed.

Connect A and B to the counter inputs the HSC is assigned to, power the encoder within its rating, and share the 0 V reference between the encoder supply and the PLC inputs. If the encoder is 5 V logic and the inputs are 24 V, level matching comes first — the same questions as connecting a 5V servo encoder to 24V PLC inputs. Use shielded twisted-pair cable, terminate the shield as the encoder manufacturer documents, and route it away from motor power cables.

In the project, enable the HSC on the matching inputs and select a quadrature, A/B counting mode so direction comes from the phase relation. The settings that matter — input assignment, count mode, filter time — are exactly those covered in configuring a high-speed counter for an encoder input, and the motion-control encoder configuration also lets an axis take its actual value from that counter; check the filter times of the counter inputs while you are there.

Hand-check before going further: turn the shaft by hand and watch the counter. It must increase in one direction, decrease in the other, and return to the same value when you come back to a marked start position. Counts lost on the return mean noise, an input filter too slow for the edge rate, or a loose connector.

Worked example: scaling a 1024-line encoder on a 100 mm roll at 0.5 m/s #

Scaling raw counts into engineering units is the same arithmetic on any controller that holds it — the pattern matches scaling raw data to engineering units.

Inputs #

  • Encoder line count: 1024 lines per revolution, an illustrative common value — take the real figure from your encoder's datasheet.
  • Decoding: x4 quadrature at the HSC, so counts per revolution = 4 x 1024 = 4096.
  • Mounting: encoder coupled directly to the conveyor drive roll, gear ratio 1 (one encoder revolution per roll revolution).
  • Roll diameter: 100 mm, measured on the machine — illustrative.
  • Load speed: 0.5 m/s = 500 mm/s — illustrative conveyor speed.
  • Program cycle: 10 ms — illustrative PLC scan time.

The rule in words #

Millimetres per count equals roll circumference divided by counts per encoder revolution, with circumference equal to pi times the roll diameter. A polled digital input can follow a pulse train only while each pulse lasts longer than about two cycle times.

The arithmetic #

  • Circumference = pi x 100 mm = 314.16 mm per roll revolution.
  • Scale = 314.16 mm/rev divided by 4096 counts/rev = 0.0767 mm per count.
  • Roll speed = 500 mm/s divided by 314.16 mm/rev = 1.592 rev/s.
  • Count rate = 1.592 rev/s x 4096 counts/rev = 6519 counts/s, about 6.5 kHz, so the edge period is 1 / 6519 s = 0.153 ms.
  • Scannable ceiling = 1 / (2 x 10 ms) = 50 pulses per second.

Result and decision #

The scaled position moves 0.0767 mm per count, and at full conveyor speed the counter sees about 6.5 kHz of quadrature edges. That is roughly 130 times the 50 Hz a scanned input could follow, so the hardware HSC in quadrature mode is not optional — and the input filter must be fast enough for a 0.153 ms edge period, with the exact maximum input frequency confirmed against your CPU's datasheet for the counter inputs you used. On resolution: a plus or minus 0.5 mm positioning requirement equals plus or minus 6.5 counts at this scale, comfortably resolvable; the same encoder asked for plus or minus 0.05 mm would deliver only 0.65 counts, and a higher line count becomes the fix. This is a calculated example for these inputs, not a measured result.

Close and tune the outer loop #

Hold the drive in speed mode with a conservative speed limit, and keep a hardware enable or stop path that works independently of the PLC program — make any encoder-wiring change with the drive disabled and the machine locked out.

Configure the PID with the scaled encoder value as the process value and the analog output as the manipulated value, and limit the output to a small fraction of drive full scale for the first runs. Tune in order: proportional gain alone until the load moves toward the target, then integral action to remove the steady-state error, then derivative only if the scaled value is quiet enough to deserve it.

Check the sign before trusting anything: a positive error must produce a reference that moves the load toward the setpoint. If the load runs away from the target, reverse the output polarity and stop immediately on any divergence.

A small step setpoint should settle without sustained oscillation. Continuous hunting around the target means excess gain, backlash between motor and load, or a coarse analog output resolution in the reference path. If the output sits at its limit and the load still falls short of the speed you asked for, the reference ceiling is the suspect — the causes are laid out in why a servo axis never reaches its commanded speed.

Prove the chain end to end #

  1. With the drive disabled, rotate the load by hand and confirm the PLC position changes with the correct sign and the scale from the worked example.
  2. Enable the drive with the setpoint equal to the present position: the shaft stays still and the drive raises no encoder or following-error fault.
  3. Command a short move: the load reaches the setpoint and settles inside the tolerance you set, confirmed against a physical measurement such as a ruler or dial gauge, not only the PLC value.
  4. Return to the start position ten times: the repeated final counts and measured positions agree within tolerance, showing no accumulated count loss.
  5. At low speed, drop the PLC to stop mid-move with the stop path ready: the hardware enable or stop path must arrest the axis without the program running.

If all five pass, the loop is synchronized in the only sense the PLC owns: the load follows the setpoint, the drive keeps its fast loops, and the encoder counts stay honest. That is a commissioning check you performed on your machine, not a substitute for its risk assessment and safety validation.

Questions asked

What are the symptoms of a wrong commutation offset?

An axis that runs away the instant it is enabled, delivers far less torque per amp than it should, or trips a following-error fault right after enable. All three point at the drive-side alignment or the feedback wiring, not at the PLC program. Re-run the drive's phasing routine and check the feedback connectors and shield terminations before touching anything in the controller.

Can one external encoder feed both the PID loop and a position display?

Yes. Scale the counter value once and let the scaled value serve several consumers at the same time: the PID process value, a position readout and a logging tag all read the same number. The only hard limit is the counter input's datasheet maximum frequency, which your encoder's count rate at top speed has to stay under.

How do I find counts per revolution when the encoder label is gone?

Mark the input shaft, zero the counter, and turn the shaft exactly one full revolution by hand. The count delta you read is counts per revolution in the decoding mode you selected. Back-check it by rolling the load a measured distance and comparing distance times counts per millimetre against the counter delta; a mismatch points at the quadrature decoding or a gear ratio between encoder and load.

Why does the scaled position creep while nothing is moving?

The counter is registering edges the machine is not producing. The usual sources are a shield terminated against the manufacturer's rule, encoder lines routed beside motor power cables, an input filter slow enough that noise is counted as motion, or a loose encoder mount letting vibration wiggle the shaft. Clean the wiring and filter first; if the creep survives clean wiring, the load really is moving.

Does this change if my drive takes step and direction pulses instead of an analog reference?

Yes. A pulse interface makes the PLC the profile generator while the drive still closes its own loops to the pulse stream, and there is no clean slot for a load-feedback correction in that path. If the load must be regulated from an external encoder, choose a drive that accepts an analog speed reference or its own second encoder input, and keep the correction in the analog path.

Keep reading

  • Explainer

    Mounting a Motor Encoder Behind a Belt Reduction

    No, not for commutation: field-oriented control switches phase current against the rotor's electrical angle, which only a sensor on the motor shaft reports directly. Behind a 10:1 belt, a 4096-count encoder gives about 410 counts per motor revolution — enough counts per pole to turn a 6-pole motor, but belt lash and multiplied noise put a load-dependent error inside the current loop. Use the belt-side sensor for velocity only; commutate from the motor shaft and add an output encoder if you need load position.

    Servo and stepper motion

  • Troubleshooting

    Servo Drive Over-Speed Alarm: Causes and Checks

    An over-speed alarm means the drive measured motor speed above the limit configured in its speed-limit parameter, not that the motor is broken. Confirm whether the limit, the command, the ramps, false encoder feedback, unstable tuning or a load that back-drives the motor put it there, cheapest first, and never raise the limit to silence a trip whose cause you have not confirmed.

    Servo and stepper motion

  • Troubleshooting

    Fix Servo Travel Error After Swapping Resolver and Encoder

    Travel that does not match the position display after a resolver-to-encoder swap is a scaling fault: the drive or the technology axis is still converting counts with the other feedback's increments per revolution. Measure one commanded move and divide actual by displayed travel; a constant ratio equal to the resolution ratio names the encoder data. Fix both layers, re-home, then re-tune.

    Servo and stepper motion