My embedded function is not updating the value in the next step calculated from previous step

Asked by KHALID SAKIB on 22 Aug 2012
Latest activity Commented on by KHALID SAKIB on 28 Aug 2012

Hi,

I Have coded Matlab Embedded function to work my solar system at the MPP (incremental conductance). So i took the previous i, V and P and calculate what shouuld be duty cycle. And Tried to reach to the exact duty cycle for my MPP by continuously calculating the duty cycle from the previous step. But it did not take the previous step value rather always took initial D as 0 in each step. The code is:

```function y = fcn(v_1,i_1,v,i,D)
```
```d=.01;
deli=i-i_1;
delv=v-v_1;
if delv==0
if deli==0, m=D;
else
if deli>0, m=D+d;
else
m=D-d;
end
end
elseif ((deli/delv)+(i/v))<.01 && ((deli/delv)+(i/v))>-.01 , m=D;
else
if ((deli/delv)+(i/v))>.01, m=D+d;
```
```        else
m=D-d;
end
end
y=m;```
```end
```

2 Comments

Kaustubha Govind on 22 Aug 2012

What is D? An input or a parameter? Who updates D?

Walter Roberson on 22 Aug 2012

Khalid wrote,

Hi Kaustubha,

Thanks for your response.

D is the duty cycle of the boost converter. It is an input as well as the output of the function(by unit delay). The embedded function is supposed to update D and reach to the required D to make the circuit to work in Maximum power point by each iteration as the time goes on.

*You can download the file:* http://knsakib.freehostia.com/solarcell_6_series_parallal_mpp.zip

The link to see the the system in JPEG: http://knsakib.freehostia.com/The%20solar%20cell%20system.jpg

The link to see inside Boost controller: http://knsakib.freehostia.com/inside%20the%20boost%20converter%20control%20%28orange%29.jpg

The matlab embedded block: http://knsakib.freehostia.com/Maximum%20power%20point%20function%20%28inside%20the%20MPPT%29.jpg

Please to go to the link or download the file copy paste those links on your browser otherwise its not working :(

6 Answers

Answer by Kaustubha Govind on 23 Aug 2012

From looking at your snapshots, the problem you described "it did not take the previous step value rather always took initial D as 0 in each step" only makes sense if "y" is calculated as 0 in every time step. I would recommend connecting a scope block at "y" and also at the output of the Unit Delay block that produces "D", and make sure both y and D are non-zero after the initial step.

0 Comments

Answer by Mariano Lizarraga on 25 Aug 2012

I was trying to download your model to help you debug this but I only get the landing homepage of "freehostia". Here are a few things I would suggest you do:

1.- Just output a counter. Comment all your embedded matlab code and just do something like

```y =  D + 1;
```

and make sure your time delay in the feedback path of D has its initial condition to either 0 or the value you want the counter to start with. If you see that the output is indeed an ever increasing counter like here: http://skit.ch/nwnx then it is a good indication that something is not working as you expect on your embedded MATLAB function. If it is not, then something is going on with your time dealy block.

2.- Put your embedded MATLAB function in a set of known states and make sure you get the output you expect. That is, disconnect the feedback, put a known value into D and some conditions in v and i and put a scope after the time delay to make sure you are getting what you are expecting.

Hope this helps

---

Mariano

0 Comments

Answer by KHALID SAKIB on 23 Aug 2012

Hi,

How I make sure y/D will not be zero. In fact, if I see the program execute step by step I see at the very first step y=.01 so in the next step initial value of D should be .01 if I am not wrong. But its not taking that value. it still takes D as 0. Is there any way? May be something needs to be defined other way... not sure.

1 Comment

Kaustubha Govind on 24 Aug 2012

If you connect a Scope right after the Unit Delay (before the input to the MATLAB Function block), do you see D taking non-zero values?

Answer by KHALID SAKIB on 24 Aug 2012

When I add a scope as you told, during the program execution sometimes it shows other values, some sometimes it shows 0. But if I see the program execute step by step, at step#1 the output y=.01. So, at step#2 the input D (which is output y) should be .01 But the scope (placed as you told) shows 0 and also in step#2 the program execute taking D=0. Even I placed another scope just at the output y. Its not even showing that value (.01) but 0.

2 Comments

Kaustubha Govind on 27 Aug 2012

Khalid: At step#2, D will indeed be 0, because it is the value of y at step#1 (note that D is the output of a Delay block). D should attain the value of 0.01 at step#3. Is this what you see?

KHALID SAKIB on 28 Aug 2012

Yes D should be .01 at step#3. But it is not taking that value.

Answer by KHALID SAKIB on 26 Aug 2012

instead of clicking you can download it if you copy paste the link in the browser.

1 Comment

Mariano Lizarraga on 27 Aug 2012

Khlaid, I've donwloaded your model and run it. The variable D is indeed changing, I don't see it to be perpetually identical to zero as you describe in your problem. I modified the embedded MATLAB code to print the value of D every time it runs, and it is indeed changing. It stays at the same value for multiple sample times but eventually changes and takes other values different than zero, here is a screenshot: https://skitch.com/malife/eq9ri/windows-xp-pro.

To make sure that it was indeed taking the input value I further modified the model and the embedded MATLAB function to just passthrough D as a new output D1, and once in the output plot it against input D, they are indeed identical, thus completely showing that D is indeed changing and being used inside the embedded MATLAB function. You can look at what I mean in this image: https://skitch.com/malife/eq98j/windows-xp-pro

Answer by KHALID SAKIB on 27 Aug 2012

Hi Mariano, Thank You so much for your analysis and suggestion. Yes, its changing and I also mentioned it in my previous comments/paragraph. But I think this change is not coming from my function (rather from internal circuitry). Because, according to my function it should be changed after every iteration/step based on the condition (of v, i, v_1, i_1). That's why I mentioned if you see step by step (click left "-" of each line and make red circle and press run and F10 to see step by step) it is not taking the changed values of D calculated from previous step (suppose step 1,2 and 3). If my function works correctly that should be changed. And also I need that to changed, because the system should reached the efficiency point quickly otherwise till to reach that maximum power point the system causes loss. Why it is not changing according to my function? not sure. It should not be stable for couple of steps. May be some variable needs to defined in different way.

Contact us