design a MPPT controller for PV system

Hello friends, I have designed an MPPT controller for PV system but I have a problem is that how to write Arduino UNO code for given algorithm in a picture. Please help me

Type all of that into a sketch. Then modify the syntax so that it makes a valid C++ function.

Or do a Google search for P&O Algorithm Arduino to see how other people have done it before you.

float calc_D_K(){
if(dP>0)if(dD>0)D_k=D_k2+ds;
else D_k=D_k2-ds;
else D_k=D_k2-ds;

else if(dD>0)D_k=D_k2-ds;
else D_k=D_k2+ds;
}

I have a problem, how to update the values of D(k-1) and D(k-2)

one2many:

float calc_D_K(){

if(dP>0)if(dD>0)D_k=D_k2+ds;
                                      else D_k=D_k2-ds;
                           else D_k=D_k2-ds;

else if(dD>0)D_k=D_k2-ds;
                      else D_k=D_k2+ds;
}

You accidentally repeated an else clause.

float calc_D_K()
{
  if (dP > 0)
  {
    if (dD > 0)
      D_k = D_k2 + ds;
    else
      D_k = D_k2 - ds;
  }
  else
  {
    if (dD > 0)
      D_k = D_k2 - ds;
    else
      D_k = D_k2 + ds;
  }
}

vipin_iitbhu:
I have a problem, how to update the values of D(k-1) and D(k-2)

After each iteration, set Dk-2 to Dk-1 and set Dk-1 to Dk.

I think he needs to use better descriptive names for the variables.. thats the advantage of the language being used over and above what looks like assembly code..also he needs to sample instantaneous solar power and
use that to complete the feedback loop..power=v*I, so 2 inputs needed, one for V and one for I, then multiply..

Maybe you could just steal this code:

after set Dk-2 to Dk-1 and set Dk-1 to Dk.
these are Dk-2 = Dk-1 =Dk.
and dD= Dk-2 - Dk-1 =0