# Discretizing a PID controller

I am discretizing the PID equation so we have this equation

Now if we separate the integral term we get

Applying backward euler method

Now as we already have a differentiation , by applying backward euler method

and the end equation is something like this

I just want to ask if I did something mathematically wrong or did I miss a step ?

• Include $\small P(k)=K_p\:e(k)$ and it's fine. The bilinear transform normally gives more accurate results, though. – Chu Jul 4 '18 at 11:46
• Note that in this form the equation produces derivative spikes when setpoint changes. You need to account for it in software if your application allows highly variable setpoint. – Maple Jul 4 '18 at 20:27

Whenever you sample a signal using an ADC, you have to keep the Nyquist–Shannon sampling theorem in mind. If your system has a frequency content that extends beyond the Nyquist frequency ($f_N = \frac{1}{2T_s}$) then you will want to limit it first to avoid aliasing, by means of an anti-alias filter.