Your model is already in discrete form but you need to introduce the $z$-operator to your equation. I perceive a missconception about the z-Transform. I hope the following lines will clarify that...
consider the following
The PI-controller can be represented as
Continous Time |
Frequency Domain |
$$u(t)=K_p\,e(t)+K_I\int_0^{\tau}e(\tau)d\tau$$ |
$$U(s)=(K_p+\frac{K_I}{s})\,E(s)$$ |
As probably you notice the proportional part is not a challenge if with want to discretize it, but the integral is! This term could be approached through Euler's forward or backwards method. Using the fordward Euler method leads to
$$u(k\,T) =\int_0^{k\,T}e(\tau)d\tau \approx \sum_{i=0}^{k-1}e(i\,T)\cdot T$$
where T is the sample period, i.e. the loop time in your microcontroller and the notation $u(k\,T)$ denote the value of the variable $u$ at time $k\,T$ with $k=0,1,2...$.
In the Z-Transform domain the operator $z$ is used to denote a forward shift by one sampling interval, e.g. $z\cdot\,x(k)$ is equal to $x(k+1)$. Analogously, the backward shift operator is denoted by $z^{-1}$, e.g. $z^{-1}\cdot x(k) = x(k-1)$.
In digital control systems one can approximate the $s$-Domain in $z$-Transform domain, e.g. using a euler backward integration we have
Integation in Discrete Time |
Integration in Z-Domain |
$$x(k+1)\approx x(k) + T\cdot u(k+1)$$ |
$$zX(z)=X(z)+T\,z\,U(z)\,\text{, reordering}\\ \frac{X(z)}{U(z)}=\frac{T\,z}{z-1}$$ |
Which if you noticed, is what you found in the "another" PI-Controller.
Now how the approximation is made? easy, we can recall the integration as $\dot{x}(t)=u(t)$ which in laplace is $\frac{X(s)}{U(s)}=\frac{1}{s}$. Then,
$$\frac{1}{s}\approx\frac{T\,z}{z-1}\,\text{, which leads to}\, s\approx \frac{z-1}{T\,z}$$
The advantage of the last equation is that we can have our Transfer function in Freq Domain and then replace the approximation of $s$, i.e. $C(z)\approx C(s)|_{s=\frac{z-1}{T\,z}}$