I couldn't able to run Level 2 M-file S function...
Afficher commentaires plus anciens
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??
Réponse acceptée
Plus de réponses (2)
Michelle
le 11 Juil 2012
0 votes
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 commentaire
Bhumin Desai
le 11 Juil 2012
Michelle
le 11 Juil 2012
0 votes
bah - sorry for the odd formatting!
Catégories
En savoir plus sur Modeling dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!