/******************************************************************************************************************
【flag对应执行程序 :】
startFlag=0:未启动;startFlag=1:移相启动;startFlag=2:变频启动
Loop_LLC=0:开环运行;Loop_LLC=1:闭环中移相环节;Loop_LLC=2:闭环中变频环节
注意:不同程序段进行切换时,要注意程序间的无缝对接
**********************************************************************/
#include <stdio.h>
#define Tdead 20//死区时间:20*e-8=200ns.
#define angle 1//这里计数1次移1次角度,每次移0.72度;(TBPRD+1)/360=500/360约=1.39,即每移1度,计数1.39次;360/(TBPRD+1)=0.72,即每计数1次,移0.72度 330/180约等于2,即每移1度,计数次数为4(计算每移1度需要计数几次?因为计数330次为半个周期,因此330次对应180度,所以计数1次对应180/330=6/11度,约等于0.5454545,当每个周期计数值加2,则对应1.0909度,每移1度对应计数330/180次,约等于2)
#define Prd_LLC_Kp 2//LLC闭环变频环节PI
#define Prd_LLC_Ki 1//变频积分常数对变频环节输出电压波动有着一定影响
#define Phase_LLC_Kp 10//LLC闭环移相环节PI
#define Phase_LLC_Ki 10
#define Vout_LLC_ref 48//LLC输出参考电压
#define Vout_Prd_LLC_OutMax 999
#define Vout_Prd_LLC_OutMin 499
#define Vout_Phase_LLC_OutMax 270 //移相180度
#define Vout_Phase_LLC_OutMin 20 //移相0度
_declspec(dllexport) void simuser (double t, double delt, double* in, double* out)
{
static int startFlag=1,Loop_LLC=0;
static int Tcount=0,i=1,temp2=0;
static double time,VoutFeedback;//delt=1e-8s时,对应系统频率为100000k,当脉冲频率为200k时,TBPRD=1/TBCLK/fpulse-1=1/1e-8/200k-1=499
static double pulse1=0,pulse2=0, pulse3=0,pulse4=0;
static int TBPRD=499,timetemp=0,CBset=270,CAset=Tdead,CAbefore=0,CAbehind=270,CAclear=250,CBclear=499,CBbefore=250,CBbehind=20,settemp=270;//CB=0.5*(TBPRD+1)+Tdead,CA=Tdead,Ctemp=0.5*(TBPRD+1);CBbefore=CBset-Tdead;CBbehind=CBclear+Tdead;CAbefore=CAset-Tdead;CAbehind=CAclear+Tdead;
// struct PI_Struct
//{
// double Err; //误差量
// double ref; //基准值
// double Kp; //比例系数kp
// double Ki; //积分系数ki
// double Kc;
// double Up; //比例项
// double Ui; //积分项
// double SatErr;
// double OutPreSat;
// double Out;
// double OutMax;//(限幅)
// double OutMin;//(限幅)
// double Net;
//};
// struct PI_Struct Vout_Prd_LLC; //LLC电压闭环(变频)
// struct PI_Struct Vout_Phase_LLC;//LLC电压闭环(移相)
static double Vout_Prd_LLC_Kp = Prd_LLC_Kp;
static double Vout_Prd_LLC_Ki = Prd_LLC_Ki;
static double Vout_Prd_LLC_Up = 0;
static double Vout_Prd_LLC_Ui = 499;
static double Vout_Prd_LLC_OutPreSat = 499;
static double Vout_Prd_LLC_Out = 499;
static double Vout_Prd_LLC_ref = Vout_LLC_ref;
static double Vout_Prd_LLC_err=0;
static double Vout_Phase_LLC_Kp = Phase_LLC_Kp;
static double Vout_Phase_LLC_Ki = Phase_LLC_Ki;
static double Vout_Phase_LLC_Up = 0;
static double Vout_Phase_LLC_Ui = 20;
static double Vout_Phase_LLC_OutPreSat = 20;//Vout_Phase_LLC_OutPreSat=Vout_Phase_LLC_Up+Vout_Phase_LLC_Ui(PI公式,给定移相环节CBset初始值)
static double Vout_Phase_LLC_Out = 20;
static double Vout_Phase_LLC_ref = Vout_LLC_ref;
static double Vout_Phase_LLC_err=0;
VoutFeedback=in[0];
/*计数环节:产生三角波*/
if(Tcount<TBPRD)
{
Tcount++;
timetemp++;
}
else
{
Tcount=0;
}
switch(startFlag)
{
case 0:
break;
case 1:
{
/*脉冲触发环节*/
//pulse1直接设定,pulse2作为pulse1的互补脉冲相对pulse1需要前后加死区,
if(Tcount==CAset)
{
pulse1=1;
}
if(Tcount==CAclear)
{
pulse1=0;
}
if(Tcount==CAbefore)
{
pulse2=0;
}
if(Tcount==CAbehind)
{
pulse2=1;
}
if(Tcount==CBbefore)
{
pulse3=0;
}
if(Tcount==CBbehind)
{
pulse3=1;
}
if(Tcount==CBset)
{
pulse4=1;
}
if(Tcount==CBclear)
{
pulse4=0;
}
if(Tcount==0)
{
if(CBset>=CAset+angle)
{
CBset=CBset-angle;
CBclear=CBclear-angle;
CBbefore=CBset-Tdead;
CBbehind=CBclear+Tdead;
if(CBbehind>TBPRD)
CBbehind=CBbehind-TBPRD;
else
{
if(i==1)
{
pulse3=1;
i--;
}
}
if(CBbefore==0)
pulse3=0;
}
else
{
CBset=CAset;
CBclear=CAclear;
CBbefore=CAbefore;//CBbefore=CBset-Tdead;
CBbehind=CAbehind;//CBbehind=CBclear-Tdead;
startFlag=2;
}
}
if(VoutFeedback>=Vout_Phase_LLC_ref)
{
startFlag=0;
Loop_LLC=1;
//Vout_Phase_LLC_Out = CBset;//(这里为错误语句,下面为正确语句)从移相启动到闭环移相环节,更新闭环移相环节初始 CBset值
Vout_Phase_LLC_Ui= CBset;//从移相启动到闭环移相环节,更新闭环移相环节初始 CBset值
}
break;
}
case 2:
{
if(Tcount==CAset)
{
pulse1=1;
}
if(Tcount==CAclear)
{
pulse1=0;
}
if(Tcount==CAbefore)
{
pulse2=0;
}
if(Tcount==CAbehind)
{
pulse2=1;
}
if(Tcount==CBbefore)
{
pulse3=0;
}
if(Tcount==CBbehind)
{
pulse3=1;
}
if(Tcount==CBset)
{
pulse4=1;
}
if(Tcount==CBclear)
{
pulse4=0;
}
if((Tcount==0)&&(TBPRD<=999))
{
TBPRD++;
//CAset=Tdead;
CAclear=0.5*(TBPRD+1);
//CAbefore=0;
CAbehind=CAclear+Tdead;
//CBset=Tdead;
CBclear=CAclear;
//CAbefore=0;
CBbehind=CAbehind;
}
if(VoutFeedback>=Vout_Prd_LLC_ref)
{
startFlag=0;
Loop_LLC=2;
//Vout_Prd_LLC_Out=TBPRD;//(这里为错误语句,下面为正确语句)从变频启动到闭环变频环节,更新闭环变频环节初始TBPRD值
Vout_Prd_LLC_Ui=TBPRD;//从变频启动到闭环变频环节,更新闭环变频环节初始TBPRD值,这句话很重要。。。。。
}
break;
}
}
switch(Loop_LLC)
{
case 0:
break;
case 1:
{
if(Tcount==0)
{
TBPRD=499;//思考移相变频过程中set与clear问题:如果直接从启动中移相环节过渡到闭环中移相环节,则set与clear则可以正常使用;如果从闭环中变频环节过渡到闭环中移相环节,变频环节的set与clear是根据公式重新计算得到的,因此如果从变频进入移相,需要进行set与clear的初始化过程,将set与clear的数值重新赋值为移相时数值(如果从变频过渡到移相,一定是需要减小电压,因此移相角是逐渐增大过程,初始移相角为0,需要在变频结束时进行配置移相初值问题,又因为本程序针对脉冲置位与复位采用静态变量,有实时更新功能,因此不需要重新设置);
Vout_Phase_LLC_err=VoutFeedback-Vout_Phase_LLC_ref;
Vout_Phase_LLC_Up=Vout_Phase_LLC_err*Vout_Phase_LLC_Kp;
Vout_Phase_LLC_Ui=Vout_Phase_LLC_Ui+Vout_Phase_LLC_err*Vout_Phase_LLC_Ki;
Vout_Phase_LLC_OutPreSat=Vout_Phase_LLC_Up+Vout_Phase_LLC_Ui;
if(Vout_Phase_LLC_Ui>=Vout_Phase_LLC_OutMax)
Vout_Phase_LLC_Ui=Vout_Phase_LLC_OutMax;
if(Vout_Phase_LLC_Ui<Vout_Phase_LLC_OutMin)
Vout_Phase_LLC_Ui=Vout_Phase_LLC_OutMin;
if(Vout_Phase_LLC_OutPreSat>=Vout_Phase_LLC_OutMax)
Vout_Phase_LLC_OutPreSat=Vout_Phase_LLC_OutMax;
if(Vout_Phase_LLC_OutPreSat<Vout_Phase_LLC_OutMin)
Vout_Phase_LLC_OutPreSat=Vout_Phase_LLC_OutMin;
Vout_Phase_LLC_Out=Vout_Phase_LLC_OutPreSat;
CBset=Vout_Phase_LLC_Out;
CBclear=CBset+TBPRD-270;
//CBset=CBset+Vout_Phase_LLC_Out;
//CBclear=CBclear+Vout_Phase_LLC_Out;
if(CBset>=270||CBclear>TBPRD)//电压不能再减小了,即不能完成电压输出稳定。
{
CBset=270;
CBclear=TBPRD;
}
/*if(CBset>270)
CBset=270;
if(CBclear>TBPRD)
CBclear=TBPRD;*/
CBbefore=CBset-Tdead;
CBbehind=CBclear+Tdead;
if(CBbehind>TBPRD)
{
CBbehind=CBbehind-TBPRD;
}
if(CBbehind-temp2>200)
{
pulse3=1;
}
//settemp=0.5*(TBPRD+1)+Tdead;
if(CBset==CAset)
{
//CBset=CAset;
CBbefore=CAbefore;
pulse3=0;
Loop_LLC=2;
Vout_Phase_LLC_Out=Vout_Phase_LLC_OutMin;//从闭环移相环节进入闭环变频环节前,为了下次再次进入闭环移相环节,先把闭环移相环节初始条件做好,对移相环节CBset赋初值,移相角为0,既是对下次闭环移相环节设定初始条件,又是为闭环变频环
没有合适的资源?快使用搜索试试~ 我知道了~
PSIM全桥LLC仿真
共46个文件
tlog:10个
pdb:4个
log:2个
5星 · 超过95%的资源 需积分: 40 195 下载量 125 浏览量
2019-11-25
15:15:06
上传
评论 22
收藏 17.86MB ZIP 举报
温馨提示
用C语言写控制的全桥LLC PSIM仿真,要的拿走,包含PSIM仿真文件,c语言源代码控制DLL文件。需要的拿走
资源推荐
资源详情
资源评论
收起资源包目录
FullBridgeLLC.zip (46个子文件)
FullBridgeLLC
LoopLLC
LoopLLC
LoopLLC
LoopLLC.vcxproj 4KB
LoopLLC.opt 48KB
LoopLLC.ncb 33KB
LoopLLC.c 10KB
LoopLLC.dsw 537B
LoopLLC.vcxproj.user 143B
LoopLLC.plg 988B
Debug
vc100.idb 27KB
LoopLLC.exp 543B
LoopLLC.vcxprojResolveAssemblyReference.cache 713B
LoopLLC.pdb 25KB
CL.write.1.tlog 332B
CL.read.1.tlog 1000B
mt.read.1.tlog 282B
LoopLLC.obj 14KB
LoopLLC.pch 211KB
LoopLLC.Build.CppClean.log 1KB
mt.command.1.tlog 430B
cl.command.1.tlog 728B
vc60.idb 33KB
link.write.1.tlog 580B
LoopLLC.lastbuildstate 58B
link.command.1.tlog 1KB
link.read.1.tlog 3KB
vc60.pdb 44KB
LoopLLC.write.1.tlog 5KB
mt.write.1.tlog 282B
LoopLLC.log 2KB
LoopLLC.lib 2KB
LoopLLC.dll.intermediate.manifest 381B
vc100.pdb 60KB
LoopLLC.dsp 3KB
LoopLLC.vcxproj.filters 943B
LoopLLC.suo 11KB
ipch
loopllc-1ddc58e6
loopllc-a985df41.ipch 1.38MB
Debug
LoopLLC.exp 595B
LoopLLC.pdb 371KB
LoopLLC.ilk 291KB
LoopLLC.dll.manifest 406B
LoopLLC.dll 29KB
LoopLLC.lib 2KB
LoopLLC.sln 893B
LoopLLC.sdf 1.52MB
fullLLC.smv 28.53MB
fullLLC.psimsch 42KB
LoopLLC.dll 29KB
共 46 条
- 1
资源评论
- designworks2022-05-10这个需要的PSIM版本太高了,PSIM9.0打不开。遗憾。但C语言源文件不少,还有dll文件。
电力电子小泽
- 粉丝: 4
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功