The PI controller can not run normally

,

I have a DPS - DAB matlab model, and I am realizing it in plecs, the parameters are same, but the PI controller’s output is always 0, so can you help me find the problems?

two models are attached.

best wishes

DAB-DPS.plecs (83.1 KB)

DAB-DPS.slx (30.7 KB)

The issue is due to a difference between MATLAB and C syntax in you C-Script. In Matlab “1/2” in an S-Function will return 0.5, but C will return 0 since it treats 1 and 2 as integers and not floating point values. Integer division will return an integer. So your C-Script logic check was faulty and the output would always be zero. Good practice is to add “.” after any number if you want it to be a float (e.g. p=1./2.:wink: or simply enter in the value as a float (p=0.5;).

See the following example: GDB online Debugger | Code, Compile, Run, Debug online C, C++

Attached is a revised version of your model with the C-Script problem fixed.

DAB-DPS_BL.plecs (77 KB)

Hey, I appreciate your answer, thanks.

And I have one little question.

In many discrete simulation systems, some use discrete PID and some use continuous PID,like the model above. In the continuous simulation system, discrete PID is also used.

And when I exchange the location of ZOH and PID(continue), the figure of scope1 hardly change, but the Input of PID(continue) is discrete, and it can work normally, so why?

And when I replace the PID(continue) with PID(discrete), the figure of scope1 is not as good as PID(continue).

So I would like to ask that, what’s the difference in the use of discrete PID and continuous PID? When should I choose PID(continue) or PID(discrete)?

best wishes

The discrete vs. continuous controls depend on the application. Once you move into hardware you have to pick an implementation.

A series combination of a ZOH and a Continuous PID controller is not equivalent to a Discrete PID Controller. You can look at the implementations of the two blocks to see the difference (See the “Continuous Time” and “Discrete Time” blocks in the library components).

With the Continuous PI implementation the block outputs and error integration be in continuous time. They will be changing every simulation time step, even if you have a ZOH block.

A Discrete PI implementation the block outputs and error integration will occur only at discrete instants that you specify with the “Sample Time” paraemter. I assume this is what you mean by “not as good”.