필터 지우기
필터 지우기

I couldn't able to run Level 2 M-file S function...

조회 수: 1 (최근 30일)
Bhumin Desai
Bhumin Desai 2012년 7월 11일
Below is my Level 2 M-file S function,
function svpwm_states(block)
function setup(block)
block.NumInputPorts = 2;
block.NumOutputPorts = 1;
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
block.InputPort(1).DirectFeedthrough = false;
block.InputPort(2).DirectFeedthrough = false;
block.SampleTimes = [-1 0];
block.SimStateCompliance = 'DefaultSimState';
block.RegBlockMethod('PostPropagationSetup', @DoPostPropSetup);
block.RegBlockMethod('Start', @Start);
%block.RegBlockMethod('InitializeConditions', @InitializeConditions);
block.RegBlockMethod('Outputs',@Output);
block.RegBlockMethod('Update', @Update);
function DoPostPropSetup(block)
block.NumDworks = 1;
block.Dwork(1).Name = 'k';
block.Dwork(1).Dimensions = 1;
block.Dwork(1).DatatypeID = 0; % double
block.Dwork(1).Complexity = 'Real'; % real
block.Dwork(1).UsedAsDiscState = true;
%block.Dwork(2).Name = 'x';
%block.Dwork(2).Dimensions = 1;
%block.Dwork(2).DatatypeID = 0; % double
%block.Dwork(2).Complexity = 'Real'; % real
%block.Dwork(2).UsedAsDiscState = true;
function Start(block)
block.Dwork(1).Data = 0;
function Output(block)
block.OutputPort(1).Data = block.Dwork(1).Data;
function Update(block)
vsd = block.InputPort(1).Data;
vsq = block.InputPort(2).Data;
k = block.Dwork(1).Data;
if vsd>0 & vsq>=0 & vsd>vsq;
k=k+1;
elseif vsd>0 & vsq>=0 & vsd<=vsq;
k=k+2;
elseif vsd<=0 & vsq>0;
k=k+3;
elseif vsd<0 & vsq<=0 & vsd<vsq;
k=k+4;
elseif vsd<0 & vsq<0 & vsd>=vsq;
k=k+5;
elseif vsd>=0 & vsq<0;
k=k+6;
end
block.Dwork(1).Data = k;
function Terminate(block)
but when I tried to RUN the m-file, it's not showing any error. It didn't run at all. Plus when I used this block in my simulink model it didn't create two I/P port as declare in the code. I'm using this S function for the first time...Where am I going wrong, can any one suggest it??

채택된 답변

Kaustubha Govind
Kaustubha Govind 2012년 7월 11일
You need to call setup from your top-level function:
function svpwm_states(block)
setup(block);
  댓글 수: 3
Bhumin Desai
Bhumin Desai 2012년 7월 11일
I have corrected it now it runs But strangely it gives me this error ..
"Input argument "block" is undefined."
Kaustubha Govind
Kaustubha Govind 2012년 7월 12일
Try setting breakpoints in your code to see where the error occurs? You could also run "dbstop if all error" in MATLAB before running your model and see if the MATLAB debugger stops in your S-function. That should help you fix the error.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Michelle
Michelle 2012년 7월 11일
I just wrote my first couple of these in the past few days, so take my suggestion with a grain of salt!!
I THINK you have to define your input and output's in more detail (where you currently just have the feed through marked as false).
I have these in my code, and it plays nice.
block.InputPort(1).Dimensions = 1; block.InputPort(1).DatatypeID = 0; % double block.InputPort(1).Complexity = 'Real'; block.InputPort(1).DirectFeedthrough = false;
Also - i THINK (big caveat there) that you'll want to remove the terminate function line, or call it up top after
block.RegBlockMethod('Update', @Update);
Hopefully this helps!!
  댓글 수: 1
Bhumin Desai
Bhumin Desai 2012년 7월 11일
I tried this but it won't help...atleast it should give me some error...it's not running at all...

댓글을 달려면 로그인하십시오.


Michelle
Michelle 2012년 7월 11일
bah - sorry for the odd formatting!

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by