×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Embedded Matlab Function Block

Embedded Matlab Function Block

Embedded Matlab Function Block

(OP)
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.

 

RE: Embedded Matlab Function Block

(OP)
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   

RE: Embedded Matlab Function Block

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)

RE: Embedded Matlab Function Block

btw, dSpace is really useful smile

peace
Fe (IronX32)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources