AutomateDirectUSAMotion LibraryIndustrial monitors & PCs

How-to

Running Three Phase-Shifted Hydraulic Cylinders With PLC PID

Pneumatics and hydraulics Published 8 min read By AutomateDirectUSA engineering team

Short answer

Yes. Run one position PID loop per cylinder and feed all three from a single master phase computed once per fixed control interval: the cycle period is 60 divided by RPM in seconds, cylinder 2 leads by a third of it and cylinder 3 by two thirds. A lookup table can supply the setpoints if you commit all three as one set; the real limit is analog-channel sampling skew.

On this page
  1. Separate the profile from the loops
  2. Build the master phase and the 120 degree offsets
  3. Execute every loop at one fixed interval
  4. Worked example: 20 RPM on an 8 in stroke with a 0.002 in tolerance
  5. Make the feedback one snapshot
  6. Commit the setpoints as a set
  7. Tune the loops and respect the valve path
  8. Questions asked

Yes — run one position PID loop per cylinder and drive all three from a single master phase that advances once per fixed control interval. The cycle period is 60 divided by RPM in seconds, so cylinder 2's setpoint is read from the profile 120 degrees ahead of cylinder 1's and cylinder 3's from 240 degrees ahead. A lookup table is the right setpoint source, provided all three values are computed from one snapshot and committed as a set before any PID executes. Your five questions collapse into three jobs: hold a fixed interval, budget the input sampling skew, and protect the setpoint commit.

Separate the profile from the loops #

A PID does not create the periodic motion; it corrects the difference between commanded and measured position. Split the chain into four jobs: the transducers measure, one trajectory calculation says where each cylinder should be, three PID loops produce three valve commands, and the output module plus valve drivers apply them to the valves. The single-axis version of this, controlling hydraulic cylinder position from a 0-10V analog input, is the same four blocks with one cylinder, so the loop tuning you already know carries over.

What must not be duplicated is the timebase. Three independent timers accumulate three different errors, and those errors show up later as phase drift you will chase as a tuning problem. One master phase, one snapshot, three loops.

Build the master phase and the 120 degree offsets #

For a commanded speed in rev/min, the cycle period is T = 60 / RPM seconds. Cylinder 2's setpoint is the profile position at master phase plus 120 degrees, cylinder 3's at plus 240 degrees — T/3 and 2T/3 in time. These are fixed phase locations inside the repeating profile, not delays each cylinder accumulates on its own.

Choose a table length that divides by three, so cylinder 2 reads a whole-number index offset of table length / 3 and cylinder 3 twice that. If the length does not divide by three, use fractional indexing with linear interpolation rather than rounding each axis to a different entry. Make the table cyclically continuous: the last entry must flow into the first with no position step, and ideally no slope step either, because a slope step demands an instantaneous velocity change from the valve.

Settle the sign of "120 degrees ahead" at commissioning — jog the master phase forward slowly with the profile amplitude reduced and confirm the physical firing order. This check, like the channel-swap test later, runs the machine under pressure: relieve stored hydraulic energy and follow your lockout procedure and the machine's risk assessment before hands or tools go near the axes.

The same table-plus-commit pattern extends to discrete outputs; table-driven sequencer valve control with a PLC program is the on/off-valve version of it.

Execute every loop at one fixed interval #

Yes, you can and must fix the sample interval, because the integral and derivative terms are only correct for the elapsed time they assume. Put the whole update in one periodic task, in this order:

  1. Capture the master time or phase once.
  2. Copy the latest complete set of three feedback values into working memory.
  3. Compute all three phase-shifted setpoints into staging registers.
  4. Execute the three PID calculations once each.
  5. Apply command limits and transfer the three valve commands to the outputs.

Do not trigger the loops from scan logic whose duration changes with unrelated machine code, and do not let a loop execute twice inside one interval. Measure the actual interval and its worst-case spread in the running program; the configured number proves nothing by itself. Choose the interval from the slowest element of the whole path — transducer conversion, input module, PLC, output module, valve driver, valve, cylinder — not from the RPM. A 3 s cycle can contain profile segments that need far faster correction than a smooth 3 s cycle suggests.

Worked example: 20 RPM on an 8 in stroke with a 0.002 in tolerance #

Inputs, each with its source:

  • Commanded speed: 20 rev/min, the top of this machine's 1–20 rev/min range.
  • Stroke 8 in and position tolerance 0.002 in: values reported for a comparable three-axis machine on proportional valves, used here as example inputs, not as measurements of your machine.
  • Control interval: 10 ms, chosen for this example.
  • Profile: a sinusoidal out-and-back over the full stroke once per cycle, assumed so the peak speed has a closed form.

Rules in words: the period is 60 divided by the speed; each offset is one third and two thirds of the period; updates per cycle are the period divided by the interval; the peak speed of a sinusoidal out-and-back is pi times the stroke divided by the period; apparent position error from sampling is speed times the time offset between channels; the allowable time offset is tolerance divided by peak speed.

The arithmetic:

  • T = 60 / 20 = 3.000 s.
  • Cylinder 2 offset = 3.000 s / 3 = 1.000 s; cylinder 3 offset = 2.000 s.
  • Updates per cycle = 3.000 s / 0.010 s = 300, so a 300-entry table gives one entry per update, cylinder 2 reads index +100 and cylinder 3 index +200, and the phase advances 360° / 300 = 1.2° per update.
  • Peak speed = pi x 8 in / 3.000 s = 8.38 in/s.
  • Skew budget = 0.002 in / 8.38 in/s = 0.000239 s, about 0.24 ms.
  • Sensitivity: each 1.0 ms of channel-to-channel offset appears as 8.38 in/s x 0.001 s = 0.0084 in of false phase error, which is 4.2 times the tolerance.

This is a calculated example for these inputs, not a measured result. The decision it leads to: take the channel-to-channel conversion time from the analog I/O manual of your input module, by part number. At or under about 0.24 ms, the multiplexed inputs can hold a 0.002 in phase relationship at 20 RPM; above it they cannot, and no PID tuning recovers an error made before the loop runs — that is the case for simultaneous-sampling input hardware or a multi-axis motion controller. A profile with ramps and dwells runs a higher peak speed than the sinusoid, so redo the last two lines with your real profile's peak before accepting the budget.

Make the feedback one snapshot #

Can you ensure all three transducers are sampled at the same time? On a multiplexed module, no — reading three channels in the same scan does not mean they were converted at the same instant. Modules in this class push every channel through one A/D converter into one 16-bit register, and ladder logic de-multiplexes it; the module's analog I/O manual documents the conversion sequence chapter by part number, and that document, not the ladder, gives you the channel-to-channel time. Quantify it; do not assume zero.

Two practices follow. Copy the latest complete channel set into working memory before any PID runs, so no loop mixes an old sample with a new one. Then separate channel skew from a mechanical lag by swapping two transducers between input channels and repeating the run: if the apparent lag follows the channel it is timing; if it stays with the cylinder it is scaling or hydraulics.

If your tolerance needs simultaneity tighter than the measured skew allows, software cannot reconstruct it — same-time positions require known sample times plus a valid motion estimate, which is a controller, not a patch. The same input-path floor appears when asking whether a PLC servo valve can stop a ram repeatably: the measurement path sets the floor, not the gains.

Commit the setpoints as a set #

Keep the loops running through setpoint changes. A position servo is supposed to receive a new setpoint every interval, and disabling a PID for a setpoint write is how you get output bumps. What you must prevent is a loop acting on a partially updated trajectory or a mixture of setpoints from two different master phases.

Calculate the three setpoints in staging registers, range-check them, transfer all three in one commit, then run the PIDs. In sequential ladder this is simply profile-and-commit rungs ahead of the PID rungs. If another task or an operator interface can rewrite the table asynchronously, guard the transfer with a ready/acknowledge handshake or a sequence counter the control task verifies.

Change recipes, tables, speed or mode at a control boundary: validate the replacement profile first, and if motion must pause, hold the loops in a state where the integral cannot wind up against a command the outputs cannot follow. Resume with the loop state aligned to the actual output so the command does not step.

Tune the loops and respect the valve path #

The PLC loop is the outer position loop; the valve driver's PWM current pulses and the valve sit inside it, and their response caps your gains. Integral action is the classic instability on hydraulic position loops — one laboratory demonstration of PID position control on a hydraulic cylinder shows integral action alone driving the loop into oscillation quickly — so start with proportional only, add integral in small steps, and use derivative sparingly or not at all. The reasons PI tuning runs slow on a high-inertia hydraulic drive are the same ones that set your gain ceiling here. Keep the profile's slope continuous where you can: a slope discontinuity is a velocity step, and a short route to why a hydraulic cylinder jerks when the valve shifts.

Questions asked

Do the three cylinders need different PID gains?

Yes, plan on it. Identical cylinders still differ in friction, load, hose runs and valve deadband, so tune each loop on its own axis and accept different gains. What must be identical is the timing: one master phase, one feedback snapshot, one interval for all three. If one axis needs markedly softer gains than its sisters, find the mechanical cause before you ship the sequence.

My profile table is 1000 points, which is not divisible by three. Does that matter?

Yes. Cylinder 2's offset is 333.33 entries, so rounding each axis to its own whole index injects a phase error of up to half an entry. Use fractional indexing with linear interpolation between entries, or pick a table length that divides by three. With a 300-entry table the offsets land exactly on entries 100 and 200.

How do I tell channel skew from a real mechanical lag?

Command all three cylinders to the same phase, record the apparent position differences at speed, then swap two transducers between input channels and repeat the run. If the apparent lag follows the channel, it is acquisition timing; if it stays with the cylinder, it is scaling or hydraulics. The swap test separates the two in one pass.

Can I change RPM while the machine is running?

Yes, at a control boundary. Compute the new cycle period, convert the current master phase to the new rate so commanded position stays continuous, and commit the new rate through the same staging handshake as a recipe change. Never let a loop see a phase that jumps, because the PID will answer with a velocity step the valve cannot follow.

When is a motion controller the right call instead of the PLC?

When the numbers say so. If the skew budget from the worked example comes out tighter than your input module's channel-to-channel conversion time, or the axes must interpolate between arbitrary target points instead of repeating one table, a multi-axis hydraulic motion controller does the coordination in hardware. For a fixed repeating profile with a comfortable skew budget, three PLC loops hold the phase.

Keep reading

  • Selection guide

    Controlling Hydraulic Cylinder Position From a 0-10V Analog Input

    No. An analog voltage into a hydraulic valve commands spool position and therefore flow, not cylinder position. Use it as the position reference to a closed-loop motion controller with an in-cylinder displacement transducer, and size the valve near 10 L/min for the 7.8 L/min peak of the 1.5-inch-bore example.

    Pneumatics and hydraulics

  • Troubleshooting

    Why PI Tuning Is Slow on a High-Inertia Hydraulic Drive

    Your manual voltage-decrement test took the motor from 2100 to 2000 RPM in about 1 s, while the tuned PI loop manages about 3.3 RPM/s — roughly 30 times slower — so the hydraulics can respond and the slowness points to output scaling, output limits or valve-command mismatch. Fix those, then retune against the measured benchmark.

    Pneumatics and hydraulics

  • Explainer

    Can a PLC Servo Valve Stop a Hydraulic Ram Repeatably

    No — not on a PLC analog output alone. Oil compressibility, load and valve null drift move an open-loop stop, so the loop must close on a ram-mounted transducer, which a Delta Motion note says can position heavy loads to better than 0.0005 in. Decide by measuring today's stopping spread against the part tolerance: if the stop switch meets it, modernize the servo positioner and keep the manual fallback.

    Pneumatics and hydraulics