/*-----------------------------------------------------------*/
/************************************************************/
/*ad中断程序*/
#include "const.h"
#include "pid_reg1.h"
#include "svgen.h"
#include "firfilt.h"
/*#include "firfilt.h" */
/**************************************************************/
/*外部变量声明
/**************************************************************/
void prevent();
void vregulator();
extern *MCRA;
extern *MCRC;
extern *PADATDIR;
extern *PBDATDIR;
extern *PEDATDIR;
extern *CMPR1;
extern *CMPR2;
extern *CMPR3;
extern *CMPR4;
extern *CMPR5;
extern *CMPR6;
extern *ADCTRL2;
extern *RESULT0;
extern *RESULT1;
extern *RESULT2;
extern *RESULT3;
extern *RESULT4;
extern *RESULT5;
extern *RESULT6;
extern *RESULT7;
extern *RESULT8;
extern *RESULT9;
extern *RESULT10;
/**************************整流器*****************************/
extern TWO ibackrotate;
extern TWO urefrotate;
extern TWO erotate;
extern TWO dqrotate ;
extern TWO dqstation;
extern TWO irefstation;
extern TWO ibackstation;
extern TWO gridstation;
extern TWO irefrotate ;
extern THREE iback ;
extern THREE grid ;
extern wl;
extern anglematrix[N];
extern SVGENDQ svpwm ;
extern PIDREG1 cdpi;
extern PIDREG1 cqpi;
/***************************逆变器**********************************/
extern THREE inviback; //逆变测电流反馈
extern THREE inviref; //逆变测电流给定
extern THREE invvback; //逆变器电压反馈
extern THREE invvref; //你变器电压给定
extern TWO invibacksta; //静止坐标系下的电流反馈
extern TWO invibackrot; //旋转坐标系下的电流反馈
extern TWO invirefsta; //静止坐标系下的电流给定
extern TWO invirefrot; //旋转坐标系下的电流给定
extern TWO invvbacksta; //
extern TWO invvbackrot;
extern TWO invvrefsta;
extern TWO invvrefrot;
extern TWO invurefrotate; //旋转坐标系下电流环输出
extern TWO invdqrotate; //旋转坐标系下的占空比
extern TWO invdqstation; //禁止坐标系下的占空比
//PIDREG1 vpi=PIDREG1_DEFAULTS; //电压环调节器
extern PIDREG1 invcdpi; //电流环调节器d
extern PIDREG1 invcqpi; //电流环调节器q
extern SVGENDQ invsvpwm;
extern invcount;
extern invwl;
/************************************************************************/
extern tp;
extern count;
extern invdc;
extern udc ;
extern udcref;
extern vvv;
extern iii;
extern invi;
int pest=0,invgrid=0;
extern softcount;
extern softflag;
extern vflag;
extern number;
extern lastout;
extern FIRFILT_ORD10 fir;
extern coeff[500];
extern aaa[500];
extern bbb[500];
extern ccc[500];
/************************************************************************/
int uout=0;
long int longacc=0;
int prestate=0,erstate=0;
int iiref=0;
/*******************************************
保护程序
************************************************/
void prevent()
{
disable();
*MCRA=0X0C03F; //输出禁止
*PADATDIR=0x0ff00;
*PBDATDIR=0x0ff00;
/////////////////////////////////
*MCRC=*MCRC&0X0FF81; //逆变器PWM输出禁止
*PEDATDIR=0x0ff00;
kickdog();
for(;;)
{ kickdog(); }
}
/*****************************************************
移位说明:
占空比是桥臂电压电压和直流母线电压的比值,并且直流电压比桥臂电压高一位
因此,vdc如果是Q4,invdc就是Q11,
******************************************************/
interrupt void ADC()
{
long int longtemp;
int temp,temp1;
kickdog();
//port00=1000;
if(count>=N)
{ count=0;
}
if(invcount>=N)
{ invcount=0;}
/************************整流器***********************/
ibackstation.angle=anglematrix[count];
ibackrotate.angle=anglematrix[count];
irefrotate.angle=anglematrix[count];
irefstation.angle=anglematrix[count];
dqrotate.angle=anglematrix[count];
dqstation.angle=anglematrix[count];
gridstation.angle=anglematrix[count];
erotate.angle=anglematrix[count];
count++;
/************************逆变器*********************/
invibacksta.angle=anglematrix[invcount];
invibackrot.angle=anglematrix[invcount];
invirefrot.angle=anglematrix[invcount];
invirefsta.angle=anglematrix[invcount];
invdqrotate.angle=anglematrix[invcount];
invdqstation.angle=anglematrix[invcount];
invcount++;
/////////////////////////////////////////////////
if (udc<2000)
{
*MCRA=*MCRA&0X0F03F; //逆变桥PWM输出禁止
*PADATDIR=0x0C000;
*PBDATDIR=0x0F00;
/////////////////////////////////////////////////
/////////////////////////////////////////////////
*MCRC=*MCRC&0X0FF81; //整流器PWM输出禁止
*PEDATDIR=0x0ff00;
/***************************************/
cdpi.out=0;
cdpi.pid_e1_reg1=0;
cdpi.pid_e2_reg1=0;
cqpi.out=0;
cqpi.pid_e1_reg1=0;
cqpi.pid_e2_reg1=0;
invcdpi.out=0;
invcdpi.pid_e1_reg1=0;
invcdpi.pid_e2_reg1=0;
invcqpi.out=0;
invcqpi.pid_e1_reg1=0;
invcqpi.pid_e2_reg1=0;
}
/*******************************************************************
采样用标么值的方法,并选用一倍裕量,
电流采样最大值:
3.3V----65536
16.5A---32767 实测: 6000-->3.8A
考虑裕量:
16.5A---16383 15A< 14500
交流侧电压采样:
3.3v----65536
330v----32767
右移一位:
330v----16384 实测: 4000-->50V
直流侧电压采样:
3.3V----65536
1320v---65536
右移一位:
1320V---32767 660-----16384
实测: 5000-->178V
**********************************************************************/
asm(" clrc SXM"); //disable sxm
iback.a=*RESULT0>>1; //Ia 1/10
iback.b=*RESULT1>>1; //Ib 1/10
iback.c=*RESULT2>>1; //Ic 1/10
udc=*RESULT3>>1; //udc 1/200
grid.a=*RESULT4>>1; //ea
grid.b=*RESULT5>>1; //eb
grid.c=*RESULT6>>1; //ec
/////////////////////////
inviback.a=*RESULT9>>1; //inviback
inviback.b=*RESULT10>>1; //inviback
asm(" setc SXM");
iback.a-=16870;
iback.b-=16664;
iback.c-=16620;
grid.a-=16410;
grid.b-=16400;
grid.c-=16550;
/***********************************************/
temp=(iback.a>>1)+(iback.b>>1)+(iback.c>>1);
temp1=(int)((long)temp*10922>>14);
iback.a-=temp1;
iback.b-=temp1;
iback.c-=temp1;
port00=(iback.a>>3)+2000;
//port01=(iback.b>>3)+2000;
//port02=(iback.c>>3)+2000;
//port03=(temp1)+2000;
/***********************************************/
//port00=(grid.a>>3)+2000;
//port01=(grid.b>>3)+2000;
//port02=(grid.c>>3)+2000;
temp=(grid.a>>1)+(grid.b>>1)+(grid.c>>1);
temp1=(int)((long)temp*10922>>14);
grid.a-=temp1;
grid.b-=temp1;
grid.c-=temp1;
//port01=(grid.a>>3)+2000;
//port01=(grid.b>>3)+2000;
//port02=(grid.c>>3)+2000;
//port03=(temp1)+2000
评论1