求一个boost PFC的matlab仿真程序.
谢谢!
我的邮箱是bkq7758@sina.com
求boost PFC的matlab仿真程序
全部回复(11)
正序查看
倒序查看
现在还没有回复呢,说说你的想法
@youdeworld
能否给我一份...谢谢啊...邮箱:hutianwww@163.com
#include"stdio.h"
#include"conio.h"
#include"stdlib.h"
#include"math.h"
#define REAL double
#define ICBOOL char
#define ICREG int
/*******************************data structure defination*************************************/
//simulator timing
struct simtime{
REAL dt;long int nstep;REAL tmax;long int nmax; //analog simulator time step
REAL clkdt;int nclkdt; //length of digital clock cycle
};
//analog components
struct analogparam{REAL transratio; REAL ll; REAL lm; REAL c1; REAL c2; REAL r1; REAL r2;};
struct analogstate{REAL ill;REAL ilm;REAL vc1;REAL vc2;REAL vs1;REAL vs2;REAL is1;REAL is2; REAL vi; REAL vo;};
//IC, pwm for test
struct iostate{ICBOOL mosdrv;};
struct pwmgen{REAL period;REAL pw;ICREG nperiod;ICREG npw;ICREG ncount;};
/*************************************time step advance****************************************/
void analogdt(struct simtime *stime,struct analogparam *aparam,struct analogstate *astate,struct iostate *ios)
{
REAL dt,transratio,ll,lm,c1,c2,r1,r2; //param
REAL ill,ilm,vc1,vc2,vs1,vs2,is1,is2,vi,vo; //state
//param
dt=stime->dt;
transratio=aparam->transratio;
ll=aparam->ll;
lm=aparam->lm;
c1=aparam->c1;
c2=aparam->c2;
r1=aparam->r1;
r2=aparam->r2;
//state
ill=astate->ill;
ilm=astate->ilm;
vc1=astate->vc1;
vc2=astate->vc2;
vs1=astate->vs1;
vs2=astate->vs2;
is1=astate->is1;
is2=astate->is2;
vi=astate->vi;
vo=astate->vo;
//switches DC operating point
if(ios->mosdrv)
{
astate->vs1=0.0;
astate->is1=ill+vc1/r1;
}
else
{
vs1=r1*ill+vc1;
vs1=0.5*(vs1+fabs(vs1)); //max(value,0), >=0, body diode on=0
astate->vs1=vs1;
is1=ill+vc1/r1;
is1=0.5*(is1-fabs(is1)); //min(value,0), <=0, body diode off=0
astate->is1=is1;
}
vs2=vc2+transratio*(ill-ilm)*r2;
vs2=0.5*(vs2+fabs(vs2)); //max(value,0), >=0, diode off=0
astate->vs2=vs2;
is2=-transratio*(ill-ilm)-vc2/r2;
is2=0.5*(is2+fabs(is2)); //max(value,0), >=0, diode on=0
astate->is2=is2;
//differential
astate->ill=ill+ dt*(vi-vs1+transratio*(vo-vs2))/ll;
astate->ilm=ilm+ dt*-1*transratio*(vo-vs2)/lm;
astate->vc1=vc1+ dt*(ill-is1)/c1;
astate->vc2=vc2+ dt*(is2+transratio*(ill-ilm))/c2;
//switches DC operating point
if(ios->mosdrv)
{
astate->vs1=0.0;
astate->is1=ill+vc1/r1;
}
else
{
vs1=r1*ill+vc1;
vs1=0.5*(vs1+fabs(vs1)); //max(value,0), >=0, body diode on=0
astate->vs1=vs1;
is1=ill+vc1/r1;
is1=0.5*(is1-fabs(is1)); //min(value,0), <=0, body diode off=0
astate->is1=is1;
}
vs2=vc2+transratio*(ill-ilm)*r2;
vs2=0.5*(vs2+fabs(vs2)); //max(value,0), >=0, diode off=0
astate->vs2=vs2;
is2=-transratio*(ill-ilm)-vc2/r2;
is2=0.5*(is2+fabs(is2)); //max(value,0), >=0, diode on=0
astate->is2=is2;
}
/*************************************pwm for test**********************************************/
void pwmtest(struct pwmgen *pwm,struct iostate *ios)
{
ios->mosdrv=0;
if(pwm->ncountnpw) ios->mosdrv=1;
pwm->ncount++;
if(pwm->ncount>=pwm->nperiod) pwm->ncount=0;
}
/******************************************init*************************************************/
void init(struct simtime *stime,struct analogparam *aparam,struct analogstate *astate,struct pwmgen *pwm)
{
stime->clkdt=1e-8;
stime->dt=1e-9;
stime->nclkdt=stime->clkdt/stime->dt;
stime->tmax=3e-5;
stime->nmax=stime->tmax/stime->dt;
stime->nstep=0;
aparam->transratio=10.0;
aparam->lm=200e-6;
aparam->ll=aparam->lm/100.0;
aparam->c1=1e-9;
aparam->c2=1e-9;
aparam->r1=100.0;
aparam->r2=10.0;
astate->vi=310;
astate->vo=12;
astate->vc1=astate->vi;
astate->vc2=astate->vo;
astate->vs1=astate->vi;
astate->vs2=astate->vo;
astate->ill=0;
astate->ilm=0;
astate->is1=0;
astate->is2=0;
pwm->period=1e-5;
pwm->pw=2e-6;
pwm->nperiod=pwm->period/stime->clkdt;
pwm->npw=pwm->pw/stime->clkdt;
pwm->ncount=0;
}
/*****************************************main**************************************************/
void main(void)
{
struct simtime stime;
struct analogparam aparam;
struct analogstate astate;
struct iostate ios;
struct pwmgen pwm;
FILE *fp;
if((fp=fopen("out.plt","w"))==NULL){printf("file open error");exit(0);}
fprintf(fp,"variables=time,ill,ilm,vc1,vc2,vs1,vs2,is1,is2\n");
init(&stime,&aparam,&astate,&pwm);
for(stime.nstep=1;stime.nstep<=stime.nmax;stime.nstep++)
{
if(stime.nstep%stime.nclkdt==0) pwmtest(&pwm,&ios);
analogdt(&stime,&aparam,&astate,&ios);
// printf("%d\n",nstep);
fprintf(fp,"%e %f %f %f %f %f %f %f %f\n",stime.dt*stime.nstep,astate.ill,astate.ilm,astate.vc1,astate.vc2,astate.vs1,astate.vs2,astate.is1,astate.is2);
}
fclose(fp);
}
#include"conio.h"
#include"stdlib.h"
#include"math.h"
#define REAL double
#define ICBOOL char
#define ICREG int
/*******************************data structure defination*************************************/
//simulator timing
struct simtime{
REAL dt;long int nstep;REAL tmax;long int nmax; //analog simulator time step
REAL clkdt;int nclkdt; //length of digital clock cycle
};
//analog components
struct analogparam{REAL transratio; REAL ll; REAL lm; REAL c1; REAL c2; REAL r1; REAL r2;};
struct analogstate{REAL ill;REAL ilm;REAL vc1;REAL vc2;REAL vs1;REAL vs2;REAL is1;REAL is2; REAL vi; REAL vo;};
//IC, pwm for test
struct iostate{ICBOOL mosdrv;};
struct pwmgen{REAL period;REAL pw;ICREG nperiod;ICREG npw;ICREG ncount;};
/*************************************time step advance****************************************/
void analogdt(struct simtime *stime,struct analogparam *aparam,struct analogstate *astate,struct iostate *ios)
{
REAL dt,transratio,ll,lm,c1,c2,r1,r2; //param
REAL ill,ilm,vc1,vc2,vs1,vs2,is1,is2,vi,vo; //state
//param
dt=stime->dt;
transratio=aparam->transratio;
ll=aparam->ll;
lm=aparam->lm;
c1=aparam->c1;
c2=aparam->c2;
r1=aparam->r1;
r2=aparam->r2;
//state
ill=astate->ill;
ilm=astate->ilm;
vc1=astate->vc1;
vc2=astate->vc2;
vs1=astate->vs1;
vs2=astate->vs2;
is1=astate->is1;
is2=astate->is2;
vi=astate->vi;
vo=astate->vo;
//switches DC operating point
if(ios->mosdrv)
{
astate->vs1=0.0;
astate->is1=ill+vc1/r1;
}
else
{
vs1=r1*ill+vc1;
vs1=0.5*(vs1+fabs(vs1)); //max(value,0), >=0, body diode on=0
astate->vs1=vs1;
is1=ill+vc1/r1;
is1=0.5*(is1-fabs(is1)); //min(value,0), <=0, body diode off=0
astate->is1=is1;
}
vs2=vc2+transratio*(ill-ilm)*r2;
vs2=0.5*(vs2+fabs(vs2)); //max(value,0), >=0, diode off=0
astate->vs2=vs2;
is2=-transratio*(ill-ilm)-vc2/r2;
is2=0.5*(is2+fabs(is2)); //max(value,0), >=0, diode on=0
astate->is2=is2;
//differential
astate->ill=ill+ dt*(vi-vs1+transratio*(vo-vs2))/ll;
astate->ilm=ilm+ dt*-1*transratio*(vo-vs2)/lm;
astate->vc1=vc1+ dt*(ill-is1)/c1;
astate->vc2=vc2+ dt*(is2+transratio*(ill-ilm))/c2;
//switches DC operating point
if(ios->mosdrv)
{
astate->vs1=0.0;
astate->is1=ill+vc1/r1;
}
else
{
vs1=r1*ill+vc1;
vs1=0.5*(vs1+fabs(vs1)); //max(value,0), >=0, body diode on=0
astate->vs1=vs1;
is1=ill+vc1/r1;
is1=0.5*(is1-fabs(is1)); //min(value,0), <=0, body diode off=0
astate->is1=is1;
}
vs2=vc2+transratio*(ill-ilm)*r2;
vs2=0.5*(vs2+fabs(vs2)); //max(value,0), >=0, diode off=0
astate->vs2=vs2;
is2=-transratio*(ill-ilm)-vc2/r2;
is2=0.5*(is2+fabs(is2)); //max(value,0), >=0, diode on=0
astate->is2=is2;
}
/*************************************pwm for test**********************************************/
void pwmtest(struct pwmgen *pwm,struct iostate *ios)
{
ios->mosdrv=0;
if(pwm->ncount
pwm->ncount++;
if(pwm->ncount>=pwm->nperiod) pwm->ncount=0;
}
/******************************************init*************************************************/
void init(struct simtime *stime,struct analogparam *aparam,struct analogstate *astate,struct pwmgen *pwm)
{
stime->clkdt=1e-8;
stime->dt=1e-9;
stime->nclkdt=stime->clkdt/stime->dt;
stime->tmax=3e-5;
stime->nmax=stime->tmax/stime->dt;
stime->nstep=0;
aparam->transratio=10.0;
aparam->lm=200e-6;
aparam->ll=aparam->lm/100.0;
aparam->c1=1e-9;
aparam->c2=1e-9;
aparam->r1=100.0;
aparam->r2=10.0;
astate->vi=310;
astate->vo=12;
astate->vc1=astate->vi;
astate->vc2=astate->vo;
astate->vs1=astate->vi;
astate->vs2=astate->vo;
astate->ill=0;
astate->ilm=0;
astate->is1=0;
astate->is2=0;
pwm->period=1e-5;
pwm->pw=2e-6;
pwm->nperiod=pwm->period/stime->clkdt;
pwm->npw=pwm->pw/stime->clkdt;
pwm->ncount=0;
}
/*****************************************main**************************************************/
void main(void)
{
struct simtime stime;
struct analogparam aparam;
struct analogstate astate;
struct iostate ios;
struct pwmgen pwm;
FILE *fp;
if((fp=fopen("out.plt","w"))==NULL){printf("file open error");exit(0);}
fprintf(fp,"variables=time,ill,ilm,vc1,vc2,vs1,vs2,is1,is2\n");
init(&stime,&aparam,&astate,&pwm);
for(stime.nstep=1;stime.nstep<=stime.nmax;stime.nstep++)
{
if(stime.nstep%stime.nclkdt==0) pwmtest(&pwm,&ios);
analogdt(&stime,&aparam,&astate,&ios);
// printf("%d\n",nstep);
fprintf(fp,"%e %f %f %f %f %f %f %f %f\n",stime.dt*stime.nstep,astate.ill,astate.ilm,astate.vc1,astate.vc2,astate.vs1,astate.vs2,astate.is1,astate.is2);
}
fclose(fp);
}
0
回复
提示