Skip to main content
engineering

Discrete PID Controller Calculator

Convert continuous PID gains into a digital difference equation at sample period Ts: velocity and positional forms, backward Euler or Tustin, Nyquist check

Reviewed by Christopher FloiedPublished Updated

This free online discrete pid controller calculator provides instant results with no signup required. All calculations run directly in your browser — your data is never sent to a server. Supports both metric (SI) and imperial units with built-in unit selection dropdowns on every input field, so you can work in whatever units your problem provides. Designed for engineering students and professionals working through coursework, design projects, or quick reference calculations.

Discrete PID Controller Calculator

Converts a continuous parallel PID, C(s) = Kp + Ki/s + Kd·s, into a difference equation at sample period Ts. Gains are in the parallel (independent-gain) convention, not the standard/ISA Kc(1 + 1/(Ti·s) + Td·s) form.

q₀ (same units as Kp)
7.1
q₁ (same units as Kp)
-12
q₂ (same units as Kp)
5
Δu per sample at constant unit error (units of Kp)
0.1 = Ki·Ts
Sample rate 1/Ts
10 Hz
Nyquist ω_N = π/Ts
31.4159 rad/s
Nyquist f_N = 1/(2Ts)
5 Hz
Ti = Kp/Ki · Td = Kd/Kp
2 s · 0.25 s
Sampling marginal — Ts is coarse
Td/Ts = 2.50 (dimensionless); Ti/Ts = 20.00 (dimensionless). Ts is only 2–5× shorter than the shortest controller time constant. The backward difference is a poor derivative here — expect noticeable phase lag, derivative kick and noise amplification. Reduce Ts or add a derivative filter.
Velocity (incremental) form — Backward Euler
u[k] = u[k−1] + 7.1·e[k] − 12·e[k−1] + 5·e[k−2]

Denominator is (1 − z⁻¹), so the recurrence feeds back u[k−1]. The velocity form has no integral accumulator, so it cannot wind up — but it does require the actuator to hold its last value.

Positional (absolute) form — Backward Euler
u[k] = 2·e[k] + I[k] + D[k] | I-step 0.1 | D-gain 5
Backward rectangular: I[k] = I[k−1] + Ki·Ts·e[k]
Backward difference: D[k] = (Kd/Ts)·(e[k] − e[k−1])

Per-sample gains: proportional 2, integral step 0.1, derivative 5 (all in the same units as Kp). The positional form needs explicit anti-windup clamping on I[k].

Diverges on this plant at Ts = 0.1 s: Tustin (bilinear). The y-axis is scaled to the responses that converge, so an unstable trace runs off the top or bottom of the frame instead of flattening the others; samples beyond ±1000 are dropped rather than drawn as ±∞.

Closed-loop unit-step response, y[k] (dimensionless output/setpoint ratio)

ZOH-discretised first-order plant G(s) = 1/(1s + 1), unit step setpoint, sampled every 0.1 s.

Tip: hover to read values, click to pin a point for export

Coefficient comparison — all three discretisations

Methodu historyq₀q₁q₂ΣqΔu/sample at e = 1
Backward Euleru[k−1]7.1-1250.10.1
Trapezoid I + Euler Du[k−1]7.05-11.9550.10.1
Tustin (bilinear)u[k−2]12.05-19.98.050.20.1

All q values are in the same units as Kp (controller output per unit error). Σq divided by the u-history lag equals Ki·Ts for every method — at a constant error the controller output ramps at exactly the continuous integral rate, which is the arithmetic check that the discretisation is correct.

How to Use This Calculator

1

Enter your input values

Fill in all required input fields for the Discrete PID Controller Calculator. Most fields include unit selectors so you can work in your preferred unit system — metric or imperial, whichever matches your problem.

2

Review your inputs

Double-check that all values are correct and that you have selected the right units for each field. Incorrect units are the most common source of calculation errors and can produce results that are off by factors of 2, 10, or more.

3

Read the results

The Discrete PID Controller Calculator instantly computes the output and displays results with units clearly labeled. All calculations happen in your browser — no loading time and no data sent to a server.

4

Explore parameter sensitivity

Try adjusting individual input values to see how the output changes. This is a quick and effective way to develop intuition about how different parameters influence the result and to identify which inputs have the largest effect.

Formula Reference

Continuous PID and the Two Discretisation Substitutions

C(s) = Kp + Ki/s + Kd·s | backward Euler (backward-rectangular): s → (1 − z⁻¹)/Ts | Tustin / bilinear (trapezoidal): s → (2/Ts)·(1 − z⁻¹)/(1 + z⁻¹) | z⁻¹ = one-sample delay

Variables: C(s) = controller transfer function (controller output units per error unit); s = Laplace variable (rad/s); Kp = proportional gain (output unit per error unit); Ki = integral gain (output unit per error unit per second); Kd = derivative gain (output unit · second per error unit); Ts = sample period (s); z⁻¹ = unit delay operator, i.e. one sample of Ts seconds (dimensionless). Gains are the PARALLEL (independent-gain) convention; to convert from the standard/ISA form Kc·(1 + 1/(Ti·s) + Td·s) use Kp = Kc, Ki = Kc/Ti (1/s scaling) and Kd = Kc·Td (s scaling). Source: Franklin, Powell & Workman, Digital Control of Dynamic Systems, 3rd ed., Ch. 4 (Discrete Equivalents / design by emulation — backward-rectangular and bilinear rules); Åström & Wittenmark, Computer-Controlled Systems, 3rd ed., Ch. 8 (PID control, discretisation of the PID algorithm).

Velocity (Incremental) Form — Backward Euler

u[k] = u[k−1] + q₀·e[k] + q₁·e[k−1] + q₂·e[k−2] | q₀ = Kp + Ki·Ts + Kd/Ts | q₁ = −Kp − 2·Kd/Ts | q₂ = Kd/Ts

Variables: u[k] = controller output at sample k (controller output units); e[k] = r[k] − y[k], the control error at sample k (error units); k = sample index (dimensionless integer); q₀, q₁, q₂ = velocity-form coefficients, all in the same units as Kp (output unit per error unit); Kp, Ki, Kd, Ts as above. Applying s → (1 − z⁻¹)/Ts to C(s) gives the common denominator (1 − z⁻¹), which is why the recurrence feeds back u[k−1]. Worked check with Kp = 2, Ki = 1, Kd = 0.5, Ts = 0.1 s: q₀ = 2 + 0.1 + 5 = 7.1, q₁ = −2 − 10 = −12, q₂ = 5. The velocity form carries no integral accumulator, so it cannot integrator-wind-up, but it assumes the actuator holds its previous value. Source: Åström & Wittenmark, Computer-Controlled Systems, 3rd ed., Ch. 8 (incremental / velocity PID algorithm); Franklin, Powell & Workman, Digital Control of Dynamic Systems, 3rd ed., Ch. 4.

Velocity Form — Tustin (Full Bilinear)

u[k] = u[k−2] + q₀·e[k] + q₁·e[k−1] + q₂·e[k−2] | q₀ = Kp + Ki·Ts/2 + 2·Kd/Ts | q₁ = Ki·Ts − 4·Kd/Ts | q₂ = −Kp + Ki·Ts/2 + 2·Kd/Ts

Variables: u[k] = controller output at sample k (controller output units); e[k] = control error (error units); q₀, q₁, q₂ = velocity-form coefficients in the same units as Kp; Kp, Ki, Kd, Ts as above. Applying the bilinear rule to BOTH the integral and derivative terms produces the common denominator (1 − z⁻¹)(1 + z⁻¹) = 1 − z⁻², so the recurrence feeds back u[k−2] and NOT u[k−1] — substituting u[k−1] here is a common and silent error. The extra factor also places a controller pole at z = −1, i.e. exactly at the Nyquist frequency, which can ring at a period of 2·Ts. Worked check with Kp = 2, Ki = 1, Kd = 0.5, Ts = 0.1 s: q₀ = 12.05, q₁ = −19.9, q₂ = 8.05. Source: Franklin, Powell & Workman, Digital Control of Dynamic Systems, 3rd ed., Ch. 4 (bilinear/Tustin equivalent); Ogata, Discrete-Time Control Systems, 2nd ed., Ch. 4 (bilinear transformation).

Velocity Form — Trapezoidal Integral with Backward-Difference Derivative

u[k] = u[k−1] + q₀·e[k] + q₁·e[k−1] + q₂·e[k−2] | q₀ = Kp + Ki·Ts/2 + Kd/Ts | q₁ = −Kp + Ki·Ts/2 − 2·Kd/Ts | q₂ = Kd/Ts

Variables: u[k] = controller output at sample k (controller output units); e[k] = control error (error units); q₀, q₁, q₂ = velocity-form coefficients in the same units as Kp; Kp, Ki, Kd, Ts as above. This mixed rule integrates with the trapezoidal (Tustin) rule but differentiates with the plain backward difference, so the denominator stays (1 − z⁻¹) — it keeps the compact u[k−1] recurrence and avoids the z = −1 mode of the full bilinear form, which is why most embedded PID libraries ship this variant. Worked check with Kp = 2, Ki = 1, Kd = 0.5, Ts = 0.1 s: q₀ = 7.05, q₁ = −11.95, q₂ = 5. Source: Åström & Hägglund, PID Controllers: Theory, Design, and Tuning, 2nd ed., Ch. 3 (digital implementation — approximating the integral and derivative terms); Franklin, Powell & Workman, Digital Control of Dynamic Systems, 3rd ed., Ch. 4.

Positional (Absolute) Form

u[k] = Kp·e[k] + I[k] + D[k] | backward rectangular: I[k] = I[k−1] + Ki·Ts·e[k] | trapezoidal: I[k] = I[k−1] + (Ki·Ts/2)·(e[k] + e[k−1]) | backward difference: D[k] = (Kd/Ts)·(e[k] − e[k−1]) | bilinear: D[k] = −D[k−1] + (2·Kd/Ts)·(e[k] − e[k−1])

Variables: u[k] = absolute controller output at sample k (controller output units); I[k] = integral state at sample k (controller output units); D[k] = derivative contribution at sample k (controller output units); e[k] = control error (error units); Kp, Ki, Kd, Ts as above. Per-sample gains: Kp (output per error unit), Ki·Ts or Ki·Ts/2 (integral increment per unit error per sample), Kd/Ts or 2·Kd/Ts (derivative gain per unit error). Unlike the velocity form, the positional form holds an explicit accumulator I[k] and therefore REQUIRES anti-windup clamping or back-calculation whenever the actuator saturates. Source: Åström & Hägglund, PID Controllers: Theory, Design, and Tuning, 2nd ed., Ch. 3 (position and velocity algorithms, integrator windup).

Nyquist Frequency and Sampling-Adequacy Check

f_s = 1/Ts | f_N = f_s/2 = 1/(2·Ts) | ω_N = π/Ts | Ti = Kp/Ki | Td = Kd/Kp | design guidance: Td/Ts ≥ 10 and Ti/Ts ≥ 10 | arithmetic check: (q₀ + q₁ + q₂)/L = Ki·Ts

Variables: f_s = sample rate (Hz); Ts = sample period (s); f_N = Nyquist (folding) frequency (Hz); ω_N = Nyquist angular frequency (rad/s) — note ω_N = π/Ts is in rad/s, while f_N = 1/(2·Ts) is in Hz, a factor of 2π apart; Ti = integral (reset) time (s); Td = derivative (rate) time (s); Td/Ts and Ti/Ts = dimensionless sampling ratios; L = the recurrence's u-history lag (1 for backward Euler and the trapezoidal/backward-difference mix, 2 for full bilinear, dimensionless). Nothing above the Nyquist frequency can be represented — signal content beyond f_N aliases into the loop, so an analogue anti-alias filter below f_N is mandatory. The backward difference (e[k] − e[k−1])/Ts only approximates de/dt while Ts ≪ Td; at Td/Ts below about 5 the derivative term becomes a large, noisy, badly phased finite difference, and below about 2 the discretised controller no longer represents the continuous design. The last identity is the arithmetic self-check: at a constant error the P and D contributions cancel over one denominator period, so the output must ramp at exactly the continuous integral rate Ki·Ts per sample. Source: Oppenheim & Schafer, Discrete-Time Signal Processing, 3rd ed., Ch. 4 (sampling theorem, folding frequency); Åström & Wittenmark, Computer-Controlled Systems, 3rd ed., Ch. 8 (choice of sampling period for PID, anti-aliasing); Franklin, Powell & Workman, Digital Control of Dynamic Systems, 3rd ed., Ch. 11 (sample-rate selection).

When to Use This Calculator

  • Use the Discrete PID Controller Calculator when solving homework or exam problems that require quick numerical verification of your hand calculations — instant feedback helps identify arithmetic errors before they propagate.
  • Use it during the early design phase to rapidly iterate on parameters and narrow down feasible configurations before committing time to detailed finite element simulations or full design packages.
  • Use it when reviewing a colleague's calculation or checking a vendor's data sheet for plausibility — a quick sanity check can prevent costly downstream errors.
  • Use it to generate reference data for a technical report or presentation without manual computation, ensuring consistent, reproducible numbers throughout the document.
  • Use it in the field when a quick estimate is needed and a full engineering software package is not available.

About This Calculator

The Discrete PID Controller Calculator is a precision engineering calculation tool designed for students, engineers, and technical professionals. Convert continuous PID gains into a digital difference equation at sample period Ts: velocity and positional forms, backward Euler or Tustin, Nyquist check All calculations are performed using established engineering formulas from the relevant scientific literature and standards. Inputs support both metric (SI) and imperial unit systems, with unit conversion handled automatically — simply select your preferred unit from the dropdown next to each field. Results are computed instantly in the browser without sending data to a server, ensuring both speed and privacy. This calculator is intended as a supplementary tool for learning and design exploration; always verify results against authoritative references for safety-critical applications.

The Theory Behind It

A digital PID controller runs on a sampled system, so the continuous integral and derivative terms must be replaced by difference approximations at a sample period Ts. Two choices define the resulting algorithm. The first is the discretisation rule: backward Euler substitutes s → (1 − z⁻¹)/Ts, which is simple and unconditionally stable in mapping the left half-plane inside the unit circle; Tustin (bilinear) substitutes s → (2/Ts)·(1 − z⁻¹)/(1 + z⁻¹), which preserves frequency response more faithfully at the cost of frequency warping near Nyquist. The second is the FORM. The positional form computes the absolute output u[k] from the accumulated error sum, which requires explicit anti-windup handling and bumps the output if gains change online. The velocity (incremental) form computes the CHANGE in output, u[k] = u[k−1] + q0·e[k] + q1·e[k−1] + q2·e[k−2], which is what most industrial controllers implement because integrator windup is handled naturally by clamping the actuator and gain changes are bumpless. For backward Euler the velocity coefficients are exactly q0 = Kp + Ki·Ts + Kd/Ts, q1 = −Kp − 2·Kd/Ts, and q2 = Kd/Ts. Sample period selection matters as much as the gains. The Nyquist angular frequency is π/Ts; any loop dynamics above it are aliased and invisible to the controller. A common rule is to sample 10 to 20 times faster than the closed-loop bandwidth, and to keep Ts well below the derivative time constant Td, since the derivative term differentiates over a single sample interval and becomes noise-dominated as Ts grows relative to Td.

Real-World Applications

  • Porting an analogue loop to a microcontroller: convert existing Kp, Ki, Kd values into difference-equation coefficients that can be typed straight into firmware.
  • PLC and motion-controller implementation: most industrial platforms expect the velocity form, and this gives the three coefficients directly.
  • Choosing a sample rate: check the Nyquist frequency against the loop bandwidth before committing to a scan time.
  • Diagnosing a digital loop that behaves worse than its analogue prototype: usually either the sample period is too coarse relative to the derivative term, or the discretisation rule differs from the one assumed during tuning.
  • Comparing Euler against Tustin on the same gains, to see whether the extra fidelity of the bilinear transform justifies its slightly more complex coefficients.

Frequently Asked Questions

Should I use the positional or the velocity form?

Velocity, in almost all practical cases. It computes the change in output rather than the absolute value, so integrator windup is handled by simply clamping the actuator, and changing gains while running does not produce a step in the output. The positional form needs explicit anti-windup logic and bumpless-transfer handling. The positional form is easier to reason about on paper, which is why textbooks introduce it first.

Backward Euler or Tustin?

Backward Euler is simpler and maps the entire stable s-plane into the unit circle, so a stable continuous design cannot become unstable through discretisation. Tustin preserves the frequency response more accurately, particularly near the crossover, but warps frequencies as they approach Nyquist. If your sample rate is comfortably fast relative to the loop bandwidth the two are nearly indistinguishable; if it is marginal, Tustin usually behaves better.

How fast should I sample?

A widely used guideline is 10 to 20 times the closed-loop bandwidth. Below about 10 the discrete loop's phase lag from the sample-and-hold starts eroding the phase margin the continuous design assumed. Also check Ts against the derivative time constant: if Ts approaches Td the derivative term is differentiating over roughly its own time constant and will be dominated by measurement noise.

Why does my derivative term make the output jump?

Two usual causes. First, derivative on error responds to setpoint steps with an impulse; deriving on measurement instead removes that. Second, the derivative gain Kd/Ts grows as the sample period shrinks, so a fast loop amplifies quantisation and sensor noise. Practical implementations filter the derivative, typically with a first-order filter at 5 to 20 times the derivative corner.

What is the Nyquist frequency here and why does it appear?

It is π/Ts in rad/s, or 1/(2·Ts) in Hz — the highest frequency a sampler can represent. Anything above it aliases down and appears as a lower-frequency disturbance the controller cannot distinguish from real signal. It is shown because it is the hard ceiling on what any amount of tuning can control.

Common Mistakes & Tips

  • !Using the continuous gains unchanged and assuming discretisation is free; the derivative term in particular scales as Kd/Ts.
  • !Sampling too slowly, so the sample-and-hold phase lag eats the phase margin the continuous design relied on.
  • !Implementing the positional form without anti-windup, then blaming the tuning when the actuator saturates.
  • !Taking the derivative of error rather than of measurement, which produces a derivative kick on every setpoint change.
  • !Mixing gain conventions: Kp/Ki/Kd (parallel) and Kp/Ti/Td (standard) are not interchangeable, and Ki = Kp/Ti.

Related Concepts

Related Calculators

Embed this calculator on your site

Paste this snippet into your blog, course page, or documentation to drop a live, interactive Discrete PID Controller Calculator into your page.

Free to embed — includes a link back to MegaCalc.