How-to
PID control of a ±10 V proportional valve from a PLC
Short answer
Run the valve from a PID loop whose signed output is clamped to -100% to 100% and scaled linearly so +100% gives +10 V and -100% gives -10 V. Derive cylinder speed from the linear transducer, command speed as a curve of stroke position, and start the stop deadband at 2 mm so the valve does not chatter at target.

On this page
Replace the card with three functions in your PLC: a signed PID output clamped to its percent span and scaled linearly onto the valve's bipolar voltage command, a speed measurement derived from the cylinder's position transducer, and a speed setpoint picked from a curve of stroke position. Run the PID as a speed loop; position selects the setpoint and defines the stop deadband. This page covers the bipolar valve command and the speed-profile structure. The feedback side is covered separately by controlling hydraulic cylinder position from a 0-10 V analog input, and by path control of a hydraulic cylinder with 4-20 mA feedback for current-loop transducers.
What the card did and what replaces it #
An old valve driver card did three jobs. It turned a signed demand into a bipolar voltage: positive voltage drove the cylinder one way, negative voltage drove it the other, and the magnitude set the speed. It conditioned the cylinder's position transducer into usable units. And it shaped the motion.
Rebuild each job in the PLC. The transducer gives position in millimetres. The difference of position across one fixed task interval gives measured speed. A curve of stroke position gives the commanded speed, and the PID drives measured speed to that command. The controller works in percent, with the output clamped to -100% to +100% and zero meaning a centered valve. Because the loop closes on speed, it opens the valve farther on its own when load pressure rises and the speed sags.
Map the signed output to the bipolar command #
Keep the mapping linear and symmetric: 0% to 0 V at a centered valve, +100% to +10 V (full speed, extend), -100% to -10 V (full speed, retract). Sign is direction; magnitude is speed. If both directions come out reversed on the machine, flip the sign in this mapping, never in the PID's action settings.
The output module makes the volts, so the program writes an integer. Bipolar voltage channels use a symmetric raw range; for example, one common convention converts -10 V to +10 V into the integer range -27648 to +27648, while unipolar ranges such as 0-10 V map to a positive-only span. Take the actual numbers from the manual for your exact module and its configured range, because they differ between manufacturers and between ranges on the same module family.
The per-scan formula is one multiply:
raw = (output % ÷ 100) × full-scale raw value
Prove it in manual before the loop ever runs: command 10%, measure the terminal, then command -10% and measure again.
Drive the speed setpoint from stroke position #
Do not feed position error straight into the PID. A position loop wrapped around a proportional valve hunts at the target and fights the valve's own response. Instead, divide the stroke into zones and let position choose the speed: travel speed through the middle zones, a deceleration ramp before the target, a creep speed if the last few millimetres matter, and zero inside the deadband. Ramp between zone speeds rather than stepping them — a step in the commanded speed is what makes a cylinder jerk when the valve shifts, and why a hydraulic cylinder jerks when the valve shifts walks through that mechanism. Direction lives in the sign of the commanded speed, so a retract zone simply commands a negative speed.
Worked example: zones, speed and output scaling #
Calculated example, valid for these inputs only: stroke 500 mm; transducer scaled so position reads in millimetres; PID task fixed at 10 ms; speed curve of 100 mm/s from 0 to 450 mm, ramping down to 20 mm/s between 450 and 490 mm, holding 20 mm/s to the target at 500 mm; stop deadband of 2 mm around the target.
Measured speed: the transducer reads 1.0 mm farther than on the previous task, so speed = 1.0 mm ÷ 0.010 s = 100 mm/s, which matches the curve's travel speed with whatever output the tuning settled on.
Deceleration check: dropping 80 mm/s across 40 mm takes 40 mm ÷ 60 mm/s (the average through the ramp) = 0.67 s, so the deceleration is 80 mm/s ÷ 0.67 s ≈ 120 mm/s². If the cylinder overruns the target, stretch the ramp; if it dawdles through it, steepen the ramp.
Output scaling: say the tuned loop settles at +45% in the travel zone. Under the 27648 convention above, raw = 45 ÷ 100 × 27648 = 12441.6, written to the module as 12442, and the terminal voltage is 12442 ÷ 27648 × 10 V = 4.50 V, extending. A -45% output writes -12442 and commands the same magnitude in retract.
These are calculated results for these inputs, not measurements from a machine.
Tune the loop, find the null, set the deadband #
Find the valve's null compensation first. In manual with 0% commanded, raise the output in 1% steps until the cylinder just begins to creep — say it moves at 6% (an example figure; yours will differ). Store about that much as a signed offset applied to the output before the scaling, positive toward extend and negative toward retract, so the spool crosses its manufacturing overlap quickly in both directions instead of dawdling near null.
Raise proportional gain until measured speed tracks the curve without hunting, add integral until the standing error under load disappears, and add derivative only if the speed overshoots on the deceleration ramps. On a large or springy axis the integral term dominates and tuning feels slow; why PI tuning is slow on a high-inertia hydraulic drive explains that behaviour and what to change.
Set the position deadband last, at the target only. Start it at 2 mm and treat that figure as the positioning tolerance: when the absolute difference between target and position is inside the deadband, command zero and stop integrating. If the valve audibly reverses at the target, the deadband is narrower than the transducer's noise — widen it to roughly twice the position scatter you observe at rest, and a troubleshooting guide for PID valve deadband oscillation covers that failure in detail. Shrink the deadband only when the application genuinely needs the tighter tolerance, and re-tune the gains along with it.
Commission in this order #
One safety note before the first live output: a centered proportional valve will not hold a vertical cylinder, so block or support any hanging or pressing load, and fit a counterbalance or pilot-operated check valve wherever the machine's risk assessment calls for positive holding.
Then work down the list:
- Scale the transducer into millimetres and confirm position increases toward the target.
- In manual, command 10% one way, then the other; confirm both directions and that speed grows with output. Fix any sign error here, in the mapping.
- Find the null offset in 1% steps and store it as the signed compensation.
- Set the fixed task interval, derive speed from consecutive positions, and prove it with a stopwatch: 100 mm of travel in about 1.0 s should read near 100 mm/s.
- Tune the speed loop at mid-stroke on the travel-zone speed.
- Add the zones and ramps and confirm the commanded speed never steps.
- Set the deadband and run ten full cycles, watching for valve chatter at the target.
- Add a stall fault: output still well above the null offset with no position change for a set time — for example 20% and 500 ms, both set from your own commissioning numbers — zeros the output and raises an alarm. A valve held open with zero speed means a blockage or a lost load, not a tuning problem.
The decision, in one line: clamp the PID output to its signed percent span, scale it linearly onto the bipolar command with your module's documented raw range, run a speed PID whose setpoint comes from a ramped curve of stroke position, find the valve null before tuning, and start the stop deadband at 2 mm — widen it if the valve chatters at target, shrink it only with re-tuned gains and a genuinely tighter tolerance.
Questions asked
Can I run a valve that takes 4-20 mA instead of a bipolar voltage?
Yes, with the same structure. Many bidirectional current-command valves use 4 mA as full speed one way, 20 mA as full speed the other, and 12 mA centered, so map -100% to 4 mA and +100% to 20 mA with 12 mA at zero output. The arithmetic is identical; only the endpoints change. Check the valve's own datasheet for the actual convention before wiring.
How fast should the PID task run for a hydraulic valve loop?
In a fixed cyclic interrupt, not wherever the scan leaves it, because the speed calculation divides position change by the interval and the integral term assumes a constant sample time. For a proportional valve on a cylinder axis, 10 ms is a reasonable starting interval; halve it if the valve overshoots between corrections. Whatever you choose, keep it constant while the loop runs.
Why does the cylinder drift after the loop reaches target?
Usually one of two causes. The output the idle PID leaves sits inside the valve's spool overlap, so internal leakage paths stay open; the signed null-compensation offset found during commissioning closes them. Or the piston seal leaks, which no valve command can hold against — drift that follows the load's direction points at the seal, and that is a cylinder repair, not a tuning problem.

