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

10 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2012-8-22
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.
_Please to go to the link or download the file copy paste those links on your browser otherwise its not working :(_

请先登录,再进行评论。

回答(6 个)

Kaustubha Govind
Kaustubha Govind 2012-8-23
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.

Mariano Lizarraga
Mariano Lizarraga 2012-8-25
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

KHALID SAKIB
KHALID SAKIB 2012-8-23
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.

KHALID SAKIB
KHALID SAKIB 2012-8-24
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 个评论
Kaustubha Govind
Kaustubha Govind 2012-8-27
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
KHALID SAKIB 2012-8-26
instead of clicking you can download it if you copy paste the link in the browser.
  1 个评论
Mariano Lizarraga
Mariano Lizarraga 2012-8-27
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

请先登录,再进行评论。


KHALID SAKIB
KHALID SAKIB 2012-8-27
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.

类别

Help CenterFile Exchange 中查找有关 String 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by