Integral continuous domain transfer function is 1 / s, and the controller is a discrete system, so shall discrete continuous transfer function, of course, there are formulas calculate, for me this is not a good basis for people to understand strenuous, so use matlab to solve this problem.
Lcfun = tf ([0,1], [1,0]);% continuous function of 1 / s molecules [0,1], the denominator is a [1,0];
Ldfun = C2D (Lcfun,. 3-1E, 'tustin');% c2d continuous function is a discrete, 1e-3 signal sampling period of 10ms;
can view discrete function Ldfun in matlab = (0.0005 z + 0.0005) / (z-1); then convert discrete function written into the C language habit:
the Y (n-) / X-(n-) = (0.0005 + 0.0005 Z) / (Z-. 1);
decomposition at Serve:
zY (Z) = 0.0005zX (Z) + 0.0005X (Z ) + Y (z);
this equation is equivalent to:
the Y (n-) = 0.0005x (n-) + 0.0005x (. 1-n-) + Y (n--. 1);
NOTE: Y (n) is the current need to calculate the result value, x (n) is the current input value, (n-1) the input value at a time point x, y (n-1) is the result of a time value.
If the code is used to generate C matlab model, this process is not required, the direct use simulink discrete integrator module:
setting the gain module is 0.0005, while the maximum value is provided in accordance with the actual minimum value.
Finally, the whole project together and compiled into C code.