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;
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.
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
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.
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.
instead of clicking you can download it if you copy paste the link in the browser.
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.