MATLAB: Are the discrete controllers not identical

discrete controldiscrete transfer functionsimulink

I am simulating a simple closed loop speed controller for a DC motor in Simulink.
I have a continuous PI controller working just fine.
I have then discretized the continuous controller and implemented it in two different, but equivalent ways, and it seems that the two discrete implementations provide different results, even though they are supposed to be equivalent.
Both discrete controllers are obtained by the same discretization method (Tustin), but one is implemented as a single discrete transfer function, whereas the other is implemented as a sum of the P and I parts individually.
The attached model contains all setup in the InitFcn callback, and illustrates both the continuous controller as well as both of the discrete controllers.
The "Decomposed Discrete Control Structure" tracks the continuous controller reasonably well, whereas the "Discrete Transfer Function Control Structure" has large deviations, and is even unstable for longer sample times. Conversely, the issue is resolved for faster sample times.

Best Answer

I figured it out, and the answer is of course that the two discrete implementations are in fact not equivalent, although the difference is subtle.
The "Discrete Transfer Function Control Structure" is implemented as a purely discrete controller since all control processing is handled by the discrete transfer function, including sampling of the error signal.
The "Decomposed Discrete Control Structure" is however in fact a hybrid controller: Since there is no collective sampling of the error signal, the porportional branch is maintained as a continuous contribution to the control action, and only the integral contribution is discretized.
In order to render both discrete controllers equivalent, a sampling of the error signal must be introduced in the "Decomposed Discrete Control Structure", prior to calculating either P or I control actions. This could be done e.g. by a "zoh" block right after calculating the error.