I have written a code for maximum power point tracking. The purpose was to create DLL file and use it in a circuit base simulation program. I used Microsoft visual c++ 2008 express and created that DLL file but I only get first value from the created array in C. I mean circuit based simulation program only get first value (although I see all array values after executing in "ChSciTE"). Do I need to store data somewhere? I am kind of rookie about writing C code? The code is below and the algorithm is attached as pdf. If anyone help me I would be so happy... I have been playing with this for 3 weeks...

```
#include <math.h>
main() {
static double y[21]; //controlled variable
static double m_A[21]; //modulation index
double dm_A=0.05; //small change for modulation index
int n;
double i_cell[]={4.65, 4.68, 4.7, 3.7, 2.1, 2.8,4.68, 4.65, 3.9, 3.7, 2.1, 2.8,4.68, 4.65, 3.9, 4.3, 2.1, 3.3, 4, 3.7,4.6};
for (n=1;n<=19;n++){
m_A[0]=0.75;
m_A[1]=0.65;
y[n-1]=i_cell[n-1]*m_A[n-1]; //estimated initial controlled variable
y[n]=i_cell[n]*m_A[n];
if (((m_A[n]>=m_A[n-1]) && (y[n]>=y[n-1])) || //algorithm for maximum power point tracking
(((m_A[n]<m_A[n-1]) && (y[n]<y[n-1]))))
m_A[n+1]=m_A[n]+dm_A; //increase modulation index
else //while one of them is increasing and the other one decreasing
m_A[n+1]=m_A[n]-dm_A; //decrease modulation index
printf("%f \n",m_A[n+1]); //display modulation indices
}
}
```

The code above for seeing results in "ChSciTE" program but the one I pasted below creates that DLL file to use in simulation.

```
#include <math.h>
__declspec(dllexport) void simuser (t, delt, in, out)
double t, delt;
double *in, *out;
{
static double y[21]; //controlled variable
static double m_A[21]; //modulation index
double i_cell=4.65; //estimated initial current value
int n;
for (n=1;n<=19;n++){
m_A[0]=0.75; //estimated initial current value
m_A[1]=0.65; //second estimated initial current value
y[n-1]=i_cell*m_A[0]; //estimated initial controlled variable
y[n]=in[0]*m_A[n]; //in[0] current input value comes from sim.
if (((m_A[n]>=m_A[n-1]) && (y[n]>=y[n-1])) ||
(((m_A[n]<m_A[n-1]) && (y[n]<y[n-1]))))
m_A[n+1]=m_A[n]+in[1]; //in[1] input from circuit based simulation
else //while one of them increases and the other one decreases
m_A[n+1]=m_A[n]-in[1]; //decrease modulation index
out[0]=m_A[n+1]; // out[0] is output which is transfered to the sim.
}
}
```

in[0]: first input comes from simulation program

in[1]: second input comes from simulation program

out[0]: output from C code or DLL file goes to simulation or taken by simulation program

Those values taken by simulation should be m_A[n+1]? As far as I understand which is an array. However only the first, I mean m_A[1+1] = m_A[2] has taken by simulation. How could I write the code all values from m_A[2], m_A[3]........m_A[20] can be taken by simulation or DLL sends those values to simulation program one by one for every 20 ms or different interval...