whitbuzben
Electrical
- Dec 2, 2010
- 18
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.
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.