Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Embedded Matlab Function Block

Status
Not open for further replies.

whitbuzben

Electrical
Dec 2, 2010
18
0
0
GB
Hi All

I am using the embedded Matlab function block to write some code for a state machine. Within the block i have the following code:

function [AC_Contactor,DC_Contactor,AC_Precharge,DC_Precharge,X] = V_ctrl_AC(B1,DC_Voltage_Ref,DC_Link_Voltage)

AC_Contactor=0; DC_Contactor=0; AC_Precharge=0; DC_Voltage_Ref=0; DC_Precharge=0; X=0;

if B1<1

AC_Contactor=0;
DC_Contactor=0;
AC_Precharge=0;
DC_Precharge=0;

elseif (B1==1 && X==0 && DC_Link_Voltage<70) (B1== && X==1 && DC_Link_Voltage<40)

AC_Contactor=0;
DC_Contactor=0;
AC_Precharge=1;
DC_Precharge=0;
X=0;

elseif (B1==1 && DC_Link_Voltage >= 70)

AC_Contactor=1;
DC_Contactor=1;
AC_Precharge=0;
DC_Precharge=1;
X=1;

end;

What i want the programme to do is execute the first command if B1<1. Then if the variables B1, X and DC_Link_Voltage are 1, 0 and less than 70 respectively i want to execute the second statement.Then once B1 and DC_Link_Voltage are 1 and >=70 i want to execute the third statement.

I use the variable X to add hysteresis because i do not want to jump back to the second statement until the Dc_Link_Voltage has dropped back BELOW 40. Unfortunately this code does not seem to work as everytime the Dc_Link_Voltage goes back below 70 i fall back into statemnent 2. I have a Ccode version of this which works. I am new to programming in Matlab any assistance would be appreciated.



 
Replies continue below

Recommended for you

If you have working C code, then why aren't you duplicating that?

TTFN
faq731-376
7ofakss
 
I am working with a DSPACE unit and i need the code inrunning in Matlab so that i can trasfer it onto the DSPACE. I apologise ther is a small error in the initial post above. This might be clearer:

function [AC_Contactor,DC_Contactor,AC_Precharge,DC_Precharge,X] = V_ctrl_AC(B1,DC_Voltage_Ref,DC_Link_Voltage)

AC_Contactor=0; DC_Contactor=0; AC_Precharge=0; DC_Voltage_Ref=0; DC_Precharge=0; X=0;

if B1<1

AC_Contactor=0;
DC_Contactor=0;
AC_Precharge=0;
DC_Precharge=0;

elseif (B1==1 && X==0 && DC_Link_Voltage<70)||(B1==1 && X==1 && DC_Link_Voltage<40)

AC_Contactor=0;
DC_Contactor=0;
AC_Precharge=1;
DC_Precharge=0;
X=0;

elseif (B1==1 && DC_Link_Voltage >= 70)

AC_Contactor=1;
DC_Contactor=1;
AC_Precharge=0;
DC_Precharge=1;
X=1;

end;

Again any help would be appreciated.

Thanks
 
I used dSpace for research before. You don't "have to" have the code im Matlab. You can use an S-function written in all C and it still compiles to .mex for dSpace realtime experiments.



[peace]
Fe (IronX32)
 
Status
Not open for further replies.
Back
Top