📄 vsi_control.c
字号:
//
//###########################################################################
//
// FILE: VSI_Control.c
//
// TITLE: Control Program for Single-Phase Voltage Source Inverter
//
// DESCRIPTION:
//
// This program is to control single-phase inverter, repetitive control
// and predictive control method are adopted.
//
//
//
//
//###########################################################################
//
// Ver | dd mmm yyyy | Who | Description of changes
// =====|=============|=========|===============================================
// 0.50| 01 May 2002 | T.CHEN. | for TMX320F2812
// 1.00| 02 Nov 2003 | T.CHEN. | for TMP320F2812
//###########################################################################
// Step 0. Include required header files
// DSP28_Device.h: device specific definitions #include statements for
// all of the peripheral .h definition files.
// DSP28_Example.h is specific for the given example.
#include "DSP281x_Device.h"
#include "DSP281x_Examples.h" // DSP281x Examples Include File
#include "IQMathLib.h"
#include "DSP281x_Fonts.h"
// Control function software module
// repetitive control parameters
/*
#define kn1 143 // 0.0699 转折频率4500rad/s
#define kn2 107 // 0.0524
#define km1 2664 // 1.301
#define km2 -867 // -0.4232
*/
#define kn1 250 // 0.1219 转折频率6000rad/s
#define kn2 167 // 0.0817
#define km1 2248 // 1.09762
#define km2 -617 // -0.3012
//#define LCDDATAADD 0x80004
//#define LCDCMDADD 0x80005
#define WAIT_LCD_IDLE delay()
#define LCD_NOP lcd_nop()
// Serial Communications Interface software module
// Man-Machine Interface software module
//* Control software module variable define
unsigned int const LcdInitSYS[8]={0x30,0x87,0x07,0x27,0x39,0xef,0x28,0x00};
unsigned int const LcdInitSCR[10]={0x00,0x00,0xef,0x00,0x30,0xef,0x00,0x00,0x00,0x00};
struct CTR_VARS {
int reset_lock;
int Udc;
int Udc_offset;
int Udc_prescale; // amplify 2^10 times
int Udc_uplimit;
int Udc_lowlimit;
int Udc_aver;
int long Udc_sum;
int Vs;
int Vs_offset;
int Vs_prescale; // amplify 2^10 times
int sinwt; // sinusoid function
int coswt;
int Vs_sinwt_main; // the peak-value of Vs
int long Vs_sinwt_sum; // used to calculate peak-value of Vs
int Vs_rms_ref; // the reference output voltage is Vs_rms_ref*sinwt
int long Vs_sum_20ms; // used to calculate DC component of Vs
int rep[f_point]; // repetitive control variables
int Vyk;
int Vyks1;
int pid_Vyks1; // predictive-PID control variables
int pid_Vyks2;
int Ic;
int Ic_offset; // the sample value of analog signal
int Ic_prescale; // amplify 2^10 times
int long Ic_sum_20ms; // used to calculate DC component of Ic
int Ic_coswt_main;
int long Ic_coswt_sum;
int Il;
int Il_offset; // the sample value of analog signal
int long Il_sum_20ms; // used to calculate DC component of Il
int pianci;
int Il_sinwt_main; // the peak-value of Il
int long Il_sinwt_sum; // used to calculate peak-value of Il
int factor_tmp;
int pre_factor; // feedforward value
int start;
int fault; // indicate the fault status
int run_led; // used to control the flash of run-lamp
int run_stop;
int pwm_enable;
int t2ufint_counter;
int long sum_counter; // used to calculate phase
int thirtysecond;
int KeyValue;
int Udc_low_fault;
int Udc_high_fault;
int Il_fault;
int short_circuit;
int Vs_fault;
int pianci_rec;
};
volatile struct CTR_VARS CtrVars;
//** SCI software variable define
struct SCIA_VARS {
int i;
// int xxx[5];
};
volatile struct SCIA_VARS SciaVars;
struct SCIB_VARS {
int test;
};
volatile struct SCIB_VARS ScibVars;
_iq30 *sintab_pointer;
int tmp[f_point];
// Prototype statements for functions found within this file.
interrupt void eva_t2ufint_isr(void);
interrupt void eva_capint1_isr(void);
interrupt void eva_capint2_isr(void);
interrupt void sciarxint_isr(void);
interrupt void scibrxint_isr(void);
interrupt void xnmi_isr(void);
void initvariable(void); // initialize variables
char * lpstr =(char *)0x80000;
unsigned char ch;
long int count=0;
unsigned int delay()
{
unsigned int i;
unsigned int j;
for(i=0;i<0x3f;i++)
j=i;
return j;
}
unsigned int lcd_nop()
{
unsigned int i=0;
unsigned int j=0;
for(i=0;i<0xf;i++)
j += i;
return j;
}
void OutLCDCmd(unsigned int data)
{
//WAIT_LCD_IDLE;
(*(char *)(lpstr+1))=0x7c;
(*(char *)(lpstr+1))=0x5c;
LCDCMDADD = data;
//LCD_NOP;
(*(char *)(lpstr+1))=0x54;
LCD_NOP;
(*(char *)(lpstr+1))=0x5c;
LCD_NOP;
(*(char *)(lpstr+1))=0x7c;
}
void OutLCDData(unsigned int data)
{
// WAIT_LCD_IDLE;
(*(char *)(lpstr+1))=0x6c;
(*(char *)(lpstr+1))=0x4c;
LCDDATAADD = data;
// LCD_NOP;
(*(char *)(lpstr+1))=0x44;
LCD_NOP;
(*(char *)(lpstr+1))=0x4c;
LCD_NOP;
(*(char *)(lpstr+1))=0x6c;
}
void AdjustContrast(void)
{
unsigned char i;
// (*(char*)lpstr) = 0xf0;
(*(char*)lpstr) = 0xf4;
for(i=0;i<2;i++)
{
(*(char*)lpstr) = 0x08;
WAIT_LCD_IDLE;
(*(char*)lpstr) = 0xfc;
}
}
void ClearLCDLay1()
{
unsigned int i=0;
OutLCDCmd(0X46);
WAIT_LCD_IDLE;
OutLCDData(0X00);
WAIT_LCD_IDLE;
OutLCDData(0X00);
WAIT_LCD_IDLE;
OutLCDCmd(0X4C);
WAIT_LCD_IDLE;
OutLCDCmd(0X42);
WAIT_LCD_IDLE;
for(i=0;i<0x2fff;i++)
{
OutLCDData(0X00);
// OutLCDData(0Xff);
WAIT_LCD_IDLE;
}
}
void ClearLCDLay2()
{
unsigned int i=0;
OutLCDCmd(0X46);
WAIT_LCD_IDLE;
OutLCDData(0X00);
WAIT_LCD_IDLE;
OutLCDData(0X30);
WAIT_LCD_IDLE;
OutLCDCmd(0X4C);
WAIT_LCD_IDLE;
OutLCDCmd(0X42);
WAIT_LCD_IDLE;
for(i=0;i<0x3000;i++)
{
OutLCDData(0X00);
// OutLCDData(0Xf0);
WAIT_LCD_IDLE;
}
}
/*
void InitLCD1335()
{
unsigned int i=0;
OutLCDCmd(0x40);
for(i=0;i<8;i++)
OutLCDData(LcdInitSYS[i]);
OutLCDCmd(0x44);
for(i=0;i<10;i++)
OutLCDData(LcdInitSCR[i]);
OutLCDCmd(0x5a);//设置点单元卷动位置
OutLCDData(0x00);
OutLCDCmd(0x5b);//设置显示合成方式
OutLCDData(0x01);
OutLCDCmd(0x58);//设置显示开关
// OutLCDData(0x16);
OutLCDData(0x56);
OutLCDCmd(0X4C);
// ClearLCDLay1();
// ClearLCDLay2();
OutLCDCmd(0x46);//设置指针位置
OutLCDData(0x00);
OutLCDData(0x00);
OutLCDCmd(0x5d);//设置光标形状
// OutLCDData(0x01);
OutLCDData(0x04);
OutLCDData(0x86);
OutLCDCmd(0x59);//设置显示开关
OutLCDCmd(0x4c);
OutLCDCmd(0x42);
OutLCDData(0x45);
OutLCDData(0x50);
OutLCDData(0x53);
OutLCDData(0x4f);
OutLCDData(0x4e);
OutLCDData(0x17);
}
*/
void InitLCD1335()
{
unsigned int i=0;
OutLCDCmd(0x40);
for(i=0;i<8;i++)
OutLCDData(LcdInitSYS[i]);
OutLCDCmd(0x44);
for(i=0;i<10;i++)
OutLCDData(LcdInitSCR[i]);
OutLCDCmd(0x5a);//设置点单元卷动位置
OutLCDData(0x00);
OutLCDCmd(0x5b);//设置显示合成方式
OutLCDData(0x01);
OutLCDCmd(0x58);//设置显示开关
OutLCDData(0x16);
OutLCDCmd(0X4C);
ClearLCDLay1();
ClearLCDLay2();
OutLCDCmd(0x46);//设置指针位置
OutLCDData(0x00);
OutLCDData(0x00);
OutLCDCmd(0x5d);//设置光标形状
OutLCDData(0x01);
OutLCDData(0x86);
OutLCDCmd(0x59);//设置显示开关
OutLCDData(0x17);
}
//-------------在固定位置输出点------
void PutPixelLCD(unsigned int PositionX,unsigned int PositionY,unsigned int Pixel)
{
unsigned int TempValue=0;
unsigned char LCDInfo=0;
TempValue=PositionX;
PositionX=320-PositionY-1;
PositionY=TempValue;
TempValue=40*PositionY+PositionX/8+0x3000;
OutLCDCmd(0X46);
WAIT_LCD_IDLE;
OutLCDData(TempValue&0xff);
WAIT_LCD_IDLE;
OutLCDData((TempValue>>8)&0xff);
WAIT_LCD_IDLE;
OutLCDCmd(0X4c);
WAIT_LCD_IDLE;
OutLCDCmd(0X43);
WAIT_LCD_IDLE;
LCDInfo=(*(unsigned char *)LCDCMDADD);
LCDInfo=0;
switch(PositionX%8)
{
case 0:
{
if(Pixel)
LCDInfo=LCDInfo|0x80;
else
LCDInfo=LCDInfo&0x7f;
break;
}
case 1:
{
if(Pixel)
LCDInfo=LCDInfo|0x40;
else
LCDInfo=LCDInfo&0xbf;
break;
}
case 2:
{
if(Pixel)
LCDInfo=LCDInfo|0x20;
else
LCDInfo=LCDInfo&0xdf;
break;
}
case 3:
{
if(Pixel)
LCDInfo=LCDInfo|0x10;
else
LCDInfo=LCDInfo&0xef;
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -