I have been implementing a control software where one of its core functionalities is the ability to synchronize with the three phase grid. Basically I need to implement some form of the phase locked loop (PLL) suitable for three phases. I have found that there are several posibilies how to do that. One of the simplest I have found is basically based on calculation of the time integral of the phase voltages. My first idea how to do that was to use the trapezoidal integration rule in recurent form

$$I(k) = I(k-1) + \frac{T}{2}\cdot\left[x(k-1) + x(k)\right].$$

I have implemented the above written difference equation in C and I have tried to pass a sinewave into it

    #define PI 3.14
    #define N 64

    float x, y;
    for(int k = 0; k < N; k++){
        x = sin(k*2*PI/N);
        y = integrate(1.0, x);

    float integrate(float T, float xk)
        static float intk_1 = 0; // I(k-1) 
        static float xk_1 = 0; // x(k-1)
        float intk = intk_1 + T/2*(xk_1 + xk);
        intk_1 = intk;
        xk_1 = xk;
        return intk;

Based on the outcomes of my experiment I have realized that in case the integration process starts from the point where the sinewave has zero value the resulted integral has large offset

enter image description here

In case the integration process starts from point where the sinewave has its positive maximum the integral has zero offset.

I need to have the integral with zero offset to be able to estimate the phase and frequency of the three phase grid. The obvious solution could be to somehow detect the positive maximum of the sinewaves and then start integration process. The problem is that the frequency of the three phase grid fluctuates in some tolerance band. Can anybody give me an advice how to do the integration process so that the resulted integrals have zero offsets?


1 Answer 1


I recommend a standard dq-PLL, check this reference https://vbn.aau.dk/ws/portalfiles/portal/273236528/PLL_Review_RSER.pdf

enter image description here

There are 2 required integrators. For algebraic loop reasons, the last integrator, the one that converts the angular frequency to the phase, should be a forward-Euler integrator. The integrator in the PI controller, can be a trapezoidal integrator if you want.

Edit : Ts = Sampling Period

enter image description here

  • $\begingroup$ Thank you again for your recommendation regarding the dq-pll. I have prepared a Scilab based simulation of this type of pll and based on that I have encountered that setting of the parameters of the PI controller i.e. $K_p, T_i$ based on desired roots of the characteristic polynomial of the closed loop results in good dynamic response only in case the input three phase voltages have unit amplitude. In case I substitute the unit amplitude by the real one let's say $\sqrt(2)\cdot 230$ the dynamic response becomes very poor. Do you think it is an inherent feature of that type of pll? $\endgroup$
    – Steve
    Commented May 21, 2021 at 13:40
  • $\begingroup$ You need to normalize the amplitude to 1 PU.. That was implied in the PDF I posted. $\endgroup$
    – Ben
    Commented May 21, 2021 at 13:56
  • 1
    $\begingroup$ If you use the full amplitude, that's like increasing the PI gain by a factor of 230 $\endgroup$
    – Ben
    Commented May 21, 2021 at 13:59
  • $\begingroup$ Thank you very much for clarification. I have just integrated that into my simulation and it works. $\endgroup$
    – Steve
    Commented May 21, 2021 at 14:10

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.