# PLC ST programming

I have a mathematical model of two dynamic systems which I need to implement in PLC, but I don't know how to implement differential equations in structured text language. Any suggestions on that will be helpful.

I have been thinking of converting differential equations to difference equation, but I don't have any idea how to do this.

$$\ddot{\Theta}=\dfrac{1-K_d\cdot\dot{\Theta}}{J} \tag {1}$$

$$\dot{i} = \dfrac{1}{L}(V-K_g k_f \dot{\Theta}-R i) \tag {2}$$

theta_dot_dot = 1/J*(1 - Kd*(theta_dot)) -------> Equation 1
i_dot = 1/L*(V - (Kg)(kf)(theta_dot) - R*i) --------> Equation 2

• Post the equation to be converted. (Hit the edit link below your question.) It might not be possible. What brand and model of PLC too. Commented Jan 28, 2020 at 18:20
• There are some things that PLC's are not really geared towards, such as multi-dimensional systems modeling. The best thing to do is to use something geared towards running this in C or Matlab and using a connector (some Fieldbus implementation) to tell the PLC what to do with the physical IO. Commented Jan 28, 2020 at 18:35
• Almost the same as in C, even more similar is turbo pascal. There is also a PLC coder option in MATLAB. Show the equations of your system first, then make express them in Z-transform,... Commented Jan 28, 2020 at 20:33
• @Transistor Im using OpenPLC and I will have to use that model in structured text language. Commented Jan 28, 2020 at 21:28
• @RonBeyer I have modelled the system with PID controller in Simulink and it is working there. But I don't know how to write the equivalent one in structured text. Commented Jan 28, 2020 at 21:30

$$\ddot{\Theta}=\dfrac{1-K_d\cdot\dot{\Theta}}{J}$$
$$J\ddot{\Theta}+K_d\cdot\dot{\Theta}-1=0$$ $$\ddot{\Theta}+\dfrac{K_d}{J}\cdot\dot{\Theta}-\dfrac{1}{J}=0$$ Discriminant : $$\ \dfrac{K_d^2}{J^2} -\dfrac{4}{J}\$$ is it positive?
$$\dot{i} = \dfrac{1}{L}(V-K_g k_f \dot{\Theta}-R i)$$
$$i = \dfrac{1}{L}\int(V-K_g k_f \dot{\Theta}-R i)dt$$ You solve the second equation with trapz rule.
$$Sample_{act}=\dfrac{1}{L}(V-K_g k_f \dot{\Theta}-R i)$$ $$i = i+\dfrac{1}{2}\cdot T_{sample}\cdot (Sample_{act}+Sample_{old})$$ $$Sample_{old}=Sample_{act}$$