#include "SimplorerAfx.h"
#include "Sim2000User.h"
#include "Simd_define.h"
#include "math.h"
#define STRG_NCNAME_INPUT1 "Input1"
#define STRG_NCNAME_INPUT2 "Input2"
#define STRG_NCNAME_INPUT3 "Input3"
#define STRG_NCNAME_INPUT4 "Input4"
#define STRG_NCNAME_OUTPUT1 "Output1"
#define STRG_NCNAME_OUTPUT2 "Output2"
#define STRG_NCNAME_OUTPUT3 "Output3"
#define STRG_NCNAME_OUTPUT4 "Output4"
#define STRG_NCNAME_OUTPUT5 "Output5"
#define STRG_NCNAME_OUTPUT6 "Output6"
#define STRG_NCNAME_INTEG_OUT1 "INTEG_OUT1"
#define STRG_NCNAME_INTEG_OUT2 "INTEG_OUT2"
#define STRG_NCNAME_INTEG_OUT3 "INTEG_OUT3"
#define STRG_NCNAME_INTEG_OUT4 "INTEG_OUT4"
FCTDECL Prepare_Simd( CModUser *pMod )
{
//inner states--AddNode_State
//conservative nodes-- AddNode__c
//non-conservative nodes--AddNode_nc
pMod->AddNode_nc(STRG_NCNAME_INPUT1, 0.0,DIRIN);
pMod->AddNode_nc(STRG_NCNAME_INPUT2, 0.0,DIRIN);
pMod->AddNode_nc(STRG_NCNAME_INPUT3, 0.0,DIRIN);
pMod->AddNode_nc(STRG_NCNAME_INPUT4, 0.0,DIRIN);
//Parameter Info
//English
pMod->SetInfoNode_nc( STRG_NCNAME_INPUT1, "Input1");
pMod->SetInfoNode_nc( STRG_NCNAME_INPUT2, "Input2");
pMod->SetInfoNode_nc( STRG_NCNAME_INPUT3, "Input3");
pMod->SetInfoNode_nc( STRG_NCNAME_INPUT4, "Input4");
//Output
pMod->AddNode_nc( STRG_NCNAME_OUTPUT1, 0.0, DIROUT);
pMod->AddNode_nc( STRG_NCNAME_OUTPUT2, 0.0, DIROUT);
pMod->AddNode_nc( STRG_NCNAME_OUTPUT3, 0.0, DIROUT);
pMod->AddNode_nc( STRG_NCNAME_OUTPUT4, 0.0, DIROUT);
pMod->AddNode_nc( STRG_NCNAME_OUTPUT5, 0.0, DIROUT);
pMod->AddNode_nc( STRG_NCNAME_OUTPUT6, 0.0, DIROUT);
pMod->AddNode_nc( STRG_NCNAME_INTEG_OUT1, 0.0, DIROUT);
pMod->AddNode_nc( STRG_NCNAME_INTEG_OUT2, 0.0, DIROUT);
pMod->AddNode_nc( STRG_NCNAME_INTEG_OUT3, 0.0, DIROUT);
pMod->AddNode_nc( STRG_NCNAME_INTEG_OUT4, 0.0, DIROUT);
//Output Info
pMod->SetInfoNode_nc( STRG_NCNAME_OUTPUT1, "Output1");
pMod->SetInfoNode_nc( STRG_NCNAME_OUTPUT2, "Output2");
pMod->SetInfoNode_nc( STRG_NCNAME_OUTPUT3, "Output3");
pMod->SetInfoNode_nc( STRG_NCNAME_OUTPUT4, "Output4");
pMod->SetInfoNode_nc( STRG_NCNAME_OUTPUT5, "Output5");
pMod->SetInfoNode_nc( STRG_NCNAME_OUTPUT6, "Output6");
pMod->SetInfoNode_nc( STRG_NCNAME_INTEG_OUT1, "INTEG_OUT1");
pMod->SetInfoNode_nc( STRG_NCNAME_INTEG_OUT2, "INTEG_OUT2");
pMod->SetInfoNode_nc( STRG_NCNAME_INTEG_OUT3, "INTEG_OUT3");
pMod->SetInfoNode_nc( STRG_NCNAME_INTEG_OUT4, "INTEG_OUT4");
//Adding an inner states with the same name like the output!
pMod->AddNode_State( STRG_NCNAME_OUTPUT1);
pMod->AddNode_State( STRG_NCNAME_OUTPUT2);
pMod->AddNode_State( STRG_NCNAME_OUTPUT3);
pMod->AddNode_State( STRG_NCNAME_OUTPUT4);
pMod->AddNode_State( STRG_NCNAME_OUTPUT5);
pMod->AddNode_State( STRG_NCNAME_OUTPUT6);
pMod->AddNode_State( STRG_NCNAME_INTEG_OUT1);
pMod->AddNode_State( STRG_NCNAME_INTEG_OUT2);
pMod->AddNode_State( STRG_NCNAME_INTEG_OUT3);
pMod->AddNode_State( STRG_NCNAME_INTEG_OUT4);
return 1L;
}
FCTDECL Initialize_Simd_TR( CModUser *pMod )
{
return TRUE;
}
FCTDECL Simulate_Simd_TR( CModUser *pMod )
{
static double Tperiod;
double timer1;
double input1 =pMod->GetValNode_nc( STRG_NCNAME_INPUT1);
double input2 =pMod->GetValNode_nc( STRG_NCNAME_INPUT2);
double input3 =pMod->GetValNode_nc( STRG_NCNAME_INPUT3);
double input4 =pMod->GetValNode_nc( STRG_NCNAME_INPUT4);
static double nsum=0 ;//have to define to the static variable
static double deadtime;
static double sum1=0,sum2=0,sum3=0,sum4=0 ,sum6=0 ;
static double sum7=0,sum9=0,sum10=0;
static double output1,output2,output3,output4;
static double sample_time;
static double MULA, MULB , MULAf,MULBf,sumaf,sumbf;
static double integ1,integ2,integ3,integ4;
static double ton1_s,ton2_s ,ton1_e ,ton2_e ,ton1_sf;
static double ton2_sf,ton1_ef,ton2_ef;
static double ton1,ton2,ton3,counter2;
Tperiod=1.0/2000;
deadtime=1.0e-5;
timer1=1-fabs(2-4.*fmod(input4,Tperiod)/Tperiod);
if(input4>nsum*Tperiod)
{
nsum=nsum+1;
//the up one step start and end time
ton1_sf=ton1_s;
ton1_ef=ton1_e;
ton2_sf=ton2_s;
ton2_ef=ton2_e;
MULAf =MULA;
MULBf =MULB;
//speed PI control
sum1=3000-input1;
integ1=pMod->GetValNode_State( STRG_NCNAME_INTEG_OUT1);
sample_time=GET_SAMPLETIME(pMod);
integ1 +=sum1*sample_time;
sum2=sum1*4+integ1*10+2*3000*3000/(3*1000*75);
//current PI control
MULA=sum2*input3/1000;
MULB=sum2*input4/1000;
sum3=MULA-input2;
integ2= pMod->GetValNode_State(STRG_NCNAME_INTEG_OUT2);
integ2+=sum3*sample_time;
sum6=sum3*1.5+integ2*5;
sum4=MULB-input3;
integ3=pMod->GetValNode_State(STRG_NCNAME_INTEG_OUT3);
integ3+= sum4* sample_time;
sum7=sum4*1.5+integ3*5;
//former fed back
sumaf=MULA*0.068+0.0023*(MULA-MULAf)/Tperiod;
sumbf=MULB*0.068+0.0023*(MULB-MULBf)/Tperiod;
sum9=(input3-sum6-sumaf)/3000;
sum10=(input4-sum7-sumbf)/3000;
if(sum9>1)
sum9=1;
if(sum9<-1)
sum9=-1;
if(sum10>1)
sum10=1;
if(sum10<-1)
sum10=-1;
ton1=(sum9+1)*Tperiod/2;
ton2=(sum10+1)*Tperiod/2;
if(ton1>Tperiod)
ton1=Tperiod;
if(ton1<0)
ton1=0;
if(ton2>Tperiod)
ton2=Tperiod;
if(ton2<0)
ton2=0;
//the start time and end tiem of every
//IGBT which do not consider the dead time
ton1_s=(Tperiod-ton1)/2;
ton1_e=(Tperiod+ton1)/2;
ton2_s=(Tperiod-ton2)/2;
ton2_e=(Tperiod+ton2)/2;
counter2=input4-(nsum-1)*Tperiod;
//Generate the switch gating signal
if ((counter2<ton1_sf+deadtime) || (counter2>ton1_ef))
output1=-1;
else
output1=1;
if ((counter2<ton1_sf) || (counter2>ton1_ef+deadtime))
output2=1;
else
output2=-1;
if((counter2<ton2_sf+deadtime)||(counter2>ton2_ef))
output3=-1;
else
output3=1;
if((counter2<ton2_sf)||(counter2>ton2_ef+deadtime))
output4=1;
else
output4=-1;
//Setting the output via the same name internal state:
pMod->SetValNode_State(STRG_NCNAME_OUTPUT1, output1);
pMod->SetValNode_State(STRG_NCNAME_OUTPUT2,output2);
pMod->SetValNode_State(STRG_NCNAME_OUTPUT3, output3);
pMod->SetValNode_State(STRG_NCNAME_OUTPUT4, output4);
pMod->SetValNode_State(STRG_NCNAME_OUTPUT5,sum9);
pMod->SetValNode_State(STRG_NCNAME_OUTPUT6, sum10);
return TRUE;
}
}
FCTDECL Validate_Simd_TR( CModUser *pMod )
{
return TRUE;
}
FCTDECL Close_Simd_TR( CModUser *pMod )
{
return TRUE;
}
这是本人从三相PWM整流电路闭环程序修改成的两相SPWM整流电路程序,求大神指导,把程序如何从闭环改为开环
Simplorer闭环控制程序怎么改为开环控制程序 |