Calculates on this device. File exports run online.
PID Calculator
Type the gains of your PID controller (Kp, Ki, Kd, or Kc, Ti, Td) and the sample time. You get the controller output for a run of errors with its P, I and D parts at each step, the coefficients and difference equation to put in code, or the closed loop with your plant G(s) and its step response. To choose the gains for a process, use the PID tuning calculator.
Enter your values
Check these values
Your values are worked out in this browser. They are not sent to a server.
Your result will show here
Fill in the values, then choose Calculate.
Your result
How it was worked out
How to use the PID calculator
- Choose the form of your gains: parallel (Kp, Ki in 1/s, Kd in s) or standard (Kc, Ti and Td in seconds).
- For The output for a run of errors type the sample time and the errors e = set point − measurement, one for each step (or paste a column of numbers).
- For Discrete coefficients and code you get b0, b1, b2, a1, a2 and lines of code to copy.
- For The closed loop with a plant G(s) type the plant as a numerator and a denominator, such as 1 and (s + 1)(s + 2).
- The box under the result works the coefficients and the output (or the closed-loop figures) out again on the server.
The PID formulas
- Parallel form: u = Kp e + Ki ∫e dt + Kd de/dt. Standard form: u = Kc (e + (1/Ti) ∫e dt + Td de/dt), so Kp = Kc, Ki = Kc ÷ Ti and Kd = Kc × Td.
- The D part is filtered: Kd s ÷ (Tf s + 1), with Tf = Td ÷ 10 unless you type it.
- Backward Euler (the usual code): P = Kp e[k]; I = I + Ki Ts e[k]; D = (Tf D + Kd (e[k] − e[k−1])) ÷ (Tf + Ts).
- Tustin: the integral adds Ki Ts (e[k] + e[k−1]) ÷ 2 and the filter uses (2Tf − Ts) and (2Tf + Ts).
- Difference equation: u[k] = b0 e[k] + b1 e[k−1] + b2 e[k−2] − a1 u[k−1] − a2 u[k−2].
Worked example
Kp = 2, Ki = 1 per s, Kd = 0.5 s, Ts = 0.1 s, Tf = 0.025 s, backward Euler: b0 = 6.1, b1 = −10.42, b2 = 4.4, a1 = −1.2, a2 = 0.2. For the errors 1, 0.8, 0.5, 0.3, 0.1, 0 the first output is 6.1 (P 2 + I 0.1 + D 4) and the last is −0.3316.
The same gains on G(s) = 1 ÷ ((s + 1)(s + 2)) give a closed loop that rises from 10 % to 90 % in 4.81 s without overshoot and settles in 9.71 s.
Limits you should know
- The controller starts from rest and has no output limits: a real controller clamps its output and stops integrating while clamped (anti-windup).
- The closed loop is continuous and linear: the sample time, valve limits and noise are left out.