⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inv_start.c

📁 SVPWM算法的DSP源码已通过硬件验证
💻 C
字号:
// TI File $Revision: /main/2 $
// Checkin $Date: March 18, 2009   15:48:25 $
//###########################################################################
//
// FILE:   pv20k_Start.c
//
// TITLE:  
//
// ASSUMPTIONS:
//
//   This program requires the DSP2803x header files.
//
//   Make sure the CPU clock speed is properly defined in
//   DSP2803x_Examples.h before compiling this example.
//
//    $Boot_Table:
//
//    While an emulator is connected to your device, the TRSTn pin = 1,
//    which sets the device into EMU_BOOT boot mode. In this mode, the
//    peripheral boot modes are as follows:
//
//      Boot Mode:       EMU_KEY        EMU_BMODE
//                       (0xD00)	     (0xD01)
//      ---------------------------------------
//      Wait             !=0x55AA        X
//      I/O              0x55AA	         0x0000
//      SCI              0x55AA	         0x0001
//      Wait             0x55AA	         0x0002
//      Get_Mode         0x55AA	         0x0003
//      SPI              0x55AA	         0x0004
//      I2C              0x55AA	         0x0005
//      OTP              0x55AA	         0x0006
//      eCANA            0x55AA	         0x0007
//      SARAM            0x55AA	         0x000A	  <-- "Boot to SARAM"
//      Flash            0x55AA	         0x000B
//      Wait             0x55AA          Other
//
//   Write EMU_KEY to 0xD00 and EMU_BMODE to 0xD01 via the debugger
//   according to the Boot Mode Table above. Build/Load project,
//   Reset the device, and Run example
//
//   $End_Boot_Table
//
//
// Description:
//
//   This example sets up the PLL in x12/2 mode.
//
//   For 60 MHz devices (default)
//   (assuming a 10Mhz input clock).
//
//###########################################################################
// $TI Release: DSP2803x C/C++ Header Files V1.10 $
// $Release Date: July 27, 2009 $
//###########################################################################

#include	"DSP280x_Device.h"
#include	"DSP280x_Examples.h"    // Device Headerfile and Examples Include File
#include "IQmathLib.h"
#include    "Global.h"
#define	NONE	0
#define	BEGIN	0XAAAA
#define	OVER	0

#define OK_1S	1




void	vTimer0Pro(void);
void	vBeginOpr(void);
void	vStopOpr(void);
void	vPid(void);
void	vInvCon(void);


extern	void	vSetVf(void);
extern	void	vSetDatForSt(void);
//extern 	void	vClearCnt(void);


									// half period of carrier = 1/fc/2/10*10^9
									//   1.44k  2.1k    3k   3.9k   4.8k  6k   7.2k  8.1k   9k  10.2k  11k   12k  13.2k  14k   15k   16k
const	Uint16	uiHalfCarrTab[17] = {0,  20833,14286, 10000, 7692, 6250, 5000, 1389, 4157, 3333, 2941, 2727, 2500, 2273,2143, 2000,3125};
									// electric angle per carrier period = 3600*2^18/100/fc
const	Uint16	uiCalDatTab[17] = {0,    6553 ,4494,   3146, 2420, 1968, 1575, 1312, 1167, 1050, 926 , 856,  787 , 716,  673, 629,  590};

const	Uint16	uiSetParaHTab[30] = {1,5300,5000,380, 99,1,16,460,500,100, 1,3,300,3000,100,500,100,1,99,80,11,100,100,100,100,1,1,2,380,100};
const	Uint16	uiSetParaLTab[30] = {0,5000,4700,220, 50,0, 6,400, 100 ,0, 0,0, 0,   0,  0, 1,   0 ,0,85,10,1, 0,  0 , 0,  0,  0,0,0, 0,  1};


void	vBeginOpr(void)
{
	DINT;

	RunState.uiRun = RUNNING;
	RunState.uiSoftStart = BEGIN;
	

	OutputVar.uiTargetVolt = SetPara.uiPreVolt;
	OutputVar.uiCurrFreq = SetPara.uiMinFreq;

	// Enable dead-band
	EPwm1Regs.DBCTL.all = 0x000B;
	EPwm2Regs.DBCTL.all = 0x000B;
	EPwm3Regs.DBCTL.all = 0x000B;

	// Enable output on A and B
	EPwm1Regs.AQCSFRC.all = 0xf;
	EPwm2Regs.AQCSFRC.all = 0xf;
	EPwm3Regs.AQCSFRC.all = 0xf;

	EINT;
}


void	vStopOpr(void)
{
	DINT;
	// Clear running flag
	RunState.uiRun = STOP;
	RunState.uiRunning = STOP;

	// Disable dead-band to ensure EPWMA and EPWMB output low
	EPwm1Regs.DBCTL.all = 0x0000;
	EPwm2Regs.DBCTL.all = 0x0000;
	EPwm3Regs.DBCTL.all = 0x0000;

	// Force low on A and B
	EPwm1Regs.AQCSFRC.all = 0x5;
	EPwm2Regs.AQCSFRC.all = 0x5;
	EPwm3Regs.AQCSFRC.all = 0x5;

	EINT;

//	vClearCnt();
	vSetDatForSt();
//	vSetVf();
}

void vTimer0Pro()
{

     static	Uint16 	uiCnt1000 = 0;
	if (CpuTimer0Regs.TCR.bit.TIF == 1)
	{
		//if	(RunState.uiRun == RUNNING)
		//{
		//	vInvCon();
		//}
		     
		uiCnt1000++;
		if (uiCnt1000 >=  200)
		{
			uiCnt1000 = 0;
			uiCnt1S = OK_1S;
		}
		uiTime1ms = 1;
        uiPidCnt++;  
	}	
	
    // Acknowledge this interrupt to receive more interrupts from group 1
	CpuTimer0Regs.TCR.bit.TIF = 1;
	PieCtrlRegs.PIEACK.bit.ACK1 = 1;
}


void vInvCon(void)
{   
    
	if (RunState.uiRun == RUNNING)
	{
		if (OutputVar.uiCurrFreq < OutputVar.uiTargetFreq)
		{
			if(0<(OutputVar.uiTargetFreq - OutputVar.uiCurrFreq) <10)
			{
				OutputVar.uiCurrFreq += 0;
			} 
			else if((OutputVar.uiTargetFreq - OutputVar.uiCurrFreq) <30)
			{
				OutputVar.uiCurrFreq += 1;
			}
			else if((OutputVar.uiTargetFreq - OutputVar.uiCurrFreq) <60) // increase frequency
			{
				OutputVar.uiCurrFreq += 2;
			}
			else
			{
				OutputVar.uiCurrFreq += 3;
			}
			// get new phase
			PhaseSector.ulPhaseNew = (Uint32)OutputVar.uiCurrFreq * (Uint32)PhaseSector.uiCalDat / 4;
		//
		}
		else if (OutputVar.uiCurrFreq > OutputVar.uiTargetFreq)
		{
			if(0<(OutputVar.uiCurrFreq - OutputVar.uiTargetFreq) <10)
			{
				OutputVar.uiCurrFreq -= 0;
			} 
			else if((OutputVar.uiCurrFreq - OutputVar.uiTargetFreq) <30)
			{
				OutputVar.uiCurrFreq -= 1;
			}
			else if((OutputVar.uiCurrFreq - OutputVar.uiTargetFreq) <60) // increase frequency
			{
				OutputVar.uiCurrFreq -= 2;
			}
			else
			{
				OutputVar.uiCurrFreq -= 3;
			}
			
		
		}
    	PhaseSector.ulPhaseNew = (Uint32)OutputVar.uiCurrFreq * (Uint32)PhaseSector.uiCalDat / 4;
	}
}
   /*if (RunState.uiRun == RUNNING)
	{
		int32	lPidTemp1;
		Uint16	uiPidTemp1;
    
	                  
	                  
		PidRegs.lPidEk3 = (int32)OutputVar.uiTargetFreq - (int32)OutputVar.uiCurrFreq;
	
	// PID输入:目标电压和反馈电压的差值
   // PidRegs.lPidEk = (int32)OutputVar.uiTargetVolt - 180;
		if(( abs(PidRegs.lPidEk3) < SetPara.uiErrGap)&&(abs(PidRegs.lPidEk3) > 0))
		{
		// Pid control
			lPidTemp1 = (PidRegs.lKp * PidRegs.lPidEk3 + PidRegs.lKi * PidRegs.lPidEk4 + PidRegs.lPidEk5) >> 7;
		}
		else if(abs(PidRegs.lPidEk3) >= SetPara.uiErrGap)
		{
		// Only P control
			lPidTemp1 = (PidRegs.lKp * PidRegs.lPidEk3) >> 7;
		}
    	else if(abs(PidRegs.lPidEk3) == 0 )
		{
			lPidTemp1 = 0 ;
		}
		uiPidTemp1 = (Uint16)lPidTemp1 + OutputVar.uiCurrFreq;//PID输出
		uiPidTemp1 = (uiPidTemp1 > OutputVar.uiPidOutMax) ? OutputVar.uiPidOutMax : uiPidTemp1;
		OutputVar.uiCurrFreq = (uiPidTemp1 > OutputVar.uiPidOutMin) ? uiPidTemp1 : OutputVar.uiPidOutMin;
    
	// reserve ek
		PidRegs.lPidEk4 = PidRegs.lPidEk3;
		PidRegs.lPidEk5 = PidRegs.lPidEk4;
		PhaseSector.ulPhaseNew = (Uint32)OutputVar.uiCurrFreq * (Uint32)PhaseSector.uiCalDat / 4;
	}

}
*/
void vSetVf(void)
{   
   
	if(RunState.uiRun == 0xAAAA)
	{
		if (SetPara.uiPidObj == NONE)
		{
		// open-loop control
		PhaseSector.uiVfCoeff = SetPara.uiVm * PhaseSector.uiPrdHCarr / 100;
		}
		else
		{
		// pid close-loop control
			if (RunState.uiSoftStart == BEGIN)
			{
			// soft start
				if (OutputVar.uiCurrVolt <= 100)
				{   
			   		if( uiSoftStartCnt >= 50)
			   		{ 
			   			OutputVar.uiCurrVolt  +=10;
					
						uiSoftStartCnt = 0;

			   		}				 				
				}
				else
				{
					OutputVar.uiCurrVolt = 100;
					
				
               // OutputVar.uiTargetVolt = uiRmsSDAvg;
					OutputVar.uiTargetVolt = 200 ;
				
					RunState.uiSoftStart = OVER;
				}	  	    
			}
	    }
		  
	PhaseSector.uiVfCoeff = (Uint16)((Uint32)OutputVar.uiCurrVolt * (Uint32)PhaseSector.uiPrdHCarr / (Uint32)SetPara.uiUoutSet);
   }
}



void vOprCntl()
{
	if (RunState.uiRun == RUN)
	{
		if (RunState.uiRunning == STOP)
		{
			vBeginOpr();
		}
		RunState.uiRunning = RUN;

		if (uiPidCnt >= SetPara.uiPidT)
		{
			uiPidCnt = 0;
           
			
            //OutputVar.uiCurrVolt = uiRmsNBAvg;
            //OutputVar.uiCurrVolt = 100;
            //OutputVar.uiTargetVolt = uiRmsSDAvg;
         OutputVar.uiRealVolt = uiRmsNBU;
           // OutputVar.uiRealVolt = 200;
			//OutputVar.uiTargetVolt = 220;
		OutputVar.uiTargetVolt = uiRmsSDU;
			
			vPid();            		
		}
	}
	else
	{
		vStopOpr();
	}
	
}


//-----------------------------------End of file------------------------------------


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -