Digital PID Controller
Discretization methods, difference equation implementation.
The PID controller is the most widely used controller in industrial automation. In modern digital implementations, the continuous PID algorithm must be converted into a discrete-time difference equation that a microcontroller or DSP can execute. This process, called discretization, involves approximating the integral and derivative terms using numerical methods, and the choice of method directly affects closed-loop stability and performance.
Core Concept of Digital PID Controller
The continuous-time PID controller is expressed in the Laplace domain as C(s) = Kp + Ki/s + Kd·s, or equivalently in time domain as u(t) = Kp·e(t) + Ki·∫e(τ)dτ + Kd·de/dt. To implement this digitally, the integral and derivative operations must be approximated by discrete numerical methods. The result is a difference equation that computes the controller output u[n] at each sampling instant using current and past values of the error e[n].
The most basic approach is the forward Euler method, which approximates the integral as a sum: ∫e dt ≈ T·Σe[k], and the derivative as a first difference: de/dt ≈ (e[n] - e[n-1])/T, where T is the sampling period. This corresponds to substituting s = (z-1)/T in C(s). The digital PID difference equation becomes: u[n] = Kp·e[n] + Ki·T·Σe[k] + (Kd/T)·(e[n] - e[n-1]).
A more practical form is the incremental (velocity) form which computes the change in controller output: Δu[n] = u[n] - u[n-1] = Kp·(e[n]-e[n-1]) + Ki·T·e[n] + (Kd/T)·(e[n] - 2e[n-1] + e[n-2]). This form avoids integral windup problems and is preferred in implementation since accumulated sum errors are avoided.
Discretization Methods
Three main methods are used to discretize continuous controllers. The forward Euler method (s → (z-1)/T) is simple but can produce an unstable digital controller even from a stable continuous one, because the unit circle region maps only partially into the stable z-plane region. The backward Euler method (s → (z-1)/(Tz)) is more conservative and always maps stable s-plane poles to inside the unit circle, making it safer.
The Tustin method (also called bilinear transformation) uses the substitution s = 2(z-1)/(T(z+1)). This method provides the best frequency-domain match between the continuous and discrete controllers. It maps the entire left half s-plane into the unit circle interior, preserving stability. With frequency prewarping (adjusting for a specific critical frequency), the Tustin method gives nearly exact frequency response matching, making it the preferred choice for control implementation.
Practical Understanding
In embedded digital control, the PID algorithm runs in a periodic interrupt service routine triggered every T seconds. The sequence is: (1) read sensor (A/D conversion), (2) compute error e[n] = r[n] - y[n], (3) compute u[n] using the difference equation, (4) output u[n] (D/A conversion or PWM). The choice of T affects both the approximation accuracy and computational load.
Practical issues include derivative kick, which occurs when a step change in the setpoint causes a large spike in the derivative term. This is mitigated by computing the derivative on the measured output y[n] rather than the error e[n]. Another issue is integral windup, where the integral term accumulates to a large value during saturation. Anti-windup techniques limit or reset the integral when the output is saturated.
Solved Numerical Example
A continuous PID controller has parameters Kp = 2, Ki = 1, Kd = 0.5. Discretize using the forward Euler method with T = 0.1 s to find the digital PID difference equation and its z-domain transfer function.
Given:
Kp = 2, Ki = 1, Kd = 0.5, T = 0.1 s
Method: Forward Euler → s = (z-1)/T
Why this formula applies:
Forward Euler substitution converts continuous C(s) to discrete C(z)
Formula:
C(s) = Kp + Ki/s + Kd·s
Substitute s = (z-1)/T:
Substitution:
C(z) = 2 + 1/[(z-1)/0.1] + 0.5·(z-1)/0.1
= 2 + 0.1/(z-1) + 5(z-1)/1
Calculation:
C(z) = 2 + 0.1/(z-1) + 5(z-1)
Multiply through by (z-1):
Numerator = 2(z-1) + 0.1 + 5(z-1)²
= 5z² - 10z + 5 + 2z - 2 + 0.1
= 5z² - 8z + 3.1
Denominator = z - 1
Final Answer:
C(z) = (5z² - 8z + 3.1) / (z - 1)
Difference equation: u[n] = u[n-1] + 5·e[n] - 8·e[n-1] + 3.1·e[n-2]
(derived from C(z)·E(z) = U(z) rearranged)Exam Tip: For GATE digital PID questions, remember the three substitutions: Forward Euler: s = (z-1)/T; Backward Euler: s = (z-1)/(Tz); Tustin: s = 2(z-1)/(T(z+1)). Tustin is most accurate and stability-preserving. The forward Euler integral term becomes T·z/(z-1) in z-domain, and the derivative becomes (z-1)/(Tz).
Loading lab...
Quick Revision
- Continuous PID: C(s) = Kp + Ki/s + Kd·s. Discretization converts integral and derivative to numerical approximations.
- Forward Euler: s = (z-1)/T. Simple, but may cause instability. Integral becomes T/(z-1), derivative becomes (z-1)/T.
- Backward Euler: s = (z-1)/(Tz). Stable but introduces phase distortion.
- Tustin (bilinear): s = 2(z-1)/(T(z+1)). Best method: maps entire stable s-plane to unit circle interior.
- Position form: u[n] = Kp·e[n] + Ki·T·Σe + Kd/T·(e[n]-e[n-1]). Velocity form avoids windup accumulation.
- Practical issues: derivative kick (compute derivative on output, not error) and integral windup (anti-windup clamping).
- Exam trap: smaller T is not always better; it increases computational noise sensitivity in the derivative term.
Digital PID Controller
Test your ability to discretize a continuous PID controller and implement it as a difference equation for digital control.
Q1.Using the backward Euler method (s = (1 - z^(-1))/T) to discretize the integrator 1/s, which discrete-time expression is obtained?
Related Articles
PID Controller
Combined P+I+D action, tuning methods.
4 min read
P Controller
Proportional control, gain adjustment, offset error.
6 min read
PI Controller
Proportional-integral, zero steady state error.
6 min read
PD Controller
Proportional-derivative, anticipatory action, damping.
5 min read
Sampled Data Systems
Ideal sampler, zero order hold, pulse transfer function.
9 min read