0
$\begingroup$

I have a discreate PI controller implemented in stm32 MCU, it has the following form: $$ PI=K_p\cdot[r(t_i)-y(t_i)] + (K_I)\cdot\sum_{n=0}^{i}[r(t_n)-y(t_n)]\cdot\Delta t $$ where

  • $r(t_i)$ is the target (or input) value,
  • $y(t_i)$ is the output value and
  • $\Delta t $ is the sampling time.

I use the $\sum$ function to implement the integral function while the error term is $[r(t_i)-y(t_i)]$.

I need to simulate this PI controller in MATHLAB Simulink.

Besides, I have found another form of the PI controller: it doesn't has the sum equation, and but has the following structure: $$ PI=K_p\cdot[r(t_i)-y(t_i)]+ (K_I)[r(t_i)-y(t_i)]\cdot\Delta t $$ For the integral term of this PI controller, the $Z$-transform is $$ K_I(z)=e(z)\cdot T\cdot\frac{ z}{z-1}. $$

This form does not include the sum term.

My question is: if I use the sum equation to sum the error term, how should I represent the PI controller correctly in the $Z$-transform domain?

$\endgroup$
1
  • $\begingroup$ I hope you are not planning to sum the entire history for each computation cycle! $\endgroup$
    – AJN
    Commented Jun 15, 2023 at 12:35

1 Answer 1

1
$\begingroup$

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

  • $e(t) := r(t)-y(t)$

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}}$

$\endgroup$
1
  • $\begingroup$ Thanks a lot, you explained it very well. $\endgroup$
    – zymaster
    Commented Jun 16, 2023 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.