TI中文支持网
TI专业的中文技术问题搜集分享网站

TMS320F28034 PCMC斩波问题

在使用TMS320f28034这款芯片的单周期斩波功能,遇到了一些问题如下:

        ePWM的频率设置为20kHZ;ePWM1,ePWM2,ePWM3同步;ePWM1A和ePWM2A驱动全桥,控制逆变电源(ePWM1B和ePWM2B不使用);ePWM3A和ePWM3B用来做斜波补偿,和电流反馈信号一起从Comp1的一个端口进入,Comp1的另一个端口为软件计算的值写入DACVAL,对ePWM1A,ePWM2A进行斩波。现在发现在一个ePWM周期内出现多次斩波的现象。见附件。
下图通道1为全桥驱动;通道2为ePWM1A(最大占空比设置为50%);通道3为ePWM2A(最大占空比设置为50%);通道4为ePWM3A(占空比设置为50%)和ePWM3B(占空比设置为50%)+反馈电流;a b之间为一个周期。
//###########################################################################
//
// FILE:DSP2803x_Comp.c
//
// TITLE:DSP2803x Comparator Initialization & Support Functions.
//
//###########################################################################
// $TI Release: F2803x C/C++ Header Files and Peripheral Examples V127 $
// $Release Date: March 30, 2013 $
//###########################################################################

#include "DSP2803x_Device.h"// DSP2803x Headerfile Include File
#include "DSP2803x_Examples.h"// DSP2803x Examples Include File


void InitCompDriver(void);
void InitCompGpio(void);
void InitComp(void);

void InitComp(void)
{

	InitCompGpio();
	InitCompDriver();

}


void InitCompGpio()
{InitComp1Gpio();
}

void InitComp1Gpio()
{EALLOW;GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1;// Disable pull-up for GPIO1 (CMP1OUT)GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 3;// Configure GPIO1 for CMP1OUT operationGpioCtrlRegs.AIOMUX1.bit.AIO2 = 2;// Configure AIO2 for CMP1A (analog input) operationSysCtrlRegs.PCLKCR3.bit.COMP1ENCLK = 1;//EDIS;
}

#if DSP28_COMP2
void InitComp2Gpio()
{EALLOW;GpioCtrlRegs.AIOMUX1.bit.AIO4 = 2;// Configure AIO4 for CMP2A (analog input) operationEDIS;
}

#endif //end DSP28_COMP2

#if DSP28_COMP3
void InitComp3Gpio()
{EALLOW;GpioCtrlRegs.AIOMUX1.bit.AIO6 = 2;// Configure AIO6 for CMP3A (analog input) operationEDIS;
}

#endif //end DSP28_COMP3




/**********************************************************************************/
//函数名:void IntiCompDriver(void);
//功能:比较器模块初始化
//备注:
/*********************************************************************************/
void InitCompDriver()
{EALLOW;SysCtrlRegs.PCLKCR3.bit.COMP1ENCLK = 1;// Enable clock to the Comparator 1 blockComp1Regs.DACVAL.bit.DACVAL = 300;//C_CTCurr_Pro;Comp1Regs.COMPCTL.bit.COMPDACEN = 1;// Power up Comparator 1 locallyComp1Regs.COMPCTL.bit.COMPSOURCE = 0;Comp1Regs.COMPCTL.bit.CMPINV = 0;Comp1Regs.COMPCTL.bit.QUALSEL = 6;Comp1Regs.COMPCTL.bit.SYNCSEL =1;EDIS;
}


//===========================================================================
// End of file.
//===========================================================================
-----------------------------------以上为DSP2803x_Comp.c----------------------------------------------------------------
//**************************************************************************
//	Copyright(c)2017-DR_Welding
//	文件名称	:	WPCM2315CU2_Isr.c
//	作者		:	
//	模块功能	:系统中断
//	局部函数列表: 	无
//  更改记录	:
//	日期		DR版本		作者		备注
//	
//**************************************************************************

#define		in_interrupt

#include	"DSP2803x_Header.h"// Headerfile Include File
#include	"WPPM3312M2_Isr.h"
#include	"WPPM3312M2_SysReg.h"
#include	"WPPM3312M2_SysMacro.h"
#include	"WPPM3312M2_GlobalVarDef.h"
#include	"WPPM3312M2_EepromDriver.h"
#include	"WPPM3312M2_Can.h"
#include	"WPPM3312M2_Struct.h"
//#include"WPPM3312M2_LedShow.h"
#include"WPPM3312M2_KeyDispose.h"

//============================
//		内部函数声明
//============================
void vPwm1IntIsr(void);
void vTimer0IntIsr(void);
void IsrVarInit(void);

//******************************************************************
// 函数名	:void InitInterrupt(void)
// 作者		:
// 功能		:中断模块初始化
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	
//******************************************************************
void InitInterrupt(void)
{EALLOW;  	
	// 定义PWM1的中断向量PieVectTable.EPWM1_INT = &vPwm1IntIsr;PieCtrlRegs.PIEIER3.bit.INTx1 = 1;IER |= M_INT3;EDIS;  
}
//******************************************************************
// 函数名	:void vPwm1IntIsr(void)
// 作者		:
// 功能		:主拓扑PWM中断
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	
//******************************************************************
interrupt void vPwm1IntIsr(void)
{	
	//========= 更新主功率移相角=========mEnablePowerPwm();
	mSetPwm1Duty(1500);		
	PidLogic();//PI处理	

//======================== 清中断标志并再次使能中断 ===========================	
	EPwm1Regs.ETCLR.bit.INT = 1;
	PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;	
}

/****************************************************************************/
//函数名:void PidUpGrading(int PidResult);
// 作者		:MaKe
//功能:比较器模块更新PID计算结果
// 参数		:PidResult :PID计算结果
// 祷?:无
// 调用全局变量:无
// 修改全局变量:无
//备注:2018.06.29
/************************************************************************/
void PidUpGrading(int PidResult)
{EALLOW;Comp1Regs.DACVAL.bit.DACVAL = PidResult;	//C_CTCurr_Pro;//原边过流保护点EDIS;
}
------------------------------以上为WPCM2315CU2_Isr.c------------------------------------------------------------------------------//**************************************************************************
//	***
//	文件名称	:	DSP2803x_EPwm.c
//	作者		:	
//	模块功能	:DSP2803x EPwm Initialization & Support Functions.
//	局部函数列表: 	无
//	版本信息	:	TI File $Revision: /main/3 $
// 					Checkin $Date: November 10, 200914:05:11 $
//					$TI Release: 2803x C/C++ Header Files V1.21 $
// 					$Release Date: December 1, 2009 $
//  更改记录	:
//**************************************************************************


#include	"DSP2803x_Header.h"// Headerfile Include File
#include	"WPPM3312M2_SysMacro.h"
#include	"WPPM3312M2_SysReg.h"
#include	"DSP2803x_Device.h"




//============================
//		内部函数声明
//============================
void InitEPwmGpio(void);
void InitEPwm1Gpio(void);
void InitEPwm2Gpio(void);
void InitEPwm3Gpio(void);
void InitEPwm4Gpio(void);
void InitEPwm5Gpio(void);
void InitEPwm6Gpio(void);
void InitEPwm7Gpio(void);

void InitEPwmDriver(void);
void InitEPwm1Driver(void);
void InitEPwm2Driver(void);
void InitEPwm3Driver(void);
void InitEPwm4Driver(void);
void InitEPwm5Driver(void);
void InitEPwm6Driver(void);
void InitEPwm7Driver(void);

void InitTzGpio(void);
void InitTzDriver(void);
void InitDCEventDriver(void);

//******************************************************************
// 函数名	:void InitEPwm(void)
// 作者		:TI
// 功能		:初始化系统PWM模块及管脚设置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
void InitEPwm(void)
{
	// 配置管脚功能

	EALLOW;
	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;  
	EDIS;

	InitEPwmGpio();
//	InitTzGpio();
	// 初始化寄存器

//	InitTzDriver();
//	InitDCEventDriver();
	InitEPwmDriver();
	//mUpDatePwm2Phase(0);
	mUpDatePwm2Phase(1500);
	//mSetPwm4BDuty(0);

	mDisablePowerPwm();
	mDisableMotorPWM();

	mEnableMotorPWM();//////使能PWM3
//	mDisableJRFPWM();
//	mDisableFANPWM();

//	mDebugPWM(1000);  

	EALLOW;
	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;  
	EDIS;  
}


//******************************************************************
// 函数名	:void InitEPwmDriver(void)
// 作者		:TI
// 功能		:This function initializes GPIO pins to function as EPwm pins
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	Each GPIO pin can be configured as a GPIO pin or up to 3 different
// 				peripheral functional pins. By default all pins come up as GPIO
// 				inputs after reset.
//******************************************************************
void InitEPwmGpio(void)
{
#if DSP28_EPWM1InitEPwm1Gpio();
#endif // endif DSP28_EPWM1

#if DSP28_EPWM2InitEPwm2Gpio();
#endif // endif DSP28_EPWM2

#if DSP28_EPWM3InitEPwm3Gpio();
#endif // endif DSP28_EPWM3

#if DSP28_EPWM4// InitEPwm4Gpio();
#endif // endif DSP28_EPWM4

#if DSP28_EPWM5//InitEPwm5Gpio();
#endif // endif DSP28_EPWM5

#if DSP28_EPWM6//InitEPwm6Gpio();
#endif // endif DSP28_EPWM6

#if DSP28_EPWM7//InitEPwm7Gpio();
#endif // endif DSP28_EPWM7
}

//******************************************************************
// 函数名	:void InitEPwm1Gpio(void)
// 作者		:TI
// 功能		:初始化PWM1输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
#if DSP28_EPWM1
void InitEPwm1Gpio(void)
{
	EALLOW;

/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO0 = 1;// Disable pull-up on GPIO0 (EPWM1A)
	GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1;// Disable pull-up on GPIO1 (EPWM1B)

/* Configure EPWM-1 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM1 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1;// Configure GPIO0 as EPWM1A
	GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1;// Configure GPIO1 as EPWM1B

	EDIS;
}
#endif // endif DSP28_EPWM1

//******************************************************************
// 函数名	:void InitEPwm2Gpio(void)
// 作者		:TI
// 功能		:初始化PWM2输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM2
void InitEPwm2Gpio(void)
{
	EALLOW;

/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO2 = 1;// Disable pull-up on GPIO2 (EPWM2A)
	GpioCtrlRegs.GPAPUD.bit.GPIO3 = 1;// Disable pull-up on GPIO3 (EPWM2B)

/* Configure EPwm-2 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM2 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 1;// Configure GPIO2 as EPWM2A
	GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 1;// Configure GPIO3 as EPWM2B

	EDIS;
}
//#endif // endif DSP28_EPWM2

//******************************************************************
// 函数名	:void InitEPwm3Gpio(void)
// 作者		:TI
// 功能		:初始化PWM3输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM3
void InitEPwm3Gpio(void)
{
	EALLOW;

/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.GpioCtrlRegs.GPAPUD.bit.GPIO4 = 1;// Disable pull-up on GPIO4 (EPWM3A)
	GpioCtrlRegs.GPAPUD.bit.GPIO5 = 1;// Disable pull-up on GPIO5 (EPWM3B)

/* Configure EPwm-3 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM3 functional pins.
// Comment out other unwanted lines.GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 1;// Configure GPIO4 as EPWM3A
	GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 1;// Configure GPIO5 as EPWM3B

	EDIS;
}
//#endif // endif DSP28_EPWM3

//******************************************************************
// 函数名	:void InitEPwm4Gpio(void)
// 作者		:TI
// 功能		:初始化PWM4输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM4
void InitEPwm4Gpio(void)
{
	EALLOW;
/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO6 = 1;// Disable pull-up on GPIO6 (EPWM4A)
	GpioCtrlRegs.GPAPUD.bit.GPIO7 = 1;// Disable pull-up on GPIO7 (EPWM4B)

/* Configure EPWM-4 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM4 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 1;// Configure GPIO6 as EPWM4A
	GpioCtrlRegs.GPAMUX1.bit.GPIO7 = 1;// Configure GPIO7 as EPWM4B

	EDIS;
}
//#endif // endif DSP28_EPWM4

//******************************************************************
// 函数名	:void InitEPwm5Gpio(void)
// 作者		:
// 功能		:初始化PWM5输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:EPWM5模块只用到了GPIO9,故只初始化此管脚
//******************************************************************
//#if DSP28_EPWM5
void InitEPwm5Gpio(void)
{
	EALLOW;
/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO8 = 1;// Disable pull-up on GPIO8 (EPWM5A)
	GpioCtrlRegs.GPAPUD.bit.GPIO9 = 1;// Disable pull-up on GPIO9 (EPWM5B)

/* Configure EPWM-5 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM5 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO8 = 1;// Configure GPIO8 as EPWM5A
	GpioCtrlRegs.GPAMUX1.bit.GPIO9 = 1;// Configure GPIO9 as EPWM5B

	EDIS;
}
//#endif // endif DSP28_EPWM5

//******************************************************************
// 函数名	:void InitEPwm6Gpio(void)
// 作者		:TI
// 功能		:初始化PWM6输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM6
void InitEPwm6Gpio(void)
{
	EALLOW;
/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO10 = 1;// Disable pull-up on GPIO10 (EPWM6A)//GpioCtrlRegs.GPAPUD.bit.GPIO11 = 1;// Disable pull-up on GPIO11 (EPWM6B)

/* Configure EPWM-6 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM6 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO10 = 1;// Configure GPIO10 as EPWM6A//GpioCtrlRegs.GPAMUX1.bit.GPIO11 = 1;// Configure GPIO11 as EPWM6B

	EDIS;
}
//#endif // endif DSP28_EPWM6

//******************************************************************
// 函数名	:void InitEPwm7Gpio(void)
// 作者		:TI
// 功能		:初始化PWM7输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM7
void InitEPwm7Gpio(void)
{
	EALLOW;
/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.//GpioCtrlRegs.GPBPUD.bit.GPIO40 = 1;// Disable pull-up on GPIO40 (EPWM7A)
	GpioCtrlRegs.GPBPUD.bit.GPIO41 = 1;// Disable pull-up on GPIO41 (EPWM7B)

/* Configure EPWM-7 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM7 functional pins.
// Comment out other unwanted lines.// GpioCtrlRegs.GPBMUX1.bit.GPIO40 = 1;// Configure GPIO40 as EPWM7A
	GpioCtrlRegs.GPBMUX1.bit.GPIO41 = 1;// Configure GPIO41 as EPWM7B

	EDIS;
}
//#endif // endif DSP28_EPWM7


//******************************************************************
// 函数名	:void InitEPwmSyncGpio(void)
// 作者		:TI
// 功能		:This function initializes GPIO pins to function as EPwm Synch pins
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
void InitEPwmSyncGpio(void)
{

//EALLOW;

/* Configure EPWMSYNCI  */

/* Enable internal pull-up for the selected pins */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

// GpioCtrlRegs.GPAPUD.bit.GPIO6 = 0;// Enable pull-up on GPIO6 (EPWMSYNCI)
	GpioCtrlRegs.GPBPUD.bit.GPIO32 = 0;// Enable pull-up on GPIO32 (EPWMSYNCI)

/* Set qualification for selected pins to asynch only */
// This will select synch to SYSCLKOUT for the selected pins.
// Comment out other unwanted lines.

// GpioCtrlRegs.GPAQSEL1.bit.GPIO6 = 0;// Synch to SYSCLKOUT GPIO6 (EPWMSYNCI)
	GpioCtrlRegs.GPBQSEL1.bit.GPIO32 = 0;  // Synch to SYSCLKOUT GPIO32 (EPWMSYNCI)

/* Configure EPwmSync pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPwmSync functional pins.
// Comment out other unwanted lines.

// GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 2;// Configures GPIO6 for EPWMSYNCI operation
	GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 2;// Configures GPIO32 for EPWMSYNCI operation.

/* Configure EPWMSYNC0  */

/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// Comment out other unwanted lines.

// GpioCtrlRegs.GPAPUD.bit.GPIO6 = 1;// Disable pull-up on GPIO6 (EPWMSYNCO)
	GpioCtrlRegs.GPBPUD.bit.GPIO33 = 1;// Disable pull-up on GPIO33 (EPWMSYNCO)

// GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 3;// Configures GPIO6 for EPWMSYNCO
	GpioCtrlRegs.GPBMUX1.bit.GPIO33 = 2;  // Configures GPIO33 for EPWMSYNCO

}

//******************************************************************
// 函数名	:void InitTzGpio(void)
// 作者		:TI
// 功能		:This function initializes GPIO pins to function as Trip Zone (TZ) pins
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	Each GPIO pin can be configured as a GPIO pin or up to 3 different
// 				peripheral functional pins. By default all pins come up as GPIO
// 				inputs after reset.
//******************************************************************
void InitTzGpio(void)
{
	EALLOW;

/* Enable internal pull-up for the selected pins */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.
	GpioCtrlRegs.GPAPUD.bit.GPIO12 = 0;// Enable pull-up on GPIO12 (TZ1)
// GpioCtrlRegs.GPAPUD.bit.GPIO15 = 0;// Enable pull-up on GPIO15 (TZ1)
	GpioCtrlRegs.GPAPUD.bit.GPIO13 = 0;// Enable pull-up on GPIO13 (TZ2)
// GpioCtrlRegs.GPAPUD.bit.GPIO16 = 0;// Enable pull-up on GPIO16 (TZ2)
// GpioCtrlRegs.GPAPUD.bit.GPIO28 = 0;// Enable pull-up on GPIO28 (TZ2)
	GpioCtrlRegs.GPAPUD.bit.GPIO14 = 0;// Enable pull-up on GPIO14 (TZ3)
// GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0;// Enable pull-up on GPIO17 (TZ3)
// GpioCtrlRegs.GPAPUD.bit.GPIO29 = 0;// Enable pull-up on GPIO29 (TZ3)

/* Set qualification for selected pins to asynch only */
// Inputs are synchronized to SYSCLKOUT by default.
// This will select asynch (no qualification) for the selected pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAQSEL1.bit.GPIO12 = 3;  // Asynch input GPIO12 (TZ1)
// GpioCtrlRegs.GPAQSEL1.bit.GPIO15 = 3;  // Asynch input GPIO15 (TZ1)
	GpioCtrlRegs.GPAQSEL1.bit.GPIO13 = 3;  // Asynch input GPIO13 (TZ2)
// GpioCtrlRegs.GPAQSEL2.bit.GPIO16 = 3;  // Asynch input GPIO16 (TZ2)
// GpioCtrlRegs.GPAQSEL2.bit.GPIO28 = 3;  // Asynch input GPIO28 (TZ2)
	GpioCtrlRegs.GPAQSEL1.bit.GPIO14 = 3;  // Asynch input GPIO14 (TZ3)
// GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3;  // Asynch input GPIO17 (TZ3)
// GpioCtrlRegs.GPAQSEL2.bit.GPIO29 = 3;  // Asynch input GPIO29 (TZ3)


/* Configure TZ pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be TZ functional pins.
// Comment out other unwanted lines.
	GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 1;  // Configure GPIO12 as TZ1
//GpioCtrlRegs.GPAMUX1.bit.GPIO15 = 1;  // Configure GPIO15 as TZ1
	GpioCtrlRegs.GPAMUX1.bit.GPIO13 = 1;  // Configure GPIO13 as TZ2
// GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 3;  // Configure GPIO16 as TZ2
// GpioCtrlRegs.GPAMUX2.bit.GPIO28 = 3;  // Configure GPIO28 as TZ2
	GpioCtrlRegs.GPAMUX1.bit.GPIO14 = 1;  // Configure GPIO14 as TZ3
// GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 3;  // Configure GPIO17 as TZ3
// GpioCtrlRegs.GPAMUX2.bit.GPIO29 = 3;  // Configure GPIO29 as TZ3

	EDIS;

}

//******************************************************************
// 函数名	:void InitEPwmDriver(void)
// 作者		篢I
// 功能		:初始低砅WM模块寄存髋渲?
// 参数		:无
// 	:无
// 调用全局变量?
// 
// 备注
//******************************************************************
void InitEPwmDriver(void)
{ 
//#if DSP28_EPWM1InitEPwm1Driver();
//#endif 

//#if DSP28_EPWM2
	InitEPwm2Driver();
//#endif 

//#if DSP28_EPWM3
	InitEPwm3Driver();
//#endif 

//#if DSP28_EPWM4
	//InitEPwm4Driver();
//#endif 

//#if DSP28_EPWM5
	//InitEPwm5Driver();
//#endif 

//#if DSP28_EPWM6
//	InitEPwm6Driver();
//#endif 

#if DSP28_EPWM7
//	InitEPwm7Driver();
#endif 
}


//******************************************************************
// 函数名	:void InitEPwm1Driver(void)
// 作者		:TI
// 功		:初始化系统ePWM1寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	
//******************************************************************
#if DSP28_EPWM1
void InitEPwm1Driver(void)
{
	EALLOW;	
	EPwm1Regs.TBPRD 	= 3000;////PFSB_PERIOD,1250-48K
	//EPwm1Regs.TBPRD 	= 1500;////PFSB_PERIOD,1250-48K
	EPwm1Regs.TBPHS.all	= 0;
	EPwm1Regs.TBCTR		= 0;

	// Setup TBCLK
	EPwm1Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// Count up
	//EPwm1Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;
	EPwm1Regs.TBCTL.bit.PHSEN		= TB_DISABLE;		// Disable phase loading  
	EPwm1Regs.TBCTL.bit.PRDLD		= TB_SHADOW;		//
	EPwm1Regs.TBCTL.bit.SYNCOSEL	= TB_CTR_ZERO;//Count equal to zero; have a syn output
	EPwm1Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm1Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;			//
	EPwm1Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm1Regs.TBCTL.bit.PHSDIR		= 1; 
	EPwm1Regs.TBCTL.bit.FREE_SOFT	= 3;	//
	// Setup compare 
	EPwm1Regs.CMPA.half.CMPA= 1500;
	EPwm1Regs.CMPB = 1500;
	EPwm1Regs.TBPHS.half.TBPHS = 0;
	// Setup CMPCTL 
	EPwm1Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm1Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm1Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm1Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;/////
	EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;
	EPwm1Regs.AQCTLB.bit.ZRO = AQ_CLEAR;	
	EPwm1Regs.AQCTLB.bit.CBU = AQ_SET;

	//EPwm1Regs.AQSFRC.bit.RLDCSF = 0;

	
	//Set DeadBand
	EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;//
	EPwm1Regs.DBCTL.bit.IN_MODE = 0x0;
	EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
	//EPwm1Regs.DBFED = 200;//
	//EPwm1Regs.DBRED = 200;//
	EPwm1Regs.DBFED = 300;//
	EPwm1Regs.DBRED = 300;// 
	//EPwm1Regs.DBCTL.bit.HALFCYCLE = 1;

	//	// Set ETSEL
	EPwm1Regs.ETSEL.bit.INTSEL	= ET_CTR_ZERO;			// 2:0EPWMxINTn Select
	EPwm1Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable
	EPwm1Regs.ETSEL.bit.SOCASEL	= ET_CTRU_CMPA;			// 10:8Start of conversion A Select  
	EPwm1Regs.ETSEL.bit.SOCAEN	= ET_ENABLE;			// 11Start of conversion A Enable  
	EPwm1Regs.ETSEL.bit.SOCBSEL	= ET_CTRU_CMPB;			// 14:12  Start of conversion B Select	
	EPwm1Regs.ETSEL.bit.SOCBEN	= ET_ENABLE;			// 15Start of conversion B Enable

	EPwm1Regs.ETPS.bit.INTPRD	= ET_1ST;		// 1:0EPWMxINTn Period Select
	EPwm1Regs.ETPS.bit.INTCNT	= 0;		// 3:2EPWMxINTn Counter Register 
	EPwm1Regs.ETPS.bit.SOCAPRD	= ET_1ST;		// 9:8EPWMxSOCA Period Select
	EPwm1Regs.ETPS.bit.SOCACNT	= 0;		// 11:10  EPWMxSOCA Counter Register 
	EPwm1Regs.ETPS.bit.SOCBPRD	= 1;		// 13:12  EPWMxSOCB Period Select
	EPwm1Regs.ETPS.bit.SOCBCNT	= 0;		// 15:14  EPWMxSOCB Counter Register
 ///////////////////////////////////////////////////////EPwm1Regs.TZSEL.bit.DCAEVT2 = 1;//////EPwm1Regs.TZSEL.bit.DCAEVT2 = 0;//////EPwm1Regs.TZSEL.bit.DCBEVT2 = 0;//////EPwm1Regs.TZSEL.bit.DCBEVT2 = 1;EPwm1Regs.TZSEL.bit.CBC1=1;

// What do we want the TZ1 and TZ2 to doEPwm1Regs.TZCTL.bit.TZA = TZ_FORCE_LO;EPwm1Regs.TZCTL.bit.TZB = TZ_FORCE_LO;//EPwm1Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCBH_LOW; //TZ_DCAH_HI;//EPwm1Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCAH_LOW;EPwm1Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_HI;EPwm1Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCAH_HI;EPwm1Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP1OUT;// DCAH = Comparator 2 output
	EDIS;	
}
#endif 


//******************************************************************
// 函数名	:void InitEPwm2Driver(void)
// 作者		:TI
// 功能		初始化系统ePWM2寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	
//******************************************************************
#if DSP28_EPWM2
void InitEPwm2Driver(void)
{	EALLOW;
	//SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;	// Stop all the TB clocks	
	//EPwm2Regs.TBPRD 	= 1874;///48k
	EPwm2Regs.TBPRD 	= 3000;///20k// Count up
	//EPwm2Regs.TBPRD 	= 1500;///20k//Count updown
	EPwm2Regs.TBPHS.all	= 0;
	EPwm2Regs.TBCTR		= 0;

	// Setup TBCLK
	EPwm2Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// Count up
	//EPwm2Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;//Count updown
	EPwm2Regs.TBCTL.bit.PHSEN		= TB_ENABLE;		// Enable phase loading  
	EPwm2Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm2Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_IN;
	EPwm2Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm2Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm2Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm2Regs.TBCTL.bit.PHSDIR		= 1; 
	EPwm2Regs.TBCTL.bit.FREE_SOFT	= 3;				// 


	// Setup compare 
	EPwm2Regs.CMPA.half.CMPA= 1500;//
	EPwm2Regs.CMPB= 1500;//
	EPwm2Regs.TBPHS.half.TBPHS = 0;
	
	// Setup CMPCTL 
	EPwm2Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm2Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm2Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm2Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm2Regs.AQCTLA.bit.ZRO = AQ_SET;
	EPwm2Regs.AQCTLA.bit.CAU = AQ_CLEAR;
	EPwm2Regs.AQCTLB.bit.ZRO = AQ_CLEAR ;
	EPwm2Regs.AQCTLB.bit.CBU = AQ_SET;
	
//	EPwm2Regs.AQSFRC.bit.RLDCSF = 3;

	//Set DeadBand
 	EPwm2Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
	EPwm2Regs.DBCTL.bit.IN_MODE = 0x0;
	EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
	//EPwm2Regs.DBFED = 200 ;//
	//EPwm2Regs.DBRED = 200;
	EPwm2Regs.DBFED = 300;//
	EPwm2Regs.DBRED = 300; 
	////斩波比较模块
	//EPwm2Regs.TZSEL.bit.DCAEVT2 = 1;
	//EPwm2Regs.TZSEL.bit.DCAEVT2 = 0;
	//EPwm2Regs.TZSEL.bit.DCBEVT2 = 0;
	//EPwm2Regs.TZSEL.bit.DCBEVT2 = 1;
	EPwm2Regs.TZSEL.bit.CBC1=1;// What do we want the TZ1 and TZ2 to do?EPwm2Regs.TZCTL.bit.TZA = TZ_FORCE_LO;EPwm2Regs.TZCTL.bit.TZB = TZ_FORCE_LO;//EPwm2Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCBH_LOW;//EPwm2Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCBH_LOW;EPwm2Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_HI;EPwm2Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCAH_HI;EPwm2Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP1OUT; // DCAH = Comparator 2 outputEPwm2Regs.DCACTL.bit.EVT2SRCSEL = DC_EVT2;// DCAEVT2 = DCAEVT2 (not filtered)EPwm2Regs.DCACTL.bit.EVT2FRCSYNCSEL = DC_EVT_ASYNC;// Take async pathEPwm2Regs.TZEINT.bit.DCBEVT2=0;//??
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS;

}
#endif 

//******************************************************************
// 函数名	:void InitEPwm3Driver(void)
// 作者		:TI
// 功能		:初始化系统ePWM3寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM3
void InitEPwm3Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	//EPwm3Regs.TBPRD 			= Motor_PERIOD;
	EPwm3Regs.TBPRD 			= 3000;//1500;//C_MOTOR_PWM_PRD;
	EPwm3Regs.TBPHS.all			= 0;
	EPwm3Regs.TBCTR				= 0;
	EPwm3Regs.TBPHS.half.TBPHS	= 0;

	// Setup TBCLK
	//EPwm3Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;		// Count up
	EPwm3Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// 对称波形输出 
	EPwm3Regs.TBCTL.bit.PHSEN		= TB_DISABLE;// Disable phase loading  
	EPwm3Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	//EPwm3Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_DISABLE;
	EPwm3Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_IN;	//  Count equal to zero; have a syn output
	EPwm3Regs.TBCTL.bit.SWFSYNC		= 0; 
	//EPwm3Regs.TBCTL.bit.HSPCLKDIV	= 0x04;///1/8
	EPwm3Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
//	EPwm3Regs.TBCTL.bit.CLKDIV		= 0x04;///1/16 
	EPwm3Regs.TBCTL.bit.CLKDIV		= TB_DIV1;
	EPwm3Regs.TBCTL.bit.PHSDIR		= 1;
	EPwm3Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compareEPwm3Regs.CMPA.half.CMPA =1500;
	EPwm3Regs.CMPB  = 0;
	// Setup CMPCTL 
	EPwm3Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm3Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm3Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm3Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm3Regs.AQCTLA.bit.CAU = AQ_CLEAR;			// 
	EPwm3Regs.AQCTLA.bit.PRD = AQ_SET;				//  
	EPwm3Regs.AQCTLB.bit.CBU = AQ_SET;				// 
	EPwm3Regs.AQCTLB.bit.PRD = AQ_CLEAR;	// 

	EPwm3Regs.ETSEL.bit.INTSEL	= ET_CTR_PRD;			// 2:0EPWMxINTn Select
	EPwm3Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable
	
/////////////////////////////////////////////////////
	//死区模块(DB)配置
	EPwm3Regs.DBCTL.bit.OUT_MODE =DB_FULL_ENABLE;
	EPwm3Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
	EPwm3Regs.DBCTL.bit.IN_MODE = 0;
	//EPwm3Regs.DBCTL.bit.HALFCYCLE = 0;
	EPwm3Regs.DBFED = 200;//Falling delay
	EPwm3Regs.DBRED = 200;  //Raising delay  //0.01667*300=5U

	// 事件触发模块(EZ)配置
	EPwm3Regs.ETSEL.bit.INTSEL	= ET_CTRD_CMPA;		// 2:0EPWMxINTn Select
	EPwm3Regs.ETSEL.bit.INTEN	= ET_DISABLE;		// 3EPWMxINTn Enable
	EPwm3Regs.ETSEL.bit.SOCASEL	= ET_CTR_ZERO;		// 10:8Start of conversion A Select  
	EPwm3Regs.ETSEL.bit.SOCAEN	= ET_ENABLE;		// 11Start of conversion A Enable  
	EPwm3Regs.ETSEL.bit.SOCBSEL	= ET_CTR_ZERO;		// 14:12  Start of conversion B Select  
	EPwm3Regs.ETSEL.bit.SOCBEN	= ET_ENABLE;		// 15Start of conversion B Enable  

	EPwm3Regs.ETPS.bit.INTPRD = 1;		// 1:0EPWMxINTn Period Select
	EPwm3Regs.ETPS.bit.INTCNT = 0;		// 3:2EPWMxINTn Counter Register 
	EPwm3Regs.ETPS.bit.SOCAPRD = 1;		// 9:8EPWMxSOCA Period Select
	EPwm3Regs.ETPS.bit.SOCACNT = 0;		// 11:10  EPWMxSOCA Counter Register 
	EPwm3Regs.ETPS.bit.SOCBPRD = 1;		// 13:12  EPWMxSOCB Period Select
	EPwm3Regs.ETPS.bit.SOCBCNT = 0;	 	// 15:14  EPWMxSOCB Counter Register 	
	EDIS; 
}
//#endif 
//******************************************************************
// 函数名	:void InitEPwm4Driver(void)
// 作者		:TI
// 功能		:初始化系统ePWM4寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	送丝机H桥驱动
//******************************************************************
//#if DSP28_EPWM4
void InitEPwm4Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	
	EPwm4Regs.TBPRD 			= 1000;
	EPwm4Regs.TBPHS.all			= 0;
	EPwm4Regs.TBCTR				= 0;
	EPwm4Regs.TBPHS.half.TBPHS	= 0;
	
	// Setup TBCLK
	EPwm4Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;	// Count up and down 
	EPwm4Regs.TBCTL.bit.PHSEN		= TB_DISABLE;		// Disable phase loading  
	EPwm4Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm4Regs.TBCTL.bit.SYNCOSEL	= TB_CTR_ZERO;
	EPwm4Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm4Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm4Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm4Regs.TBCTL.bit.PHSDIR		= 1; 
	EPwm4Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compare 
	EPwm4Regs.CMPA.half.CMPA = Motor_PERIOD - 5;
	EPwm4Regs.CMPB = 5;

	// Setup CMPCTL 
	EPwm4Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm4Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm4Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm4Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm4Regs.AQCTLA.bit.CAU =  AQ_SET;					// Set PWM4A
	EPwm4Regs.AQCTLA.bit.CAD =  AQ_CLEAR;
	EPwm4Regs.AQCTLB.bit.CBU = AQ_CLEAR;				// Set PWM4B
	EPwm4Regs.AQCTLB.bit.CBD = AQ_SET;

//	EPwm4Regs.AQSFRC.bit.RLDCSF = 3;

	// Set deadband
//	EPwm4Regs.DBCTL.bit.OUT_MODE = DB_DISABLE;// Dead-band Output Mode Control
//	EPwm4Regs.DBCTL.bit.POLSEL= DB_ACTV_HI;// Polarity Select Control
//	EPwm4Regs.DBCTL.bit.IN_MODE  = DBB_ALL;// Dead Band Input Mode Control
//	EPwm4Regs.DBFED = 100;//Falling delay
//	EPwm4Regs.DBRED = 100;//Raising delay
	
	// Set ETSEL
	EPwm4Regs.ETSEL.bit.INTSEL	= ET_CTRD_CMPB;	// 2:0EPWMxINTn Select
	EPwm4Regs.ETSEL.bit.INTEN	= ET_ENABLE;		// 3EPWMxINTn Enable
	EPwm4Regs.ETSEL.bit.SOCASEL	= ET_CTR_ZERO;		// 10:8Start of conversion A Select
	EPwm4Regs.ETSEL.bit.SOCAEN	= ET_ENABLE;		// 11Start of conversion A Enable
	EPwm4Regs.ETSEL.bit.SOCBSEL	= ET_CTR_ZERO;			// 14:12  Start of conversion B Select  
	EPwm4Regs.ETSEL.bit.SOCBEN	= ET_ENABLE;		// 15Start of conversion B Enable

	EPwm4Regs.ETPS.bit.INTPRD	= ET_1ST;		// 1:0EPWMxINTn Period Select
	EPwm4Regs.ETPS.bit.INTCNT	= 0;			// 3:2EPWMxINTn Counter Register 
	EPwm4Regs.ETPS.bit.SOCAPRD	= ET_1ST;		// 9:8EPWMxSOCA Period Select
	EPwm4Regs.ETPS.bit.SOCACNT	= 0;			// 11:10  EPWMxSOCA Counter Register 
	EPwm4Regs.ETPS.bit.SOCBPRD	= ET_1ST;		// 13:12  EPWMxSOCB Period Select
	EPwm4Regs.ETPS.bit.SOCBCNT	= 0;			// 15:14  EPWMxSOCB Counter Register 
//	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS; 	
}
//#endif 

//******************************************************************
// 函数名	:void InitEPwm5Driver(void)
// 作者		:何志军
// 功能		:初始化系统ePWM5寄存髋渲?
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	送丝机H桥驱动
//******************************************************************
//#if DSP28_EPWM5
void InitEPwm5Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	EPwm5Regs.TBPRD 			= 1000;
	EPwm5Regs.TBPHS.all			= 0;
	EPwm5Regs.TBCTR				= 0;

	// Setup TBCLK
	EPwm5Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;		// Count up
	EPwm5Regs.TBCTL.bit.PHSEN		= TB_ENABLE;	// Disable phase loading  
	EPwm5Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm5Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_IN;
	EPwm5Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm5Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm5Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm5Regs.TBCTL.bit.PHSDIR		= 1; 
	EPwm5Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compare 
	EPwm5Regs.CMPA.half.CMPA = Motor_PERIOD - 5;
	EPwm5Regs.CMPB = 5;

	// Setup CMPCTL 
	EPwm5Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm5Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm5Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm5Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm5Regs.AQCTLA.bit.CAU = AQ_SET;					// Set PWM6A
	EPwm5Regs.AQCTLA.bit.CAD = AQ_CLEAR;
	EPwm5Regs.AQCTLB.bit.CBU = AQ_CLEAR;				// Set PWM6B
	EPwm5Regs.AQCTLB.bit.CBD = AQ_SET;
	
	// set deadband
	// EPwm5Regs.DBCTL.bit.OUT_MODE = DB_DISABLE;// Dead-band Output Mode Control
	// EPwm5Regs.DBCTL.bit.POLSEL= DB_ACTV_HI;// Polarity Select Control
			// EPwm5Regs.DBCTL.bit.IN_MODE  = DBB_ALL;// Dead Band Input Mode Control
	// EPwm5Regs.DBFED = 100;//Falling delay
	// EPwm5Regs.DBRED = 100;//Raising delay

	EPwm5Regs.ETSEL.bit.INTSEL	= ET_CTRD_CMPB;			// 2:0EPWMxINTn Select
	EPwm5Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable
	EPwm5Regs.ETSEL.bit.SOCASEL	= ET_CTR_ZERO;// 10:8Start of conversion A Select  
	EPwm5Regs.ETSEL.bit.SOCAEN	= ET_DISABLE;			// 11Start of conversion A Enable  
	EPwm5Regs.ETSEL.bit.SOCBSEL	= ET_CTR_ZERO;	// 14:12  Start of conversion B Select  
	EPwm5Regs.ETSEL.bit.SOCBEN	= ET_DISABLE;			// 15Start of conversion B Enable  

	EPwm5Regs.ETPS.bit.INTPRD = 1;		// 1:0EPWMxINTn Period Select
	EPwm5Regs.ETPS.bit.INTCNT = 0;		// 3:2EPWMxINTn Counter Register 
	EPwm5Regs.ETPS.bit.SOCAPRD = 0;		// 9:8EPWMxSOCA Period Select
	EPwm5Regs.ETPS.bit.SOCACNT = 0;		// 11:10  EPWMxSOCA Counter Register 
	EPwm5Regs.ETPS.bit.SOCBPRD = 0;		// 13:12  EPWMxSOCB Period Select
	EPwm5Regs.ETPS.bit.SOCBCNT = 0;		// 15:14  EPWMxSOCB Counter Register 

//	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS; 
}
//#endif 

//******************************************************************
// 函数名	:void InitEPwm6Driver(void)
// 作者		:TI
// 功能		:初始化系统ePWM6寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	加热阀控制
//******************************************************************
//#if DSP28_EPWM6//

void InitEPwm6Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	EPwm6Regs.TBPRD 			= 1500;
	EPwm6Regs.TBPHS.all			= 0;
	EPwm6Regs.TBCTR				= 0;
	EPwm6Regs.TBPHS.half.TBPHS	= 0;

	// Setup TBCLK
	EPwm6Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// Count up
	EPwm6Regs.TBCTL.bit.PHSEN		= TB_DISABLE;// Disable phase loading  
	EPwm6Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm6Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_DISABLE;
	EPwm6Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm6Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm6Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm6Regs.TBCTL.bit.PHSDIR		= 1;
	EPwm6Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compare 
	EPwm6Regs.CMPA.half.CMPA  = 3;
	// Setup CMPCTL 
	EPwm6Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm6Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm6Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm6Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm6Regs.AQCTLA.bit.CAU = AQ_CLEAR;				// Set PWM6A
	EPwm6Regs.AQCTLA.bit.ZRO = AQ_SET;

	EPwm6Regs.ETSEL.bit.INTSEL	= ET_CTR_PRD;			// 2:0EPWMxINTn Select
	EPwm6Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable

	EPwm6Regs.ETPS.bit.INTPRD = 1;		// 1:0EPWMxINTn Period Select
	EPwm6Regs.ETPS.bit.INTCNT = 0;		// 3:2EPWMxINTn Counter Register
	EPwm6Regs.AQCSFRC.bit.CSFA = 0;
	EPwm6Regs.AQCSFRC.bit.CSFB = 0;// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS; 
}
//#endif 

//******************************************************************
// 函数名	:void InitEPwm7Driver(void)
// 作者		:TI
// 功能		:初始化系统ePWM7寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改绷浚何?
// 备注		:	Slope Compensation PWM Control	(Hardware
//******************************************************************
//#if DSP28_EPWM7
void InitEPwm7Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	EPwm7Regs.TBPRD 			= 1000;//3130--10K
	EPwm7Regs.TBPHS.all			= 0;
	EPwm7Regs.TBCTR				= 0;
	EPwm7Regs.TBPHS.half.TBPHS	= 0;

	// Setup TBCLK
	EPwm7Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// Count up
	EPwm7Regs.TBCTL.bit.PHSEN		= TB_DISABLE;		// Disable phase loading  
	EPwm7Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm7Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_DISABLE;
	EPwm7Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm7Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm7Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm7Regs.TBCTL.bit.PHSDIR		= 1;
	EPwm7Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compare 
	EPwm7Regs.CMPB = 0;
	// Setup CMPCTL 
	EPwm7Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm7Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm7Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm7Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	// EPwm7Regs.AQCTLB.bit.CBU = AQ_CLEAR;				// Set PWM7B
	// EPwm7Regs.AQCTLB.bit.CBD = AQ_SET;
	EPwm7Regs.AQCTLB.bit.ZRO = AQ_SET;
	EPwm7Regs.AQCTLB.bit.CBU = AQ_CLEAR;

	EPwm7Regs.ETSEL.bit.INTSEL	= ET_CTRD_CMPB;			// 2:0EPWMxINTn Select
	EPwm7Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable

	EPwm7Regs.ETPS.bit.INTPRD = 1;		// 1:0EPWMxINTn Period Select
	EPwm7Regs.ETPS.bit.INTCNT = 0;		// 3:2EPWMxINTn Counter Register

//	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS; 
}
//#endif 


/******************************************************************/
//函数名:void InitTzDriver(void)
//功能:Initialize the TZ Module for epwm1,epwm2,epwm4,epwm5 and epwm6 of WPPM3312Z
//备注:2015.06.25
//===========================================================================
void InitTzDriver(void)
{// Enable TZ1/TZ2 and TZ3 as one shot trip sources on EPwm1 Module
	EALLOW;
	EPwm1Regs.TZSEL.bit.CBC1 = 1;
	//EPwm1Regs.TZSEL.bit.OSHT1 = 1;
	//EPwm1Regs.TZSEL.bit.DCBEVT1 = 1;
	EPwm1Regs.TZSEL.bit.DCAEVT1 = 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm1Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	EPwm1Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	EPwm1Regs.TZCTL.bit.DCAEVT1 = 2;
	// EPwm1Regs.TZCTL.bit.DCBEVT1= 2;

	// EPwm1Regs.TZDCSEL.bit.DCBEVT1 = TZ_DCBH_LOW;
	EPwm1Regs.TZDCSEL.bit.DCAEVT1 = TZ_DCAH_HI;
	// Enable TZ interrupt
	// EPwm1Regs.TZEINT.bit.OST = 1;
	// EDIS;
	// Enable  TZ1\TZ2 and TZ3 as one shot trip sources on EPwm2 Module
	// EALLOW;
	EPwm2Regs.TZSEL.bit.CBC1 = 1;  
	//EPwm2Regs.TZSEL.bit.OSHT1 = 1;  
	// EPwm2Regs.TZSEL.bit.DCBEVT1= 1;
	EPwm2Regs.TZSEL.bit.DCAEVT1= 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm2Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	EPwm2Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	EPwm2Regs.TZCTL.bit.DCAEVT1 = 2;
	// EPwm2Regs.TZCTL.bit.DCBEVT1 = 2;

	// EPwm2Regs.TZDCSEL.bit.DCBEVT1 = TZ_DCBH_LOW;
	EPwm2Regs.TZDCSEL.bit.DCAEVT1 = TZ_DCAH_HI;
	// Enable TZ interrupt
	// EPwm2Regs.TZEINT.bit.OST = 1;
	// EDIS;
	// Enable TZ1/TZ2 and TZ3 as one shot trip sources on EPwm4 Module
	EPwm3Regs.TZSEL.bit.CBC3 = 1;//FAN

	EPwm3Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	// EALLOW;
	// EPwm4Regs.TZSEL.bit.CBC1 = 1;
	EPwm4Regs.TZSEL.bit.DCAEVT2 = 1;
	// EPwm4Regs.TZSEL.bit.DCBEVT2 = 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm4Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	EPwm4Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	// EPwm4Regs.TZCTL.bit.DCAEVT2 = 2;
	// EPwm4Regs.TZCTL.bit.DCBEVT2 = 2;


	// EPwm4Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCBH_LOW;
	EPwm4Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_LOW;
	// Enable TZ interrupt
	// EPwm4Regs.TZEINT.bit.OST = 1;
	// EDIS;
	
	
	// Enable TZ1/TZ2 and TZ3 as one shot trip sources on EPwm5 Module
	// EALLOW;
	// EPwm5Regs.TZSEL.bit.CBC1 = 1;
	// EPwm5Regs.TZSEL.bit.CBC2 = 1;
	//EPwm5Regs.TZSEL.bit.CBC3 = 1;//FAN
	EPwm5Regs.TZSEL.bit.DCAEVT2 = 1;
	// EPwm5Regs.TZSEL.bit.DCAEVT2 = 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm5Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	EPwm5Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	// EPwm5Regs.TZCTL.bit.DCAEVT2 = 2;
	// EPwm5Regs.TZCTL.bit.DCBEVT2 = 2;

	EPwm5Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_LOW;
	// EPwm5Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_LOW;
	// Enable TZ interrupt
	// EPwm5Regs.TZEINT.bit.OST = 1;
	// EDIS;
	
	// Enable TZ1\TZ2 and TZ3 as one shot trip sources on EPwm3 Module
	// EALLOW;
	// EPwm6Regs.TZSEL.bit.CBC1 = 1;
	EPwm6Regs.TZSEL.bit.CBC2 = 1;///JRF
	// EPwm6Regs.TZSEL.bit.CBC3 = 1;
	// EPwm6Regs.TZSEL.bit.DCAEVT2= 1;
	// EPwm6Regs.TZSEL.bit.DCBEVT2 = 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm6Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	// EPwm6Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	// EPwm6Regs.TZCTL.bit.DCAEVT2 = 2;
	// EPwm6Regs.TZCTL.bit.DCBEVT2 = 2;

	// EPwm6Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCBH_LOW;
	// EPwm6Regs.TZDCSEL.bit.DCAEVT2= TZ_DCAH_HI;
	// EPwm7Regs.TZSEL.bit.CBC2 = 1;//JRF
	// EPwm7Regs.TZCTL.bit.TZA = TZ_FORCE_LO;

	// Enable TZ interrupt
	// EPwm6Regs.TZEINT.bit.OST = 1;
	EDIS;
	
	
}

/***********************************************************/
//函数名:void InitDCEventDriver
//功能:Initialize Digtal Compare Event Module
//备注:DC Event for protecting Power and Motor
//===========================================================================
void InitDCEventDriver(void)
{
	
	// Define an event (DCAEVT1) based on TZ1 and TZ2
	EALLOW;
	EPwm1Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP1OUT;// DCAH = Comparator 1 output and TZ1 input
	// EPwm1Regs.DCTRIPSEL.bit.DCBHCOMPSEL = DC_TZ1 ;
	EPwm1Regs.DCACTL.bit.EVT1SRCSEL = DC_EVT1;// DCAEVT1 = DCAEVT1(not filtered)
	EPwm1Regs.DCACTL.bit.EVT1FRCSYNCSEL = DC_EVT_ASYNC;

	EPwm2Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP1OUT;// DCAH = Comparator 1 output AND TZ1 input
	// EPwm2Regs.DCTRIPSEL.bit.DCBHCOMPSEL = DC_TZ1;
	EPwm2Regs.DCACTL.bit.EVT1SRCSEL = DC_EVT1;// DCAEVT1 = DCAEVT1 (not filtered)
	EPwm2Regs.DCACTL.bit.EVT1FRCSYNCSEL = DC_EVT_ASYNC;

	EPwm4Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP2OUT;// DCAH = Comparator 2 output
	EPwm4Regs.DCACTL.bit.EVT2SRCSEL = DC_EVT2;// DCAEVT2 = DCAEVT2 (not filtered)
	EPwm4Regs.DCACTL.bit.EVT2FRCSYNCSEL = DC_EVT_ASYNC;// Take async path

	EPwm5Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP2OUT;// DCAH = Comparator 2 output
	EPwm5Regs.DCACTL.bit.EVT2SRCSEL = DC_EVT2;// DCAEVT2= DCAEVT2 (not filtered)
	EPwm5Regs.DCACTL.bit.EVT2FRCSYNCSEL = DC_EVT_ASYNC;// Take async path

	EDIS;
}


//===========================================================================
// End of file.
//===========================================================================

----------------------以上为DSP2803x_EPwm.c-----------------------------------------------------------

Jordan Zhou:能抓取到DACVAL的实时值吗?

在使用TMS320f28034这款芯片的单周期斩波功能,遇到了一些问题如下:

        ePWM的频率设置为20kHZ;ePWM1,ePWM2,ePWM3同步;ePWM1A和ePWM2A驱动全桥,控制逆变电源(ePWM1B和ePWM2B不使用);ePWM3A和ePWM3B用来做斜波补偿,和电流反馈信号一起从Comp1的一个端口进入,Comp1的另一个端口为软件计算的值写入DACVAL,对ePWM1A,ePWM2A进行斩波。现在发现在一个ePWM周期内出现多次斩波的现象。见附件。
下图通道1为全桥驱动;通道2为ePWM1A(最大占空比设置为50%);通道3为ePWM2A(最大占空比设置为50%);通道4为ePWM3A(占空比设置为50%)和ePWM3B(占空比设置为50%)+反馈电流;a b之间为一个周期。
//###########################################################################
//
// FILE:DSP2803x_Comp.c
//
// TITLE:DSP2803x Comparator Initialization & Support Functions.
//
//###########################################################################
// $TI Release: F2803x C/C++ Header Files and Peripheral Examples V127 $
// $Release Date: March 30, 2013 $
//###########################################################################

#include "DSP2803x_Device.h"// DSP2803x Headerfile Include File
#include "DSP2803x_Examples.h"// DSP2803x Examples Include File


void InitCompDriver(void);
void InitCompGpio(void);
void InitComp(void);

void InitComp(void)
{

	InitCompGpio();
	InitCompDriver();

}


void InitCompGpio()
{InitComp1Gpio();
}

void InitComp1Gpio()
{EALLOW;GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1;// Disable pull-up for GPIO1 (CMP1OUT)GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 3;// Configure GPIO1 for CMP1OUT operationGpioCtrlRegs.AIOMUX1.bit.AIO2 = 2;// Configure AIO2 for CMP1A (analog input) operationSysCtrlRegs.PCLKCR3.bit.COMP1ENCLK = 1;//EDIS;
}

#if DSP28_COMP2
void InitComp2Gpio()
{EALLOW;GpioCtrlRegs.AIOMUX1.bit.AIO4 = 2;// Configure AIO4 for CMP2A (analog input) operationEDIS;
}

#endif //end DSP28_COMP2

#if DSP28_COMP3
void InitComp3Gpio()
{EALLOW;GpioCtrlRegs.AIOMUX1.bit.AIO6 = 2;// Configure AIO6 for CMP3A (analog input) operationEDIS;
}

#endif //end DSP28_COMP3




/**********************************************************************************/
//函数名:void IntiCompDriver(void);
//功能:比较器模块初始化
//备注:
/*********************************************************************************/
void InitCompDriver()
{EALLOW;SysCtrlRegs.PCLKCR3.bit.COMP1ENCLK = 1;// Enable clock to the Comparator 1 blockComp1Regs.DACVAL.bit.DACVAL = 300;//C_CTCurr_Pro;Comp1Regs.COMPCTL.bit.COMPDACEN = 1;// Power up Comparator 1 locallyComp1Regs.COMPCTL.bit.COMPSOURCE = 0;Comp1Regs.COMPCTL.bit.CMPINV = 0;Comp1Regs.COMPCTL.bit.QUALSEL = 6;Comp1Regs.COMPCTL.bit.SYNCSEL =1;EDIS;
}


//===========================================================================
// End of file.
//===========================================================================
-----------------------------------以上为DSP2803x_Comp.c----------------------------------------------------------------
//**************************************************************************
//	Copyright(c)2017-DR_Welding
//	文件名称	:	WPCM2315CU2_Isr.c
//	作者		:	
//	模块功能	:系统中断
//	局部函数列表: 	无
//  更改记录	:
//	日期		DR版本		作者		备注
//	
//**************************************************************************

#define		in_interrupt

#include	"DSP2803x_Header.h"// Headerfile Include File
#include	"WPPM3312M2_Isr.h"
#include	"WPPM3312M2_SysReg.h"
#include	"WPPM3312M2_SysMacro.h"
#include	"WPPM3312M2_GlobalVarDef.h"
#include	"WPPM3312M2_EepromDriver.h"
#include	"WPPM3312M2_Can.h"
#include	"WPPM3312M2_Struct.h"
//#include"WPPM3312M2_LedShow.h"
#include"WPPM3312M2_KeyDispose.h"

//============================
//		内部函数声明
//============================
void vPwm1IntIsr(void);
void vTimer0IntIsr(void);
void IsrVarInit(void);

//******************************************************************
// 函数名	:void InitInterrupt(void)
// 作者		:
// 功能		:中断模块初始化
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	
//******************************************************************
void InitInterrupt(void)
{EALLOW;  	
	// 定义PWM1的中断向量PieVectTable.EPWM1_INT = &vPwm1IntIsr;PieCtrlRegs.PIEIER3.bit.INTx1 = 1;IER |= M_INT3;EDIS;  
}
//******************************************************************
// 函数名	:void vPwm1IntIsr(void)
// 作者		:
// 功能		:主拓扑PWM中断
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	
//******************************************************************
interrupt void vPwm1IntIsr(void)
{	
	//========= 更新主功率移相角=========mEnablePowerPwm();
	mSetPwm1Duty(1500);		
	PidLogic();//PI处理	

//======================== 清中断标志并再次使能中断 ===========================	
	EPwm1Regs.ETCLR.bit.INT = 1;
	PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;	
}

/****************************************************************************/
//函数名:void PidUpGrading(int PidResult);
// 作者		:MaKe
//功能:比较器模块更新PID计算结果
// 参数		:PidResult :PID计算结果
// 祷?:无
// 调用全局变量:无
// 修改全局变量:无
//备注:2018.06.29
/************************************************************************/
void PidUpGrading(int PidResult)
{EALLOW;Comp1Regs.DACVAL.bit.DACVAL = PidResult;	//C_CTCurr_Pro;//原边过流保护点EDIS;
}
------------------------------以上为WPCM2315CU2_Isr.c------------------------------------------------------------------------------//**************************************************************************
//	***
//	文件名称	:	DSP2803x_EPwm.c
//	作者		:	
//	模块功能	:DSP2803x EPwm Initialization & Support Functions.
//	局部函数列表: 	无
//	版本信息	:	TI File $Revision: /main/3 $
// 					Checkin $Date: November 10, 200914:05:11 $
//					$TI Release: 2803x C/C++ Header Files V1.21 $
// 					$Release Date: December 1, 2009 $
//  更改记录	:
//**************************************************************************


#include	"DSP2803x_Header.h"// Headerfile Include File
#include	"WPPM3312M2_SysMacro.h"
#include	"WPPM3312M2_SysReg.h"
#include	"DSP2803x_Device.h"




//============================
//		内部函数声明
//============================
void InitEPwmGpio(void);
void InitEPwm1Gpio(void);
void InitEPwm2Gpio(void);
void InitEPwm3Gpio(void);
void InitEPwm4Gpio(void);
void InitEPwm5Gpio(void);
void InitEPwm6Gpio(void);
void InitEPwm7Gpio(void);

void InitEPwmDriver(void);
void InitEPwm1Driver(void);
void InitEPwm2Driver(void);
void InitEPwm3Driver(void);
void InitEPwm4Driver(void);
void InitEPwm5Driver(void);
void InitEPwm6Driver(void);
void InitEPwm7Driver(void);

void InitTzGpio(void);
void InitTzDriver(void);
void InitDCEventDriver(void);

//******************************************************************
// 函数名	:void InitEPwm(void)
// 作者		:TI
// 功能		:初始化系统PWM模块及管脚设置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
void InitEPwm(void)
{
	// 配置管脚功能

	EALLOW;
	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;  
	EDIS;

	InitEPwmGpio();
//	InitTzGpio();
	// 初始化寄存器

//	InitTzDriver();
//	InitDCEventDriver();
	InitEPwmDriver();
	//mUpDatePwm2Phase(0);
	mUpDatePwm2Phase(1500);
	//mSetPwm4BDuty(0);

	mDisablePowerPwm();
	mDisableMotorPWM();

	mEnableMotorPWM();//////使能PWM3
//	mDisableJRFPWM();
//	mDisableFANPWM();

//	mDebugPWM(1000);  

	EALLOW;
	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;  
	EDIS;  
}


//******************************************************************
// 函数名	:void InitEPwmDriver(void)
// 作者		:TI
// 功能		:This function initializes GPIO pins to function as EPwm pins
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	Each GPIO pin can be configured as a GPIO pin or up to 3 different
// 				peripheral functional pins. By default all pins come up as GPIO
// 				inputs after reset.
//******************************************************************
void InitEPwmGpio(void)
{
#if DSP28_EPWM1InitEPwm1Gpio();
#endif // endif DSP28_EPWM1

#if DSP28_EPWM2InitEPwm2Gpio();
#endif // endif DSP28_EPWM2

#if DSP28_EPWM3InitEPwm3Gpio();
#endif // endif DSP28_EPWM3

#if DSP28_EPWM4// InitEPwm4Gpio();
#endif // endif DSP28_EPWM4

#if DSP28_EPWM5//InitEPwm5Gpio();
#endif // endif DSP28_EPWM5

#if DSP28_EPWM6//InitEPwm6Gpio();
#endif // endif DSP28_EPWM6

#if DSP28_EPWM7//InitEPwm7Gpio();
#endif // endif DSP28_EPWM7
}

//******************************************************************
// 函数名	:void InitEPwm1Gpio(void)
// 作者		:TI
// 功能		:初始化PWM1输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
#if DSP28_EPWM1
void InitEPwm1Gpio(void)
{
	EALLOW;

/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO0 = 1;// Disable pull-up on GPIO0 (EPWM1A)
	GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1;// Disable pull-up on GPIO1 (EPWM1B)

/* Configure EPWM-1 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM1 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1;// Configure GPIO0 as EPWM1A
	GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1;// Configure GPIO1 as EPWM1B

	EDIS;
}
#endif // endif DSP28_EPWM1

//******************************************************************
// 函数名	:void InitEPwm2Gpio(void)
// 作者		:TI
// 功能		:初始化PWM2输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM2
void InitEPwm2Gpio(void)
{
	EALLOW;

/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO2 = 1;// Disable pull-up on GPIO2 (EPWM2A)
	GpioCtrlRegs.GPAPUD.bit.GPIO3 = 1;// Disable pull-up on GPIO3 (EPWM2B)

/* Configure EPwm-2 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM2 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 1;// Configure GPIO2 as EPWM2A
	GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 1;// Configure GPIO3 as EPWM2B

	EDIS;
}
//#endif // endif DSP28_EPWM2

//******************************************************************
// 函数名	:void InitEPwm3Gpio(void)
// 作者		:TI
// 功能		:初始化PWM3输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM3
void InitEPwm3Gpio(void)
{
	EALLOW;

/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.GpioCtrlRegs.GPAPUD.bit.GPIO4 = 1;// Disable pull-up on GPIO4 (EPWM3A)
	GpioCtrlRegs.GPAPUD.bit.GPIO5 = 1;// Disable pull-up on GPIO5 (EPWM3B)

/* Configure EPwm-3 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM3 functional pins.
// Comment out other unwanted lines.GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 1;// Configure GPIO4 as EPWM3A
	GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 1;// Configure GPIO5 as EPWM3B

	EDIS;
}
//#endif // endif DSP28_EPWM3

//******************************************************************
// 函数名	:void InitEPwm4Gpio(void)
// 作者		:TI
// 功能		:初始化PWM4输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM4
void InitEPwm4Gpio(void)
{
	EALLOW;
/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO6 = 1;// Disable pull-up on GPIO6 (EPWM4A)
	GpioCtrlRegs.GPAPUD.bit.GPIO7 = 1;// Disable pull-up on GPIO7 (EPWM4B)

/* Configure EPWM-4 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM4 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 1;// Configure GPIO6 as EPWM4A
	GpioCtrlRegs.GPAMUX1.bit.GPIO7 = 1;// Configure GPIO7 as EPWM4B

	EDIS;
}
//#endif // endif DSP28_EPWM4

//******************************************************************
// 函数名	:void InitEPwm5Gpio(void)
// 作者		:
// 功能		:初始化PWM5输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:EPWM5模块只用到了GPIO9,故只初始化此管脚
//******************************************************************
//#if DSP28_EPWM5
void InitEPwm5Gpio(void)
{
	EALLOW;
/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO8 = 1;// Disable pull-up on GPIO8 (EPWM5A)
	GpioCtrlRegs.GPAPUD.bit.GPIO9 = 1;// Disable pull-up on GPIO9 (EPWM5B)

/* Configure EPWM-5 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM5 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO8 = 1;// Configure GPIO8 as EPWM5A
	GpioCtrlRegs.GPAMUX1.bit.GPIO9 = 1;// Configure GPIO9 as EPWM5B

	EDIS;
}
//#endif // endif DSP28_EPWM5

//******************************************************************
// 函数名	:void InitEPwm6Gpio(void)
// 作者		:TI
// 功能		:初始化PWM6输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM6
void InitEPwm6Gpio(void)
{
	EALLOW;
/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO10 = 1;// Disable pull-up on GPIO10 (EPWM6A)//GpioCtrlRegs.GPAPUD.bit.GPIO11 = 1;// Disable pull-up on GPIO11 (EPWM6B)

/* Configure EPWM-6 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM6 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO10 = 1;// Configure GPIO10 as EPWM6A//GpioCtrlRegs.GPAMUX1.bit.GPIO11 = 1;// Configure GPIO11 as EPWM6B

	EDIS;
}
//#endif // endif DSP28_EPWM6

//******************************************************************
// 函数名	:void InitEPwm7Gpio(void)
// 作者		:TI
// 功能		:初始化PWM7输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM7
void InitEPwm7Gpio(void)
{
	EALLOW;
/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.//GpioCtrlRegs.GPBPUD.bit.GPIO40 = 1;// Disable pull-up on GPIO40 (EPWM7A)
	GpioCtrlRegs.GPBPUD.bit.GPIO41 = 1;// Disable pull-up on GPIO41 (EPWM7B)

/* Configure EPWM-7 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM7 functional pins.
// Comment out other unwanted lines.// GpioCtrlRegs.GPBMUX1.bit.GPIO40 = 1;// Configure GPIO40 as EPWM7A
	GpioCtrlRegs.GPBMUX1.bit.GPIO41 = 1;// Configure GPIO41 as EPWM7B

	EDIS;
}
//#endif // endif DSP28_EPWM7


//******************************************************************
// 函数名	:void InitEPwmSyncGpio(void)
// 作者		:TI
// 功能		:This function initializes GPIO pins to function as EPwm Synch pins
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
void InitEPwmSyncGpio(void)
{

//EALLOW;

/* Configure EPWMSYNCI  */

/* Enable internal pull-up for the selected pins */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

// GpioCtrlRegs.GPAPUD.bit.GPIO6 = 0;// Enable pull-up on GPIO6 (EPWMSYNCI)
	GpioCtrlRegs.GPBPUD.bit.GPIO32 = 0;// Enable pull-up on GPIO32 (EPWMSYNCI)

/* Set qualification for selected pins to asynch only */
// This will select synch to SYSCLKOUT for the selected pins.
// Comment out other unwanted lines.

// GpioCtrlRegs.GPAQSEL1.bit.GPIO6 = 0;// Synch to SYSCLKOUT GPIO6 (EPWMSYNCI)
	GpioCtrlRegs.GPBQSEL1.bit.GPIO32 = 0;  // Synch to SYSCLKOUT GPIO32 (EPWMSYNCI)

/* Configure EPwmSync pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPwmSync functional pins.
// Comment out other unwanted lines.

// GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 2;// Configures GPIO6 for EPWMSYNCI operation
	GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 2;// Configures GPIO32 for EPWMSYNCI operation.

/* Configure EPWMSYNC0  */

/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// Comment out other unwanted lines.

// GpioCtrlRegs.GPAPUD.bit.GPIO6 = 1;// Disable pull-up on GPIO6 (EPWMSYNCO)
	GpioCtrlRegs.GPBPUD.bit.GPIO33 = 1;// Disable pull-up on GPIO33 (EPWMSYNCO)

// GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 3;// Configures GPIO6 for EPWMSYNCO
	GpioCtrlRegs.GPBMUX1.bit.GPIO33 = 2;  // Configures GPIO33 for EPWMSYNCO

}

//******************************************************************
// 函数名	:void InitTzGpio(void)
// 作者		:TI
// 功能		:This function initializes GPIO pins to function as Trip Zone (TZ) pins
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	Each GPIO pin can be configured as a GPIO pin or up to 3 different
// 				peripheral functional pins. By default all pins come up as GPIO
// 				inputs after reset.
//******************************************************************
void InitTzGpio(void)
{
	EALLOW;

/* Enable internal pull-up for the selected pins */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.
	GpioCtrlRegs.GPAPUD.bit.GPIO12 = 0;// Enable pull-up on GPIO12 (TZ1)
// GpioCtrlRegs.GPAPUD.bit.GPIO15 = 0;// Enable pull-up on GPIO15 (TZ1)
	GpioCtrlRegs.GPAPUD.bit.GPIO13 = 0;// Enable pull-up on GPIO13 (TZ2)
// GpioCtrlRegs.GPAPUD.bit.GPIO16 = 0;// Enable pull-up on GPIO16 (TZ2)
// GpioCtrlRegs.GPAPUD.bit.GPIO28 = 0;// Enable pull-up on GPIO28 (TZ2)
	GpioCtrlRegs.GPAPUD.bit.GPIO14 = 0;// Enable pull-up on GPIO14 (TZ3)
// GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0;// Enable pull-up on GPIO17 (TZ3)
// GpioCtrlRegs.GPAPUD.bit.GPIO29 = 0;// Enable pull-up on GPIO29 (TZ3)

/* Set qualification for selected pins to asynch only */
// Inputs are synchronized to SYSCLKOUT by default.
// This will select asynch (no qualification) for the selected pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAQSEL1.bit.GPIO12 = 3;  // Asynch input GPIO12 (TZ1)
// GpioCtrlRegs.GPAQSEL1.bit.GPIO15 = 3;  // Asynch input GPIO15 (TZ1)
	GpioCtrlRegs.GPAQSEL1.bit.GPIO13 = 3;  // Asynch input GPIO13 (TZ2)
// GpioCtrlRegs.GPAQSEL2.bit.GPIO16 = 3;  // Asynch input GPIO16 (TZ2)
// GpioCtrlRegs.GPAQSEL2.bit.GPIO28 = 3;  // Asynch input GPIO28 (TZ2)
	GpioCtrlRegs.GPAQSEL1.bit.GPIO14 = 3;  // Asynch input GPIO14 (TZ3)
// GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3;  // Asynch input GPIO17 (TZ3)
// GpioCtrlRegs.GPAQSEL2.bit.GPIO29 = 3;  // Asynch input GPIO29 (TZ3)


/* Configure TZ pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be TZ functional pins.
// Comment out other unwanted lines.
	GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 1;  // Configure GPIO12 as TZ1
//GpioCtrlRegs.GPAMUX1.bit.GPIO15 = 1;  // Configure GPIO15 as TZ1
	GpioCtrlRegs.GPAMUX1.bit.GPIO13 = 1;  // Configure GPIO13 as TZ2
// GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 3;  // Configure GPIO16 as TZ2
// GpioCtrlRegs.GPAMUX2.bit.GPIO28 = 3;  // Configure GPIO28 as TZ2
	GpioCtrlRegs.GPAMUX1.bit.GPIO14 = 1;  // Configure GPIO14 as TZ3
// GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 3;  // Configure GPIO17 as TZ3
// GpioCtrlRegs.GPAMUX2.bit.GPIO29 = 3;  // Configure GPIO29 as TZ3

	EDIS;

}

//******************************************************************
// 函数名	:void InitEPwmDriver(void)
// 作者		篢I
// 功能		:初始低砅WM模块寄存髋渲?
// 参数		:无
// 	:无
// 调用全局变量?
// 
// 备注
//******************************************************************
void InitEPwmDriver(void)
{ 
//#if DSP28_EPWM1InitEPwm1Driver();
//#endif 

//#if DSP28_EPWM2
	InitEPwm2Driver();
//#endif 

//#if DSP28_EPWM3
	InitEPwm3Driver();
//#endif 

//#if DSP28_EPWM4
	//InitEPwm4Driver();
//#endif 

//#if DSP28_EPWM5
	//InitEPwm5Driver();
//#endif 

//#if DSP28_EPWM6
//	InitEPwm6Driver();
//#endif 

#if DSP28_EPWM7
//	InitEPwm7Driver();
#endif 
}


//******************************************************************
// 函数名	:void InitEPwm1Driver(void)
// 作者		:TI
// 功		:初始化系统ePWM1寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	
//******************************************************************
#if DSP28_EPWM1
void InitEPwm1Driver(void)
{
	EALLOW;	
	EPwm1Regs.TBPRD 	= 3000;////PFSB_PERIOD,1250-48K
	//EPwm1Regs.TBPRD 	= 1500;////PFSB_PERIOD,1250-48K
	EPwm1Regs.TBPHS.all	= 0;
	EPwm1Regs.TBCTR		= 0;

	// Setup TBCLK
	EPwm1Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// Count up
	//EPwm1Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;
	EPwm1Regs.TBCTL.bit.PHSEN		= TB_DISABLE;		// Disable phase loading  
	EPwm1Regs.TBCTL.bit.PRDLD		= TB_SHADOW;		//
	EPwm1Regs.TBCTL.bit.SYNCOSEL	= TB_CTR_ZERO;//Count equal to zero; have a syn output
	EPwm1Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm1Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;			//
	EPwm1Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm1Regs.TBCTL.bit.PHSDIR		= 1; 
	EPwm1Regs.TBCTL.bit.FREE_SOFT	= 3;	//
	// Setup compare 
	EPwm1Regs.CMPA.half.CMPA= 1500;
	EPwm1Regs.CMPB = 1500;
	EPwm1Regs.TBPHS.half.TBPHS = 0;
	// Setup CMPCTL 
	EPwm1Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm1Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm1Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm1Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;/////
	EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;
	EPwm1Regs.AQCTLB.bit.ZRO = AQ_CLEAR;	
	EPwm1Regs.AQCTLB.bit.CBU = AQ_SET;

	//EPwm1Regs.AQSFRC.bit.RLDCSF = 0;

	
	//Set DeadBand
	EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;//
	EPwm1Regs.DBCTL.bit.IN_MODE = 0x0;
	EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
	//EPwm1Regs.DBFED = 200;//
	//EPwm1Regs.DBRED = 200;//
	EPwm1Regs.DBFED = 300;//
	EPwm1Regs.DBRED = 300;// 
	//EPwm1Regs.DBCTL.bit.HALFCYCLE = 1;

	//	// Set ETSEL
	EPwm1Regs.ETSEL.bit.INTSEL	= ET_CTR_ZERO;			// 2:0EPWMxINTn Select
	EPwm1Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable
	EPwm1Regs.ETSEL.bit.SOCASEL	= ET_CTRU_CMPA;			// 10:8Start of conversion A Select  
	EPwm1Regs.ETSEL.bit.SOCAEN	= ET_ENABLE;			// 11Start of conversion A Enable  
	EPwm1Regs.ETSEL.bit.SOCBSEL	= ET_CTRU_CMPB;			// 14:12  Start of conversion B Select	
	EPwm1Regs.ETSEL.bit.SOCBEN	= ET_ENABLE;			// 15Start of conversion B Enable

	EPwm1Regs.ETPS.bit.INTPRD	= ET_1ST;		// 1:0EPWMxINTn Period Select
	EPwm1Regs.ETPS.bit.INTCNT	= 0;		// 3:2EPWMxINTn Counter Register 
	EPwm1Regs.ETPS.bit.SOCAPRD	= ET_1ST;		// 9:8EPWMxSOCA Period Select
	EPwm1Regs.ETPS.bit.SOCACNT	= 0;		// 11:10  EPWMxSOCA Counter Register 
	EPwm1Regs.ETPS.bit.SOCBPRD	= 1;		// 13:12  EPWMxSOCB Period Select
	EPwm1Regs.ETPS.bit.SOCBCNT	= 0;		// 15:14  EPWMxSOCB Counter Register
 ///////////////////////////////////////////////////////EPwm1Regs.TZSEL.bit.DCAEVT2 = 1;//////EPwm1Regs.TZSEL.bit.DCAEVT2 = 0;//////EPwm1Regs.TZSEL.bit.DCBEVT2 = 0;//////EPwm1Regs.TZSEL.bit.DCBEVT2 = 1;EPwm1Regs.TZSEL.bit.CBC1=1;

// What do we want the TZ1 and TZ2 to doEPwm1Regs.TZCTL.bit.TZA = TZ_FORCE_LO;EPwm1Regs.TZCTL.bit.TZB = TZ_FORCE_LO;//EPwm1Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCBH_LOW; //TZ_DCAH_HI;//EPwm1Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCAH_LOW;EPwm1Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_HI;EPwm1Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCAH_HI;EPwm1Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP1OUT;// DCAH = Comparator 2 output
	EDIS;	
}
#endif 


//******************************************************************
// 函数名	:void InitEPwm2Driver(void)
// 作者		:TI
// 功能		初始化系统ePWM2寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	
//******************************************************************
#if DSP28_EPWM2
void InitEPwm2Driver(void)
{	EALLOW;
	//SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;	// Stop all the TB clocks	
	//EPwm2Regs.TBPRD 	= 1874;///48k
	EPwm2Regs.TBPRD 	= 3000;///20k// Count up
	//EPwm2Regs.TBPRD 	= 1500;///20k//Count updown
	EPwm2Regs.TBPHS.all	= 0;
	EPwm2Regs.TBCTR		= 0;

	// Setup TBCLK
	EPwm2Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// Count up
	//EPwm2Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;//Count updown
	EPwm2Regs.TBCTL.bit.PHSEN		= TB_ENABLE;		// Enable phase loading  
	EPwm2Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm2Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_IN;
	EPwm2Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm2Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm2Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm2Regs.TBCTL.bit.PHSDIR		= 1; 
	EPwm2Regs.TBCTL.bit.FREE_SOFT	= 3;				// 


	// Setup compare 
	EPwm2Regs.CMPA.half.CMPA= 1500;//
	EPwm2Regs.CMPB= 1500;//
	EPwm2Regs.TBPHS.half.TBPHS = 0;
	
	// Setup CMPCTL 
	EPwm2Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm2Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm2Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm2Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm2Regs.AQCTLA.bit.ZRO = AQ_SET;
	EPwm2Regs.AQCTLA.bit.CAU = AQ_CLEAR;
	EPwm2Regs.AQCTLB.bit.ZRO = AQ_CLEAR ;
	EPwm2Regs.AQCTLB.bit.CBU = AQ_SET;
	
//	EPwm2Regs.AQSFRC.bit.RLDCSF = 3;

	//Set DeadBand
 	EPwm2Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
	EPwm2Regs.DBCTL.bit.IN_MODE = 0x0;
	EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
	//EPwm2Regs.DBFED = 200 ;//
	//EPwm2Regs.DBRED = 200;
	EPwm2Regs.DBFED = 300;//
	EPwm2Regs.DBRED = 300; 
	////斩波比较模块
	//EPwm2Regs.TZSEL.bit.DCAEVT2 = 1;
	//EPwm2Regs.TZSEL.bit.DCAEVT2 = 0;
	//EPwm2Regs.TZSEL.bit.DCBEVT2 = 0;
	//EPwm2Regs.TZSEL.bit.DCBEVT2 = 1;
	EPwm2Regs.TZSEL.bit.CBC1=1;// What do we want the TZ1 and TZ2 to do?EPwm2Regs.TZCTL.bit.TZA = TZ_FORCE_LO;EPwm2Regs.TZCTL.bit.TZB = TZ_FORCE_LO;//EPwm2Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCBH_LOW;//EPwm2Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCBH_LOW;EPwm2Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_HI;EPwm2Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCAH_HI;EPwm2Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP1OUT; // DCAH = Comparator 2 outputEPwm2Regs.DCACTL.bit.EVT2SRCSEL = DC_EVT2;// DCAEVT2 = DCAEVT2 (not filtered)EPwm2Regs.DCACTL.bit.EVT2FRCSYNCSEL = DC_EVT_ASYNC;// Take async pathEPwm2Regs.TZEINT.bit.DCBEVT2=0;//??
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS;

}
#endif 

//******************************************************************
// 函数名	:void InitEPwm3Driver(void)
// 作者		:TI
// 功能		:初始化系统ePWM3寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM3
void InitEPwm3Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	//EPwm3Regs.TBPRD 			= Motor_PERIOD;
	EPwm3Regs.TBPRD 			= 3000;//1500;//C_MOTOR_PWM_PRD;
	EPwm3Regs.TBPHS.all			= 0;
	EPwm3Regs.TBCTR				= 0;
	EPwm3Regs.TBPHS.half.TBPHS	= 0;

	// Setup TBCLK
	//EPwm3Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;		// Count up
	EPwm3Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// 对称波形输出 
	EPwm3Regs.TBCTL.bit.PHSEN		= TB_DISABLE;// Disable phase loading  
	EPwm3Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	//EPwm3Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_DISABLE;
	EPwm3Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_IN;	//  Count equal to zero; have a syn output
	EPwm3Regs.TBCTL.bit.SWFSYNC		= 0; 
	//EPwm3Regs.TBCTL.bit.HSPCLKDIV	= 0x04;///1/8
	EPwm3Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
//	EPwm3Regs.TBCTL.bit.CLKDIV		= 0x04;///1/16 
	EPwm3Regs.TBCTL.bit.CLKDIV		= TB_DIV1;
	EPwm3Regs.TBCTL.bit.PHSDIR		= 1;
	EPwm3Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compareEPwm3Regs.CMPA.half.CMPA =1500;
	EPwm3Regs.CMPB  = 0;
	// Setup CMPCTL 
	EPwm3Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm3Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm3Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm3Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm3Regs.AQCTLA.bit.CAU = AQ_CLEAR;			// 
	EPwm3Regs.AQCTLA.bit.PRD = AQ_SET;				//  
	EPwm3Regs.AQCTLB.bit.CBU = AQ_SET;				// 
	EPwm3Regs.AQCTLB.bit.PRD = AQ_CLEAR;	// 

	EPwm3Regs.ETSEL.bit.INTSEL	= ET_CTR_PRD;			// 2:0EPWMxINTn Select
	EPwm3Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable
	
/////////////////////////////////////////////////////
	//死区模块(DB)配置
	EPwm3Regs.DBCTL.bit.OUT_MODE =DB_FULL_ENABLE;
	EPwm3Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
	EPwm3Regs.DBCTL.bit.IN_MODE = 0;
	//EPwm3Regs.DBCTL.bit.HALFCYCLE = 0;
	EPwm3Regs.DBFED = 200;//Falling delay
	EPwm3Regs.DBRED = 200;  //Raising delay  //0.01667*300=5U

	// 事件触发模块(EZ)配置
	EPwm3Regs.ETSEL.bit.INTSEL	= ET_CTRD_CMPA;		// 2:0EPWMxINTn Select
	EPwm3Regs.ETSEL.bit.INTEN	= ET_DISABLE;		// 3EPWMxINTn Enable
	EPwm3Regs.ETSEL.bit.SOCASEL	= ET_CTR_ZERO;		// 10:8Start of conversion A Select  
	EPwm3Regs.ETSEL.bit.SOCAEN	= ET_ENABLE;		// 11Start of conversion A Enable  
	EPwm3Regs.ETSEL.bit.SOCBSEL	= ET_CTR_ZERO;		// 14:12  Start of conversion B Select  
	EPwm3Regs.ETSEL.bit.SOCBEN	= ET_ENABLE;		// 15Start of conversion B Enable  

	EPwm3Regs.ETPS.bit.INTPRD = 1;		// 1:0EPWMxINTn Period Select
	EPwm3Regs.ETPS.bit.INTCNT = 0;		// 3:2EPWMxINTn Counter Register 
	EPwm3Regs.ETPS.bit.SOCAPRD = 1;		// 9:8EPWMxSOCA Period Select
	EPwm3Regs.ETPS.bit.SOCACNT = 0;		// 11:10  EPWMxSOCA Counter Register 
	EPwm3Regs.ETPS.bit.SOCBPRD = 1;		// 13:12  EPWMxSOCB Period Select
	EPwm3Regs.ETPS.bit.SOCBCNT = 0;	 	// 15:14  EPWMxSOCB Counter Register 	
	EDIS; 
}
//#endif 
//******************************************************************
// 函数名	:void InitEPwm4Driver(void)
// 作者		:TI
// 功能		:初始化系统ePWM4寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	送丝机H桥驱动
//******************************************************************
//#if DSP28_EPWM4
void InitEPwm4Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	
	EPwm4Regs.TBPRD 			= 1000;
	EPwm4Regs.TBPHS.all			= 0;
	EPwm4Regs.TBCTR				= 0;
	EPwm4Regs.TBPHS.half.TBPHS	= 0;
	
	// Setup TBCLK
	EPwm4Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;	// Count up and down 
	EPwm4Regs.TBCTL.bit.PHSEN		= TB_DISABLE;		// Disable phase loading  
	EPwm4Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm4Regs.TBCTL.bit.SYNCOSEL	= TB_CTR_ZERO;
	EPwm4Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm4Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm4Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm4Regs.TBCTL.bit.PHSDIR		= 1; 
	EPwm4Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compare 
	EPwm4Regs.CMPA.half.CMPA = Motor_PERIOD - 5;
	EPwm4Regs.CMPB = 5;

	// Setup CMPCTL 
	EPwm4Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm4Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm4Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm4Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm4Regs.AQCTLA.bit.CAU =  AQ_SET;					// Set PWM4A
	EPwm4Regs.AQCTLA.bit.CAD =  AQ_CLEAR;
	EPwm4Regs.AQCTLB.bit.CBU = AQ_CLEAR;				// Set PWM4B
	EPwm4Regs.AQCTLB.bit.CBD = AQ_SET;

//	EPwm4Regs.AQSFRC.bit.RLDCSF = 3;

	// Set deadband
//	EPwm4Regs.DBCTL.bit.OUT_MODE = DB_DISABLE;// Dead-band Output Mode Control
//	EPwm4Regs.DBCTL.bit.POLSEL= DB_ACTV_HI;// Polarity Select Control
//	EPwm4Regs.DBCTL.bit.IN_MODE  = DBB_ALL;// Dead Band Input Mode Control
//	EPwm4Regs.DBFED = 100;//Falling delay
//	EPwm4Regs.DBRED = 100;//Raising delay
	
	// Set ETSEL
	EPwm4Regs.ETSEL.bit.INTSEL	= ET_CTRD_CMPB;	// 2:0EPWMxINTn Select
	EPwm4Regs.ETSEL.bit.INTEN	= ET_ENABLE;		// 3EPWMxINTn Enable
	EPwm4Regs.ETSEL.bit.SOCASEL	= ET_CTR_ZERO;		// 10:8Start of conversion A Select
	EPwm4Regs.ETSEL.bit.SOCAEN	= ET_ENABLE;		// 11Start of conversion A Enable
	EPwm4Regs.ETSEL.bit.SOCBSEL	= ET_CTR_ZERO;			// 14:12  Start of conversion B Select  
	EPwm4Regs.ETSEL.bit.SOCBEN	= ET_ENABLE;		// 15Start of conversion B Enable

	EPwm4Regs.ETPS.bit.INTPRD	= ET_1ST;		// 1:0EPWMxINTn Period Select
	EPwm4Regs.ETPS.bit.INTCNT	= 0;			// 3:2EPWMxINTn Counter Register 
	EPwm4Regs.ETPS.bit.SOCAPRD	= ET_1ST;		// 9:8EPWMxSOCA Period Select
	EPwm4Regs.ETPS.bit.SOCACNT	= 0;			// 11:10  EPWMxSOCA Counter Register 
	EPwm4Regs.ETPS.bit.SOCBPRD	= ET_1ST;		// 13:12  EPWMxSOCB Period Select
	EPwm4Regs.ETPS.bit.SOCBCNT	= 0;			// 15:14  EPWMxSOCB Counter Register 
//	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS; 	
}
//#endif 

//******************************************************************
// 函数名	:void InitEPwm5Driver(void)
// 作者		:何志军
// 功能		:初始化系统ePWM5寄存髋渲?
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	送丝机H桥驱动
//******************************************************************
//#if DSP28_EPWM5
void InitEPwm5Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	EPwm5Regs.TBPRD 			= 1000;
	EPwm5Regs.TBPHS.all			= 0;
	EPwm5Regs.TBCTR				= 0;

	// Setup TBCLK
	EPwm5Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;		// Count up
	EPwm5Regs.TBCTL.bit.PHSEN		= TB_ENABLE;	// Disable phase loading  
	EPwm5Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm5Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_IN;
	EPwm5Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm5Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm5Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm5Regs.TBCTL.bit.PHSDIR		= 1; 
	EPwm5Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compare 
	EPwm5Regs.CMPA.half.CMPA = Motor_PERIOD - 5;
	EPwm5Regs.CMPB = 5;

	// Setup CMPCTL 
	EPwm5Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm5Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm5Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm5Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm5Regs.AQCTLA.bit.CAU = AQ_SET;					// Set PWM6A
	EPwm5Regs.AQCTLA.bit.CAD = AQ_CLEAR;
	EPwm5Regs.AQCTLB.bit.CBU = AQ_CLEAR;				// Set PWM6B
	EPwm5Regs.AQCTLB.bit.CBD = AQ_SET;
	
	// set deadband
	// EPwm5Regs.DBCTL.bit.OUT_MODE = DB_DISABLE;// Dead-band Output Mode Control
	// EPwm5Regs.DBCTL.bit.POLSEL= DB_ACTV_HI;// Polarity Select Control
			// EPwm5Regs.DBCTL.bit.IN_MODE  = DBB_ALL;// Dead Band Input Mode Control
	// EPwm5Regs.DBFED = 100;//Falling delay
	// EPwm5Regs.DBRED = 100;//Raising delay

	EPwm5Regs.ETSEL.bit.INTSEL	= ET_CTRD_CMPB;			// 2:0EPWMxINTn Select
	EPwm5Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable
	EPwm5Regs.ETSEL.bit.SOCASEL	= ET_CTR_ZERO;// 10:8Start of conversion A Select  
	EPwm5Regs.ETSEL.bit.SOCAEN	= ET_DISABLE;			// 11Start of conversion A Enable  
	EPwm5Regs.ETSEL.bit.SOCBSEL	= ET_CTR_ZERO;	// 14:12  Start of conversion B Select  
	EPwm5Regs.ETSEL.bit.SOCBEN	= ET_DISABLE;			// 15Start of conversion B Enable  

	EPwm5Regs.ETPS.bit.INTPRD = 1;		// 1:0EPWMxINTn Period Select
	EPwm5Regs.ETPS.bit.INTCNT = 0;		// 3:2EPWMxINTn Counter Register 
	EPwm5Regs.ETPS.bit.SOCAPRD = 0;		// 9:8EPWMxSOCA Period Select
	EPwm5Regs.ETPS.bit.SOCACNT = 0;		// 11:10  EPWMxSOCA Counter Register 
	EPwm5Regs.ETPS.bit.SOCBPRD = 0;		// 13:12  EPWMxSOCB Period Select
	EPwm5Regs.ETPS.bit.SOCBCNT = 0;		// 15:14  EPWMxSOCB Counter Register 

//	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS; 
}
//#endif 

//******************************************************************
// 函数名	:void InitEPwm6Driver(void)
// 作者		:TI
// 功能		:初始化系统ePWM6寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	加热阀控制
//******************************************************************
//#if DSP28_EPWM6//

void InitEPwm6Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	EPwm6Regs.TBPRD 			= 1500;
	EPwm6Regs.TBPHS.all			= 0;
	EPwm6Regs.TBCTR				= 0;
	EPwm6Regs.TBPHS.half.TBPHS	= 0;

	// Setup TBCLK
	EPwm6Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// Count up
	EPwm6Regs.TBCTL.bit.PHSEN		= TB_DISABLE;// Disable phase loading  
	EPwm6Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm6Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_DISABLE;
	EPwm6Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm6Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm6Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm6Regs.TBCTL.bit.PHSDIR		= 1;
	EPwm6Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compare 
	EPwm6Regs.CMPA.half.CMPA  = 3;
	// Setup CMPCTL 
	EPwm6Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm6Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm6Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm6Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm6Regs.AQCTLA.bit.CAU = AQ_CLEAR;				// Set PWM6A
	EPwm6Regs.AQCTLA.bit.ZRO = AQ_SET;

	EPwm6Regs.ETSEL.bit.INTSEL	= ET_CTR_PRD;			// 2:0EPWMxINTn Select
	EPwm6Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable

	EPwm6Regs.ETPS.bit.INTPRD = 1;		// 1:0EPWMxINTn Period Select
	EPwm6Regs.ETPS.bit.INTCNT = 0;		// 3:2EPWMxINTn Counter Register
	EPwm6Regs.AQCSFRC.bit.CSFA = 0;
	EPwm6Regs.AQCSFRC.bit.CSFB = 0;// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS; 
}
//#endif 

//******************************************************************
// 函数名	:void InitEPwm7Driver(void)
// 作者		:TI
// 功能		:初始化系统ePWM7寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改绷浚何?
// 备注		:	Slope Compensation PWM Control	(Hardware
//******************************************************************
//#if DSP28_EPWM7
void InitEPwm7Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	EPwm7Regs.TBPRD 			= 1000;//3130--10K
	EPwm7Regs.TBPHS.all			= 0;
	EPwm7Regs.TBCTR				= 0;
	EPwm7Regs.TBPHS.half.TBPHS	= 0;

	// Setup TBCLK
	EPwm7Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// Count up
	EPwm7Regs.TBCTL.bit.PHSEN		= TB_DISABLE;		// Disable phase loading  
	EPwm7Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm7Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_DISABLE;
	EPwm7Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm7Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm7Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm7Regs.TBCTL.bit.PHSDIR		= 1;
	EPwm7Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compare 
	EPwm7Regs.CMPB = 0;
	// Setup CMPCTL 
	EPwm7Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm7Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm7Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm7Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	// EPwm7Regs.AQCTLB.bit.CBU = AQ_CLEAR;				// Set PWM7B
	// EPwm7Regs.AQCTLB.bit.CBD = AQ_SET;
	EPwm7Regs.AQCTLB.bit.ZRO = AQ_SET;
	EPwm7Regs.AQCTLB.bit.CBU = AQ_CLEAR;

	EPwm7Regs.ETSEL.bit.INTSEL	= ET_CTRD_CMPB;			// 2:0EPWMxINTn Select
	EPwm7Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable

	EPwm7Regs.ETPS.bit.INTPRD = 1;		// 1:0EPWMxINTn Period Select
	EPwm7Regs.ETPS.bit.INTCNT = 0;		// 3:2EPWMxINTn Counter Register

//	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS; 
}
//#endif 


/******************************************************************/
//函数名:void InitTzDriver(void)
//功能:Initialize the TZ Module for epwm1,epwm2,epwm4,epwm5 and epwm6 of WPPM3312Z
//备注:2015.06.25
//===========================================================================
void InitTzDriver(void)
{// Enable TZ1/TZ2 and TZ3 as one shot trip sources on EPwm1 Module
	EALLOW;
	EPwm1Regs.TZSEL.bit.CBC1 = 1;
	//EPwm1Regs.TZSEL.bit.OSHT1 = 1;
	//EPwm1Regs.TZSEL.bit.DCBEVT1 = 1;
	EPwm1Regs.TZSEL.bit.DCAEVT1 = 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm1Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	EPwm1Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	EPwm1Regs.TZCTL.bit.DCAEVT1 = 2;
	// EPwm1Regs.TZCTL.bit.DCBEVT1= 2;

	// EPwm1Regs.TZDCSEL.bit.DCBEVT1 = TZ_DCBH_LOW;
	EPwm1Regs.TZDCSEL.bit.DCAEVT1 = TZ_DCAH_HI;
	// Enable TZ interrupt
	// EPwm1Regs.TZEINT.bit.OST = 1;
	// EDIS;
	// Enable  TZ1\TZ2 and TZ3 as one shot trip sources on EPwm2 Module
	// EALLOW;
	EPwm2Regs.TZSEL.bit.CBC1 = 1;  
	//EPwm2Regs.TZSEL.bit.OSHT1 = 1;  
	// EPwm2Regs.TZSEL.bit.DCBEVT1= 1;
	EPwm2Regs.TZSEL.bit.DCAEVT1= 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm2Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	EPwm2Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	EPwm2Regs.TZCTL.bit.DCAEVT1 = 2;
	// EPwm2Regs.TZCTL.bit.DCBEVT1 = 2;

	// EPwm2Regs.TZDCSEL.bit.DCBEVT1 = TZ_DCBH_LOW;
	EPwm2Regs.TZDCSEL.bit.DCAEVT1 = TZ_DCAH_HI;
	// Enable TZ interrupt
	// EPwm2Regs.TZEINT.bit.OST = 1;
	// EDIS;
	// Enable TZ1/TZ2 and TZ3 as one shot trip sources on EPwm4 Module
	EPwm3Regs.TZSEL.bit.CBC3 = 1;//FAN

	EPwm3Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	// EALLOW;
	// EPwm4Regs.TZSEL.bit.CBC1 = 1;
	EPwm4Regs.TZSEL.bit.DCAEVT2 = 1;
	// EPwm4Regs.TZSEL.bit.DCBEVT2 = 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm4Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	EPwm4Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	// EPwm4Regs.TZCTL.bit.DCAEVT2 = 2;
	// EPwm4Regs.TZCTL.bit.DCBEVT2 = 2;


	// EPwm4Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCBH_LOW;
	EPwm4Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_LOW;
	// Enable TZ interrupt
	// EPwm4Regs.TZEINT.bit.OST = 1;
	// EDIS;
	
	
	// Enable TZ1/TZ2 and TZ3 as one shot trip sources on EPwm5 Module
	// EALLOW;
	// EPwm5Regs.TZSEL.bit.CBC1 = 1;
	// EPwm5Regs.TZSEL.bit.CBC2 = 1;
	//EPwm5Regs.TZSEL.bit.CBC3 = 1;//FAN
	EPwm5Regs.TZSEL.bit.DCAEVT2 = 1;
	// EPwm5Regs.TZSEL.bit.DCAEVT2 = 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm5Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	EPwm5Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	// EPwm5Regs.TZCTL.bit.DCAEVT2 = 2;
	// EPwm5Regs.TZCTL.bit.DCBEVT2 = 2;

	EPwm5Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_LOW;
	// EPwm5Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_LOW;
	// Enable TZ interrupt
	// EPwm5Regs.TZEINT.bit.OST = 1;
	// EDIS;
	
	// Enable TZ1\TZ2 and TZ3 as one shot trip sources on EPwm3 Module
	// EALLOW;
	// EPwm6Regs.TZSEL.bit.CBC1 = 1;
	EPwm6Regs.TZSEL.bit.CBC2 = 1;///JRF
	// EPwm6Regs.TZSEL.bit.CBC3 = 1;
	// EPwm6Regs.TZSEL.bit.DCAEVT2= 1;
	// EPwm6Regs.TZSEL.bit.DCBEVT2 = 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm6Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	// EPwm6Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	// EPwm6Regs.TZCTL.bit.DCAEVT2 = 2;
	// EPwm6Regs.TZCTL.bit.DCBEVT2 = 2;

	// EPwm6Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCBH_LOW;
	// EPwm6Regs.TZDCSEL.bit.DCAEVT2= TZ_DCAH_HI;
	// EPwm7Regs.TZSEL.bit.CBC2 = 1;//JRF
	// EPwm7Regs.TZCTL.bit.TZA = TZ_FORCE_LO;

	// Enable TZ interrupt
	// EPwm6Regs.TZEINT.bit.OST = 1;
	EDIS;
	
	
}

/***********************************************************/
//函数名:void InitDCEventDriver
//功能:Initialize Digtal Compare Event Module
//备注:DC Event for protecting Power and Motor
//===========================================================================
void InitDCEventDriver(void)
{
	
	// Define an event (DCAEVT1) based on TZ1 and TZ2
	EALLOW;
	EPwm1Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP1OUT;// DCAH = Comparator 1 output and TZ1 input
	// EPwm1Regs.DCTRIPSEL.bit.DCBHCOMPSEL = DC_TZ1 ;
	EPwm1Regs.DCACTL.bit.EVT1SRCSEL = DC_EVT1;// DCAEVT1 = DCAEVT1(not filtered)
	EPwm1Regs.DCACTL.bit.EVT1FRCSYNCSEL = DC_EVT_ASYNC;

	EPwm2Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP1OUT;// DCAH = Comparator 1 output AND TZ1 input
	// EPwm2Regs.DCTRIPSEL.bit.DCBHCOMPSEL = DC_TZ1;
	EPwm2Regs.DCACTL.bit.EVT1SRCSEL = DC_EVT1;// DCAEVT1 = DCAEVT1 (not filtered)
	EPwm2Regs.DCACTL.bit.EVT1FRCSYNCSEL = DC_EVT_ASYNC;

	EPwm4Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP2OUT;// DCAH = Comparator 2 output
	EPwm4Regs.DCACTL.bit.EVT2SRCSEL = DC_EVT2;// DCAEVT2 = DCAEVT2 (not filtered)
	EPwm4Regs.DCACTL.bit.EVT2FRCSYNCSEL = DC_EVT_ASYNC;// Take async path

	EPwm5Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP2OUT;// DCAH = Comparator 2 output
	EPwm5Regs.DCACTL.bit.EVT2SRCSEL = DC_EVT2;// DCAEVT2= DCAEVT2 (not filtered)
	EPwm5Regs.DCACTL.bit.EVT2FRCSYNCSEL = DC_EVT_ASYNC;// Take async path

	EDIS;
}


//===========================================================================
// End of file.
//===========================================================================

----------------------以上为DSP2803x_EPwm.c-----------------------------------------------------------

ke ma:

回复 Jordan Zhou:

DACVAL的更新在中断函数里面,它是PI计算出来的值,一个PWM周期更新一次。

在使用TMS320f28034这款芯片的单周期斩波功能,遇到了一些问题如下:

        ePWM的频率设置为20kHZ;ePWM1,ePWM2,ePWM3同步;ePWM1A和ePWM2A驱动全桥,控制逆变电源(ePWM1B和ePWM2B不使用);ePWM3A和ePWM3B用来做斜波补偿,和电流反馈信号一起从Comp1的一个端口进入,Comp1的另一个端口为软件计算的值写入DACVAL,对ePWM1A,ePWM2A进行斩波。现在发现在一个ePWM周期内出现多次斩波的现象。见附件。
下图通道1为全桥驱动;通道2为ePWM1A(最大占空比设置为50%);通道3为ePWM2A(最大占空比设置为50%);通道4为ePWM3A(占空比设置为50%)和ePWM3B(占空比设置为50%)+反馈电流;a b之间为一个周期。
//###########################################################################
//
// FILE:DSP2803x_Comp.c
//
// TITLE:DSP2803x Comparator Initialization & Support Functions.
//
//###########################################################################
// $TI Release: F2803x C/C++ Header Files and Peripheral Examples V127 $
// $Release Date: March 30, 2013 $
//###########################################################################

#include "DSP2803x_Device.h"// DSP2803x Headerfile Include File
#include "DSP2803x_Examples.h"// DSP2803x Examples Include File


void InitCompDriver(void);
void InitCompGpio(void);
void InitComp(void);

void InitComp(void)
{

	InitCompGpio();
	InitCompDriver();

}


void InitCompGpio()
{InitComp1Gpio();
}

void InitComp1Gpio()
{EALLOW;GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1;// Disable pull-up for GPIO1 (CMP1OUT)GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 3;// Configure GPIO1 for CMP1OUT operationGpioCtrlRegs.AIOMUX1.bit.AIO2 = 2;// Configure AIO2 for CMP1A (analog input) operationSysCtrlRegs.PCLKCR3.bit.COMP1ENCLK = 1;//EDIS;
}

#if DSP28_COMP2
void InitComp2Gpio()
{EALLOW;GpioCtrlRegs.AIOMUX1.bit.AIO4 = 2;// Configure AIO4 for CMP2A (analog input) operationEDIS;
}

#endif //end DSP28_COMP2

#if DSP28_COMP3
void InitComp3Gpio()
{EALLOW;GpioCtrlRegs.AIOMUX1.bit.AIO6 = 2;// Configure AIO6 for CMP3A (analog input) operationEDIS;
}

#endif //end DSP28_COMP3




/**********************************************************************************/
//函数名:void IntiCompDriver(void);
//功能:比较器模块初始化
//备注:
/*********************************************************************************/
void InitCompDriver()
{EALLOW;SysCtrlRegs.PCLKCR3.bit.COMP1ENCLK = 1;// Enable clock to the Comparator 1 blockComp1Regs.DACVAL.bit.DACVAL = 300;//C_CTCurr_Pro;Comp1Regs.COMPCTL.bit.COMPDACEN = 1;// Power up Comparator 1 locallyComp1Regs.COMPCTL.bit.COMPSOURCE = 0;Comp1Regs.COMPCTL.bit.CMPINV = 0;Comp1Regs.COMPCTL.bit.QUALSEL = 6;Comp1Regs.COMPCTL.bit.SYNCSEL =1;EDIS;
}


//===========================================================================
// End of file.
//===========================================================================
-----------------------------------以上为DSP2803x_Comp.c----------------------------------------------------------------
//**************************************************************************
//	Copyright(c)2017-DR_Welding
//	文件名称	:	WPCM2315CU2_Isr.c
//	作者		:	
//	模块功能	:系统中断
//	局部函数列表: 	无
//  更改记录	:
//	日期		DR版本		作者		备注
//	
//**************************************************************************

#define		in_interrupt

#include	"DSP2803x_Header.h"// Headerfile Include File
#include	"WPPM3312M2_Isr.h"
#include	"WPPM3312M2_SysReg.h"
#include	"WPPM3312M2_SysMacro.h"
#include	"WPPM3312M2_GlobalVarDef.h"
#include	"WPPM3312M2_EepromDriver.h"
#include	"WPPM3312M2_Can.h"
#include	"WPPM3312M2_Struct.h"
//#include"WPPM3312M2_LedShow.h"
#include"WPPM3312M2_KeyDispose.h"

//============================
//		内部函数声明
//============================
void vPwm1IntIsr(void);
void vTimer0IntIsr(void);
void IsrVarInit(void);

//******************************************************************
// 函数名	:void InitInterrupt(void)
// 作者		:
// 功能		:中断模块初始化
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	
//******************************************************************
void InitInterrupt(void)
{EALLOW;  	
	// 定义PWM1的中断向量PieVectTable.EPWM1_INT = &vPwm1IntIsr;PieCtrlRegs.PIEIER3.bit.INTx1 = 1;IER |= M_INT3;EDIS;  
}
//******************************************************************
// 函数名	:void vPwm1IntIsr(void)
// 作者		:
// 功能		:主拓扑PWM中断
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	
//******************************************************************
interrupt void vPwm1IntIsr(void)
{	
	//========= 更新主功率移相角=========mEnablePowerPwm();
	mSetPwm1Duty(1500);		
	PidLogic();//PI处理	

//======================== 清中断标志并再次使能中断 ===========================	
	EPwm1Regs.ETCLR.bit.INT = 1;
	PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;	
}

/****************************************************************************/
//函数名:void PidUpGrading(int PidResult);
// 作者		:MaKe
//功能:比较器模块更新PID计算结果
// 参数		:PidResult :PID计算结果
// 祷?:无
// 调用全局变量:无
// 修改全局变量:无
//备注:2018.06.29
/************************************************************************/
void PidUpGrading(int PidResult)
{EALLOW;Comp1Regs.DACVAL.bit.DACVAL = PidResult;	//C_CTCurr_Pro;//原边过流保护点EDIS;
}
------------------------------以上为WPCM2315CU2_Isr.c------------------------------------------------------------------------------//**************************************************************************
//	***
//	文件名称	:	DSP2803x_EPwm.c
//	作者		:	
//	模块功能	:DSP2803x EPwm Initialization & Support Functions.
//	局部函数列表: 	无
//	版本信息	:	TI File $Revision: /main/3 $
// 					Checkin $Date: November 10, 200914:05:11 $
//					$TI Release: 2803x C/C++ Header Files V1.21 $
// 					$Release Date: December 1, 2009 $
//  更改记录	:
//**************************************************************************


#include	"DSP2803x_Header.h"// Headerfile Include File
#include	"WPPM3312M2_SysMacro.h"
#include	"WPPM3312M2_SysReg.h"
#include	"DSP2803x_Device.h"




//============================
//		内部函数声明
//============================
void InitEPwmGpio(void);
void InitEPwm1Gpio(void);
void InitEPwm2Gpio(void);
void InitEPwm3Gpio(void);
void InitEPwm4Gpio(void);
void InitEPwm5Gpio(void);
void InitEPwm6Gpio(void);
void InitEPwm7Gpio(void);

void InitEPwmDriver(void);
void InitEPwm1Driver(void);
void InitEPwm2Driver(void);
void InitEPwm3Driver(void);
void InitEPwm4Driver(void);
void InitEPwm5Driver(void);
void InitEPwm6Driver(void);
void InitEPwm7Driver(void);

void InitTzGpio(void);
void InitTzDriver(void);
void InitDCEventDriver(void);

//******************************************************************
// 函数名	:void InitEPwm(void)
// 作者		:TI
// 功能		:初始化系统PWM模块及管脚设置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
void InitEPwm(void)
{
	// 配置管脚功能

	EALLOW;
	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;  
	EDIS;

	InitEPwmGpio();
//	InitTzGpio();
	// 初始化寄存器

//	InitTzDriver();
//	InitDCEventDriver();
	InitEPwmDriver();
	//mUpDatePwm2Phase(0);
	mUpDatePwm2Phase(1500);
	//mSetPwm4BDuty(0);

	mDisablePowerPwm();
	mDisableMotorPWM();

	mEnableMotorPWM();//////使能PWM3
//	mDisableJRFPWM();
//	mDisableFANPWM();

//	mDebugPWM(1000);  

	EALLOW;
	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;  
	EDIS;  
}


//******************************************************************
// 函数名	:void InitEPwmDriver(void)
// 作者		:TI
// 功能		:This function initializes GPIO pins to function as EPwm pins
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	Each GPIO pin can be configured as a GPIO pin or up to 3 different
// 				peripheral functional pins. By default all pins come up as GPIO
// 				inputs after reset.
//******************************************************************
void InitEPwmGpio(void)
{
#if DSP28_EPWM1InitEPwm1Gpio();
#endif // endif DSP28_EPWM1

#if DSP28_EPWM2InitEPwm2Gpio();
#endif // endif DSP28_EPWM2

#if DSP28_EPWM3InitEPwm3Gpio();
#endif // endif DSP28_EPWM3

#if DSP28_EPWM4// InitEPwm4Gpio();
#endif // endif DSP28_EPWM4

#if DSP28_EPWM5//InitEPwm5Gpio();
#endif // endif DSP28_EPWM5

#if DSP28_EPWM6//InitEPwm6Gpio();
#endif // endif DSP28_EPWM6

#if DSP28_EPWM7//InitEPwm7Gpio();
#endif // endif DSP28_EPWM7
}

//******************************************************************
// 函数名	:void InitEPwm1Gpio(void)
// 作者		:TI
// 功能		:初始化PWM1输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
#if DSP28_EPWM1
void InitEPwm1Gpio(void)
{
	EALLOW;

/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO0 = 1;// Disable pull-up on GPIO0 (EPWM1A)
	GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1;// Disable pull-up on GPIO1 (EPWM1B)

/* Configure EPWM-1 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM1 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1;// Configure GPIO0 as EPWM1A
	GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1;// Configure GPIO1 as EPWM1B

	EDIS;
}
#endif // endif DSP28_EPWM1

//******************************************************************
// 函数名	:void InitEPwm2Gpio(void)
// 作者		:TI
// 功能		:初始化PWM2输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM2
void InitEPwm2Gpio(void)
{
	EALLOW;

/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO2 = 1;// Disable pull-up on GPIO2 (EPWM2A)
	GpioCtrlRegs.GPAPUD.bit.GPIO3 = 1;// Disable pull-up on GPIO3 (EPWM2B)

/* Configure EPwm-2 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM2 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 1;// Configure GPIO2 as EPWM2A
	GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 1;// Configure GPIO3 as EPWM2B

	EDIS;
}
//#endif // endif DSP28_EPWM2

//******************************************************************
// 函数名	:void InitEPwm3Gpio(void)
// 作者		:TI
// 功能		:初始化PWM3输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM3
void InitEPwm3Gpio(void)
{
	EALLOW;

/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.GpioCtrlRegs.GPAPUD.bit.GPIO4 = 1;// Disable pull-up on GPIO4 (EPWM3A)
	GpioCtrlRegs.GPAPUD.bit.GPIO5 = 1;// Disable pull-up on GPIO5 (EPWM3B)

/* Configure EPwm-3 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM3 functional pins.
// Comment out other unwanted lines.GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 1;// Configure GPIO4 as EPWM3A
	GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 1;// Configure GPIO5 as EPWM3B

	EDIS;
}
//#endif // endif DSP28_EPWM3

//******************************************************************
// 函数名	:void InitEPwm4Gpio(void)
// 作者		:TI
// 功能		:初始化PWM4输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM4
void InitEPwm4Gpio(void)
{
	EALLOW;
/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO6 = 1;// Disable pull-up on GPIO6 (EPWM4A)
	GpioCtrlRegs.GPAPUD.bit.GPIO7 = 1;// Disable pull-up on GPIO7 (EPWM4B)

/* Configure EPWM-4 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM4 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 1;// Configure GPIO6 as EPWM4A
	GpioCtrlRegs.GPAMUX1.bit.GPIO7 = 1;// Configure GPIO7 as EPWM4B

	EDIS;
}
//#endif // endif DSP28_EPWM4

//******************************************************************
// 函数名	:void InitEPwm5Gpio(void)
// 作者		:
// 功能		:初始化PWM5输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:EPWM5模块只用到了GPIO9,故只初始化此管脚
//******************************************************************
//#if DSP28_EPWM5
void InitEPwm5Gpio(void)
{
	EALLOW;
/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO8 = 1;// Disable pull-up on GPIO8 (EPWM5A)
	GpioCtrlRegs.GPAPUD.bit.GPIO9 = 1;// Disable pull-up on GPIO9 (EPWM5B)

/* Configure EPWM-5 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM5 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO8 = 1;// Configure GPIO8 as EPWM5A
	GpioCtrlRegs.GPAMUX1.bit.GPIO9 = 1;// Configure GPIO9 as EPWM5B

	EDIS;
}
//#endif // endif DSP28_EPWM5

//******************************************************************
// 函数名	:void InitEPwm6Gpio(void)
// 作者		:TI
// 功能		:初始化PWM6输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM6
void InitEPwm6Gpio(void)
{
	EALLOW;
/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO10 = 1;// Disable pull-up on GPIO10 (EPWM6A)//GpioCtrlRegs.GPAPUD.bit.GPIO11 = 1;// Disable pull-up on GPIO11 (EPWM6B)

/* Configure EPWM-6 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM6 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO10 = 1;// Configure GPIO10 as EPWM6A//GpioCtrlRegs.GPAMUX1.bit.GPIO11 = 1;// Configure GPIO11 as EPWM6B

	EDIS;
}
//#endif // endif DSP28_EPWM6

//******************************************************************
// 函数名	:void InitEPwm7Gpio(void)
// 作者		:TI
// 功能		:初始化PWM7输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM7
void InitEPwm7Gpio(void)
{
	EALLOW;
/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.//GpioCtrlRegs.GPBPUD.bit.GPIO40 = 1;// Disable pull-up on GPIO40 (EPWM7A)
	GpioCtrlRegs.GPBPUD.bit.GPIO41 = 1;// Disable pull-up on GPIO41 (EPWM7B)

/* Configure EPWM-7 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM7 functional pins.
// Comment out other unwanted lines.// GpioCtrlRegs.GPBMUX1.bit.GPIO40 = 1;// Configure GPIO40 as EPWM7A
	GpioCtrlRegs.GPBMUX1.bit.GPIO41 = 1;// Configure GPIO41 as EPWM7B

	EDIS;
}
//#endif // endif DSP28_EPWM7


//******************************************************************
// 函数名	:void InitEPwmSyncGpio(void)
// 作者		:TI
// 功能		:This function initializes GPIO pins to function as EPwm Synch pins
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
void InitEPwmSyncGpio(void)
{

//EALLOW;

/* Configure EPWMSYNCI  */

/* Enable internal pull-up for the selected pins */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

// GpioCtrlRegs.GPAPUD.bit.GPIO6 = 0;// Enable pull-up on GPIO6 (EPWMSYNCI)
	GpioCtrlRegs.GPBPUD.bit.GPIO32 = 0;// Enable pull-up on GPIO32 (EPWMSYNCI)

/* Set qualification for selected pins to asynch only */
// This will select synch to SYSCLKOUT for the selected pins.
// Comment out other unwanted lines.

// GpioCtrlRegs.GPAQSEL1.bit.GPIO6 = 0;// Synch to SYSCLKOUT GPIO6 (EPWMSYNCI)
	GpioCtrlRegs.GPBQSEL1.bit.GPIO32 = 0;  // Synch to SYSCLKOUT GPIO32 (EPWMSYNCI)

/* Configure EPwmSync pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPwmSync functional pins.
// Comment out other unwanted lines.

// GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 2;// Configures GPIO6 for EPWMSYNCI operation
	GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 2;// Configures GPIO32 for EPWMSYNCI operation.

/* Configure EPWMSYNC0  */

/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// Comment out other unwanted lines.

// GpioCtrlRegs.GPAPUD.bit.GPIO6 = 1;// Disable pull-up on GPIO6 (EPWMSYNCO)
	GpioCtrlRegs.GPBPUD.bit.GPIO33 = 1;// Disable pull-up on GPIO33 (EPWMSYNCO)

// GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 3;// Configures GPIO6 for EPWMSYNCO
	GpioCtrlRegs.GPBMUX1.bit.GPIO33 = 2;  // Configures GPIO33 for EPWMSYNCO

}

//******************************************************************
// 函数名	:void InitTzGpio(void)
// 作者		:TI
// 功能		:This function initializes GPIO pins to function as Trip Zone (TZ) pins
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	Each GPIO pin can be configured as a GPIO pin or up to 3 different
// 				peripheral functional pins. By default all pins come up as GPIO
// 				inputs after reset.
//******************************************************************
void InitTzGpio(void)
{
	EALLOW;

/* Enable internal pull-up for the selected pins */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.
	GpioCtrlRegs.GPAPUD.bit.GPIO12 = 0;// Enable pull-up on GPIO12 (TZ1)
// GpioCtrlRegs.GPAPUD.bit.GPIO15 = 0;// Enable pull-up on GPIO15 (TZ1)
	GpioCtrlRegs.GPAPUD.bit.GPIO13 = 0;// Enable pull-up on GPIO13 (TZ2)
// GpioCtrlRegs.GPAPUD.bit.GPIO16 = 0;// Enable pull-up on GPIO16 (TZ2)
// GpioCtrlRegs.GPAPUD.bit.GPIO28 = 0;// Enable pull-up on GPIO28 (TZ2)
	GpioCtrlRegs.GPAPUD.bit.GPIO14 = 0;// Enable pull-up on GPIO14 (TZ3)
// GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0;// Enable pull-up on GPIO17 (TZ3)
// GpioCtrlRegs.GPAPUD.bit.GPIO29 = 0;// Enable pull-up on GPIO29 (TZ3)

/* Set qualification for selected pins to asynch only */
// Inputs are synchronized to SYSCLKOUT by default.
// This will select asynch (no qualification) for the selected pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAQSEL1.bit.GPIO12 = 3;  // Asynch input GPIO12 (TZ1)
// GpioCtrlRegs.GPAQSEL1.bit.GPIO15 = 3;  // Asynch input GPIO15 (TZ1)
	GpioCtrlRegs.GPAQSEL1.bit.GPIO13 = 3;  // Asynch input GPIO13 (TZ2)
// GpioCtrlRegs.GPAQSEL2.bit.GPIO16 = 3;  // Asynch input GPIO16 (TZ2)
// GpioCtrlRegs.GPAQSEL2.bit.GPIO28 = 3;  // Asynch input GPIO28 (TZ2)
	GpioCtrlRegs.GPAQSEL1.bit.GPIO14 = 3;  // Asynch input GPIO14 (TZ3)
// GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3;  // Asynch input GPIO17 (TZ3)
// GpioCtrlRegs.GPAQSEL2.bit.GPIO29 = 3;  // Asynch input GPIO29 (TZ3)


/* Configure TZ pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be TZ functional pins.
// Comment out other unwanted lines.
	GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 1;  // Configure GPIO12 as TZ1
//GpioCtrlRegs.GPAMUX1.bit.GPIO15 = 1;  // Configure GPIO15 as TZ1
	GpioCtrlRegs.GPAMUX1.bit.GPIO13 = 1;  // Configure GPIO13 as TZ2
// GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 3;  // Configure GPIO16 as TZ2
// GpioCtrlRegs.GPAMUX2.bit.GPIO28 = 3;  // Configure GPIO28 as TZ2
	GpioCtrlRegs.GPAMUX1.bit.GPIO14 = 1;  // Configure GPIO14 as TZ3
// GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 3;  // Configure GPIO17 as TZ3
// GpioCtrlRegs.GPAMUX2.bit.GPIO29 = 3;  // Configure GPIO29 as TZ3

	EDIS;

}

//******************************************************************
// 函数名	:void InitEPwmDriver(void)
// 作者		篢I
// 功能		:初始低砅WM模块寄存髋渲?
// 参数		:无
// 	:无
// 调用全局变量?
// 
// 备注
//******************************************************************
void InitEPwmDriver(void)
{ 
//#if DSP28_EPWM1InitEPwm1Driver();
//#endif 

//#if DSP28_EPWM2
	InitEPwm2Driver();
//#endif 

//#if DSP28_EPWM3
	InitEPwm3Driver();
//#endif 

//#if DSP28_EPWM4
	//InitEPwm4Driver();
//#endif 

//#if DSP28_EPWM5
	//InitEPwm5Driver();
//#endif 

//#if DSP28_EPWM6
//	InitEPwm6Driver();
//#endif 

#if DSP28_EPWM7
//	InitEPwm7Driver();
#endif 
}


//******************************************************************
// 函数名	:void InitEPwm1Driver(void)
// 作者		:TI
// 功		:初始化系统ePWM1寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	
//******************************************************************
#if DSP28_EPWM1
void InitEPwm1Driver(void)
{
	EALLOW;	
	EPwm1Regs.TBPRD 	= 3000;////PFSB_PERIOD,1250-48K
	//EPwm1Regs.TBPRD 	= 1500;////PFSB_PERIOD,1250-48K
	EPwm1Regs.TBPHS.all	= 0;
	EPwm1Regs.TBCTR		= 0;

	// Setup TBCLK
	EPwm1Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// Count up
	//EPwm1Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;
	EPwm1Regs.TBCTL.bit.PHSEN		= TB_DISABLE;		// Disable phase loading  
	EPwm1Regs.TBCTL.bit.PRDLD		= TB_SHADOW;		//
	EPwm1Regs.TBCTL.bit.SYNCOSEL	= TB_CTR_ZERO;//Count equal to zero; have a syn output
	EPwm1Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm1Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;			//
	EPwm1Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm1Regs.TBCTL.bit.PHSDIR		= 1; 
	EPwm1Regs.TBCTL.bit.FREE_SOFT	= 3;	//
	// Setup compare 
	EPwm1Regs.CMPA.half.CMPA= 1500;
	EPwm1Regs.CMPB = 1500;
	EPwm1Regs.TBPHS.half.TBPHS = 0;
	// Setup CMPCTL 
	EPwm1Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm1Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm1Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm1Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;/////
	EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;
	EPwm1Regs.AQCTLB.bit.ZRO = AQ_CLEAR;	
	EPwm1Regs.AQCTLB.bit.CBU = AQ_SET;

	//EPwm1Regs.AQSFRC.bit.RLDCSF = 0;

	
	//Set DeadBand
	EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;//
	EPwm1Regs.DBCTL.bit.IN_MODE = 0x0;
	EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
	//EPwm1Regs.DBFED = 200;//
	//EPwm1Regs.DBRED = 200;//
	EPwm1Regs.DBFED = 300;//
	EPwm1Regs.DBRED = 300;// 
	//EPwm1Regs.DBCTL.bit.HALFCYCLE = 1;

	//	// Set ETSEL
	EPwm1Regs.ETSEL.bit.INTSEL	= ET_CTR_ZERO;			// 2:0EPWMxINTn Select
	EPwm1Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable
	EPwm1Regs.ETSEL.bit.SOCASEL	= ET_CTRU_CMPA;			// 10:8Start of conversion A Select  
	EPwm1Regs.ETSEL.bit.SOCAEN	= ET_ENABLE;			// 11Start of conversion A Enable  
	EPwm1Regs.ETSEL.bit.SOCBSEL	= ET_CTRU_CMPB;			// 14:12  Start of conversion B Select	
	EPwm1Regs.ETSEL.bit.SOCBEN	= ET_ENABLE;			// 15Start of conversion B Enable

	EPwm1Regs.ETPS.bit.INTPRD	= ET_1ST;		// 1:0EPWMxINTn Period Select
	EPwm1Regs.ETPS.bit.INTCNT	= 0;		// 3:2EPWMxINTn Counter Register 
	EPwm1Regs.ETPS.bit.SOCAPRD	= ET_1ST;		// 9:8EPWMxSOCA Period Select
	EPwm1Regs.ETPS.bit.SOCACNT	= 0;		// 11:10  EPWMxSOCA Counter Register 
	EPwm1Regs.ETPS.bit.SOCBPRD	= 1;		// 13:12  EPWMxSOCB Period Select
	EPwm1Regs.ETPS.bit.SOCBCNT	= 0;		// 15:14  EPWMxSOCB Counter Register
 ///////////////////////////////////////////////////////EPwm1Regs.TZSEL.bit.DCAEVT2 = 1;//////EPwm1Regs.TZSEL.bit.DCAEVT2 = 0;//////EPwm1Regs.TZSEL.bit.DCBEVT2 = 0;//////EPwm1Regs.TZSEL.bit.DCBEVT2 = 1;EPwm1Regs.TZSEL.bit.CBC1=1;

// What do we want the TZ1 and TZ2 to doEPwm1Regs.TZCTL.bit.TZA = TZ_FORCE_LO;EPwm1Regs.TZCTL.bit.TZB = TZ_FORCE_LO;//EPwm1Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCBH_LOW; //TZ_DCAH_HI;//EPwm1Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCAH_LOW;EPwm1Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_HI;EPwm1Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCAH_HI;EPwm1Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP1OUT;// DCAH = Comparator 2 output
	EDIS;	
}
#endif 


//******************************************************************
// 函数名	:void InitEPwm2Driver(void)
// 作者		:TI
// 功能		初始化系统ePWM2寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	
//******************************************************************
#if DSP28_EPWM2
void InitEPwm2Driver(void)
{	EALLOW;
	//SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;	// Stop all the TB clocks	
	//EPwm2Regs.TBPRD 	= 1874;///48k
	EPwm2Regs.TBPRD 	= 3000;///20k// Count up
	//EPwm2Regs.TBPRD 	= 1500;///20k//Count updown
	EPwm2Regs.TBPHS.all	= 0;
	EPwm2Regs.TBCTR		= 0;

	// Setup TBCLK
	EPwm2Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// Count up
	//EPwm2Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;//Count updown
	EPwm2Regs.TBCTL.bit.PHSEN		= TB_ENABLE;		// Enable phase loading  
	EPwm2Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm2Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_IN;
	EPwm2Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm2Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm2Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm2Regs.TBCTL.bit.PHSDIR		= 1; 
	EPwm2Regs.TBCTL.bit.FREE_SOFT	= 3;				// 


	// Setup compare 
	EPwm2Regs.CMPA.half.CMPA= 1500;//
	EPwm2Regs.CMPB= 1500;//
	EPwm2Regs.TBPHS.half.TBPHS = 0;
	
	// Setup CMPCTL 
	EPwm2Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm2Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm2Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm2Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm2Regs.AQCTLA.bit.ZRO = AQ_SET;
	EPwm2Regs.AQCTLA.bit.CAU = AQ_CLEAR;
	EPwm2Regs.AQCTLB.bit.ZRO = AQ_CLEAR ;
	EPwm2Regs.AQCTLB.bit.CBU = AQ_SET;
	
//	EPwm2Regs.AQSFRC.bit.RLDCSF = 3;

	//Set DeadBand
 	EPwm2Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
	EPwm2Regs.DBCTL.bit.IN_MODE = 0x0;
	EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
	//EPwm2Regs.DBFED = 200 ;//
	//EPwm2Regs.DBRED = 200;
	EPwm2Regs.DBFED = 300;//
	EPwm2Regs.DBRED = 300; 
	////斩波比较模块
	//EPwm2Regs.TZSEL.bit.DCAEVT2 = 1;
	//EPwm2Regs.TZSEL.bit.DCAEVT2 = 0;
	//EPwm2Regs.TZSEL.bit.DCBEVT2 = 0;
	//EPwm2Regs.TZSEL.bit.DCBEVT2 = 1;
	EPwm2Regs.TZSEL.bit.CBC1=1;// What do we want the TZ1 and TZ2 to do?EPwm2Regs.TZCTL.bit.TZA = TZ_FORCE_LO;EPwm2Regs.TZCTL.bit.TZB = TZ_FORCE_LO;//EPwm2Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCBH_LOW;//EPwm2Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCBH_LOW;EPwm2Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_HI;EPwm2Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCAH_HI;EPwm2Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP1OUT; // DCAH = Comparator 2 outputEPwm2Regs.DCACTL.bit.EVT2SRCSEL = DC_EVT2;// DCAEVT2 = DCAEVT2 (not filtered)EPwm2Regs.DCACTL.bit.EVT2FRCSYNCSEL = DC_EVT_ASYNC;// Take async pathEPwm2Regs.TZEINT.bit.DCBEVT2=0;//??
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS;

}
#endif 

//******************************************************************
// 函数名	:void InitEPwm3Driver(void)
// 作者		:TI
// 功能		:初始化系统ePWM3寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM3
void InitEPwm3Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	//EPwm3Regs.TBPRD 			= Motor_PERIOD;
	EPwm3Regs.TBPRD 			= 3000;//1500;//C_MOTOR_PWM_PRD;
	EPwm3Regs.TBPHS.all			= 0;
	EPwm3Regs.TBCTR				= 0;
	EPwm3Regs.TBPHS.half.TBPHS	= 0;

	// Setup TBCLK
	//EPwm3Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;		// Count up
	EPwm3Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// 对称波形输出 
	EPwm3Regs.TBCTL.bit.PHSEN		= TB_DISABLE;// Disable phase loading  
	EPwm3Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	//EPwm3Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_DISABLE;
	EPwm3Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_IN;	//  Count equal to zero; have a syn output
	EPwm3Regs.TBCTL.bit.SWFSYNC		= 0; 
	//EPwm3Regs.TBCTL.bit.HSPCLKDIV	= 0x04;///1/8
	EPwm3Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
//	EPwm3Regs.TBCTL.bit.CLKDIV		= 0x04;///1/16 
	EPwm3Regs.TBCTL.bit.CLKDIV		= TB_DIV1;
	EPwm3Regs.TBCTL.bit.PHSDIR		= 1;
	EPwm3Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compareEPwm3Regs.CMPA.half.CMPA =1500;
	EPwm3Regs.CMPB  = 0;
	// Setup CMPCTL 
	EPwm3Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm3Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm3Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm3Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm3Regs.AQCTLA.bit.CAU = AQ_CLEAR;			// 
	EPwm3Regs.AQCTLA.bit.PRD = AQ_SET;				//  
	EPwm3Regs.AQCTLB.bit.CBU = AQ_SET;				// 
	EPwm3Regs.AQCTLB.bit.PRD = AQ_CLEAR;	// 

	EPwm3Regs.ETSEL.bit.INTSEL	= ET_CTR_PRD;			// 2:0EPWMxINTn Select
	EPwm3Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable
	
/////////////////////////////////////////////////////
	//死区模块(DB)配置
	EPwm3Regs.DBCTL.bit.OUT_MODE =DB_FULL_ENABLE;
	EPwm3Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
	EPwm3Regs.DBCTL.bit.IN_MODE = 0;
	//EPwm3Regs.DBCTL.bit.HALFCYCLE = 0;
	EPwm3Regs.DBFED = 200;//Falling delay
	EPwm3Regs.DBRED = 200;  //Raising delay  //0.01667*300=5U

	// 事件触发模块(EZ)配置
	EPwm3Regs.ETSEL.bit.INTSEL	= ET_CTRD_CMPA;		// 2:0EPWMxINTn Select
	EPwm3Regs.ETSEL.bit.INTEN	= ET_DISABLE;		// 3EPWMxINTn Enable
	EPwm3Regs.ETSEL.bit.SOCASEL	= ET_CTR_ZERO;		// 10:8Start of conversion A Select  
	EPwm3Regs.ETSEL.bit.SOCAEN	= ET_ENABLE;		// 11Start of conversion A Enable  
	EPwm3Regs.ETSEL.bit.SOCBSEL	= ET_CTR_ZERO;		// 14:12  Start of conversion B Select  
	EPwm3Regs.ETSEL.bit.SOCBEN	= ET_ENABLE;		// 15Start of conversion B Enable  

	EPwm3Regs.ETPS.bit.INTPRD = 1;		// 1:0EPWMxINTn Period Select
	EPwm3Regs.ETPS.bit.INTCNT = 0;		// 3:2EPWMxINTn Counter Register 
	EPwm3Regs.ETPS.bit.SOCAPRD = 1;		// 9:8EPWMxSOCA Period Select
	EPwm3Regs.ETPS.bit.SOCACNT = 0;		// 11:10  EPWMxSOCA Counter Register 
	EPwm3Regs.ETPS.bit.SOCBPRD = 1;		// 13:12  EPWMxSOCB Period Select
	EPwm3Regs.ETPS.bit.SOCBCNT = 0;	 	// 15:14  EPWMxSOCB Counter Register 	
	EDIS; 
}
//#endif 
//******************************************************************
// 函数名	:void InitEPwm4Driver(void)
// 作者		:TI
// 功能		:初始化系统ePWM4寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	送丝机H桥驱动
//******************************************************************
//#if DSP28_EPWM4
void InitEPwm4Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	
	EPwm4Regs.TBPRD 			= 1000;
	EPwm4Regs.TBPHS.all			= 0;
	EPwm4Regs.TBCTR				= 0;
	EPwm4Regs.TBPHS.half.TBPHS	= 0;
	
	// Setup TBCLK
	EPwm4Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;	// Count up and down 
	EPwm4Regs.TBCTL.bit.PHSEN		= TB_DISABLE;		// Disable phase loading  
	EPwm4Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm4Regs.TBCTL.bit.SYNCOSEL	= TB_CTR_ZERO;
	EPwm4Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm4Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm4Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm4Regs.TBCTL.bit.PHSDIR		= 1; 
	EPwm4Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compare 
	EPwm4Regs.CMPA.half.CMPA = Motor_PERIOD - 5;
	EPwm4Regs.CMPB = 5;

	// Setup CMPCTL 
	EPwm4Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm4Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm4Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm4Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm4Regs.AQCTLA.bit.CAU =  AQ_SET;					// Set PWM4A
	EPwm4Regs.AQCTLA.bit.CAD =  AQ_CLEAR;
	EPwm4Regs.AQCTLB.bit.CBU = AQ_CLEAR;				// Set PWM4B
	EPwm4Regs.AQCTLB.bit.CBD = AQ_SET;

//	EPwm4Regs.AQSFRC.bit.RLDCSF = 3;

	// Set deadband
//	EPwm4Regs.DBCTL.bit.OUT_MODE = DB_DISABLE;// Dead-band Output Mode Control
//	EPwm4Regs.DBCTL.bit.POLSEL= DB_ACTV_HI;// Polarity Select Control
//	EPwm4Regs.DBCTL.bit.IN_MODE  = DBB_ALL;// Dead Band Input Mode Control
//	EPwm4Regs.DBFED = 100;//Falling delay
//	EPwm4Regs.DBRED = 100;//Raising delay
	
	// Set ETSEL
	EPwm4Regs.ETSEL.bit.INTSEL	= ET_CTRD_CMPB;	// 2:0EPWMxINTn Select
	EPwm4Regs.ETSEL.bit.INTEN	= ET_ENABLE;		// 3EPWMxINTn Enable
	EPwm4Regs.ETSEL.bit.SOCASEL	= ET_CTR_ZERO;		// 10:8Start of conversion A Select
	EPwm4Regs.ETSEL.bit.SOCAEN	= ET_ENABLE;		// 11Start of conversion A Enable
	EPwm4Regs.ETSEL.bit.SOCBSEL	= ET_CTR_ZERO;			// 14:12  Start of conversion B Select  
	EPwm4Regs.ETSEL.bit.SOCBEN	= ET_ENABLE;		// 15Start of conversion B Enable

	EPwm4Regs.ETPS.bit.INTPRD	= ET_1ST;		// 1:0EPWMxINTn Period Select
	EPwm4Regs.ETPS.bit.INTCNT	= 0;			// 3:2EPWMxINTn Counter Register 
	EPwm4Regs.ETPS.bit.SOCAPRD	= ET_1ST;		// 9:8EPWMxSOCA Period Select
	EPwm4Regs.ETPS.bit.SOCACNT	= 0;			// 11:10  EPWMxSOCA Counter Register 
	EPwm4Regs.ETPS.bit.SOCBPRD	= ET_1ST;		// 13:12  EPWMxSOCB Period Select
	EPwm4Regs.ETPS.bit.SOCBCNT	= 0;			// 15:14  EPWMxSOCB Counter Register 
//	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS; 	
}
//#endif 

//******************************************************************
// 函数名	:void InitEPwm5Driver(void)
// 作者		:何志军
// 功能		:初始化系统ePWM5寄存髋渲?
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	送丝机H桥驱动
//******************************************************************
//#if DSP28_EPWM5
void InitEPwm5Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	EPwm5Regs.TBPRD 			= 1000;
	EPwm5Regs.TBPHS.all			= 0;
	EPwm5Regs.TBCTR				= 0;

	// Setup TBCLK
	EPwm5Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;		// Count up
	EPwm5Regs.TBCTL.bit.PHSEN		= TB_ENABLE;	// Disable phase loading  
	EPwm5Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm5Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_IN;
	EPwm5Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm5Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm5Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm5Regs.TBCTL.bit.PHSDIR		= 1; 
	EPwm5Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compare 
	EPwm5Regs.CMPA.half.CMPA = Motor_PERIOD - 5;
	EPwm5Regs.CMPB = 5;

	// Setup CMPCTL 
	EPwm5Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm5Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm5Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm5Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm5Regs.AQCTLA.bit.CAU = AQ_SET;					// Set PWM6A
	EPwm5Regs.AQCTLA.bit.CAD = AQ_CLEAR;
	EPwm5Regs.AQCTLB.bit.CBU = AQ_CLEAR;				// Set PWM6B
	EPwm5Regs.AQCTLB.bit.CBD = AQ_SET;
	
	// set deadband
	// EPwm5Regs.DBCTL.bit.OUT_MODE = DB_DISABLE;// Dead-band Output Mode Control
	// EPwm5Regs.DBCTL.bit.POLSEL= DB_ACTV_HI;// Polarity Select Control
			// EPwm5Regs.DBCTL.bit.IN_MODE  = DBB_ALL;// Dead Band Input Mode Control
	// EPwm5Regs.DBFED = 100;//Falling delay
	// EPwm5Regs.DBRED = 100;//Raising delay

	EPwm5Regs.ETSEL.bit.INTSEL	= ET_CTRD_CMPB;			// 2:0EPWMxINTn Select
	EPwm5Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable
	EPwm5Regs.ETSEL.bit.SOCASEL	= ET_CTR_ZERO;// 10:8Start of conversion A Select  
	EPwm5Regs.ETSEL.bit.SOCAEN	= ET_DISABLE;			// 11Start of conversion A Enable  
	EPwm5Regs.ETSEL.bit.SOCBSEL	= ET_CTR_ZERO;	// 14:12  Start of conversion B Select  
	EPwm5Regs.ETSEL.bit.SOCBEN	= ET_DISABLE;			// 15Start of conversion B Enable  

	EPwm5Regs.ETPS.bit.INTPRD = 1;		// 1:0EPWMxINTn Period Select
	EPwm5Regs.ETPS.bit.INTCNT = 0;		// 3:2EPWMxINTn Counter Register 
	EPwm5Regs.ETPS.bit.SOCAPRD = 0;		// 9:8EPWMxSOCA Period Select
	EPwm5Regs.ETPS.bit.SOCACNT = 0;		// 11:10  EPWMxSOCA Counter Register 
	EPwm5Regs.ETPS.bit.SOCBPRD = 0;		// 13:12  EPWMxSOCB Period Select
	EPwm5Regs.ETPS.bit.SOCBCNT = 0;		// 15:14  EPWMxSOCB Counter Register 

//	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS; 
}
//#endif 

//******************************************************************
// 函数名	:void InitEPwm6Driver(void)
// 作者		:TI
// 功能		:初始化系统ePWM6寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	加热阀控制
//******************************************************************
//#if DSP28_EPWM6//

void InitEPwm6Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	EPwm6Regs.TBPRD 			= 1500;
	EPwm6Regs.TBPHS.all			= 0;
	EPwm6Regs.TBCTR				= 0;
	EPwm6Regs.TBPHS.half.TBPHS	= 0;

	// Setup TBCLK
	EPwm6Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// Count up
	EPwm6Regs.TBCTL.bit.PHSEN		= TB_DISABLE;// Disable phase loading  
	EPwm6Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm6Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_DISABLE;
	EPwm6Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm6Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm6Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm6Regs.TBCTL.bit.PHSDIR		= 1;
	EPwm6Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compare 
	EPwm6Regs.CMPA.half.CMPA  = 3;
	// Setup CMPCTL 
	EPwm6Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm6Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm6Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm6Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm6Regs.AQCTLA.bit.CAU = AQ_CLEAR;				// Set PWM6A
	EPwm6Regs.AQCTLA.bit.ZRO = AQ_SET;

	EPwm6Regs.ETSEL.bit.INTSEL	= ET_CTR_PRD;			// 2:0EPWMxINTn Select
	EPwm6Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable

	EPwm6Regs.ETPS.bit.INTPRD = 1;		// 1:0EPWMxINTn Period Select
	EPwm6Regs.ETPS.bit.INTCNT = 0;		// 3:2EPWMxINTn Counter Register
	EPwm6Regs.AQCSFRC.bit.CSFA = 0;
	EPwm6Regs.AQCSFRC.bit.CSFB = 0;// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS; 
}
//#endif 

//******************************************************************
// 函数名	:void InitEPwm7Driver(void)
// 作者		:TI
// 功能		:初始化系统ePWM7寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改绷浚何?
// 备注		:	Slope Compensation PWM Control	(Hardware
//******************************************************************
//#if DSP28_EPWM7
void InitEPwm7Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	EPwm7Regs.TBPRD 			= 1000;//3130--10K
	EPwm7Regs.TBPHS.all			= 0;
	EPwm7Regs.TBCTR				= 0;
	EPwm7Regs.TBPHS.half.TBPHS	= 0;

	// Setup TBCLK
	EPwm7Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// Count up
	EPwm7Regs.TBCTL.bit.PHSEN		= TB_DISABLE;		// Disable phase loading  
	EPwm7Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm7Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_DISABLE;
	EPwm7Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm7Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm7Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm7Regs.TBCTL.bit.PHSDIR		= 1;
	EPwm7Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compare 
	EPwm7Regs.CMPB = 0;
	// Setup CMPCTL 
	EPwm7Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm7Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm7Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm7Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	// EPwm7Regs.AQCTLB.bit.CBU = AQ_CLEAR;				// Set PWM7B
	// EPwm7Regs.AQCTLB.bit.CBD = AQ_SET;
	EPwm7Regs.AQCTLB.bit.ZRO = AQ_SET;
	EPwm7Regs.AQCTLB.bit.CBU = AQ_CLEAR;

	EPwm7Regs.ETSEL.bit.INTSEL	= ET_CTRD_CMPB;			// 2:0EPWMxINTn Select
	EPwm7Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable

	EPwm7Regs.ETPS.bit.INTPRD = 1;		// 1:0EPWMxINTn Period Select
	EPwm7Regs.ETPS.bit.INTCNT = 0;		// 3:2EPWMxINTn Counter Register

//	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS; 
}
//#endif 


/******************************************************************/
//函数名:void InitTzDriver(void)
//功能:Initialize the TZ Module for epwm1,epwm2,epwm4,epwm5 and epwm6 of WPPM3312Z
//备注:2015.06.25
//===========================================================================
void InitTzDriver(void)
{// Enable TZ1/TZ2 and TZ3 as one shot trip sources on EPwm1 Module
	EALLOW;
	EPwm1Regs.TZSEL.bit.CBC1 = 1;
	//EPwm1Regs.TZSEL.bit.OSHT1 = 1;
	//EPwm1Regs.TZSEL.bit.DCBEVT1 = 1;
	EPwm1Regs.TZSEL.bit.DCAEVT1 = 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm1Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	EPwm1Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	EPwm1Regs.TZCTL.bit.DCAEVT1 = 2;
	// EPwm1Regs.TZCTL.bit.DCBEVT1= 2;

	// EPwm1Regs.TZDCSEL.bit.DCBEVT1 = TZ_DCBH_LOW;
	EPwm1Regs.TZDCSEL.bit.DCAEVT1 = TZ_DCAH_HI;
	// Enable TZ interrupt
	// EPwm1Regs.TZEINT.bit.OST = 1;
	// EDIS;
	// Enable  TZ1\TZ2 and TZ3 as one shot trip sources on EPwm2 Module
	// EALLOW;
	EPwm2Regs.TZSEL.bit.CBC1 = 1;  
	//EPwm2Regs.TZSEL.bit.OSHT1 = 1;  
	// EPwm2Regs.TZSEL.bit.DCBEVT1= 1;
	EPwm2Regs.TZSEL.bit.DCAEVT1= 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm2Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	EPwm2Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	EPwm2Regs.TZCTL.bit.DCAEVT1 = 2;
	// EPwm2Regs.TZCTL.bit.DCBEVT1 = 2;

	// EPwm2Regs.TZDCSEL.bit.DCBEVT1 = TZ_DCBH_LOW;
	EPwm2Regs.TZDCSEL.bit.DCAEVT1 = TZ_DCAH_HI;
	// Enable TZ interrupt
	// EPwm2Regs.TZEINT.bit.OST = 1;
	// EDIS;
	// Enable TZ1/TZ2 and TZ3 as one shot trip sources on EPwm4 Module
	EPwm3Regs.TZSEL.bit.CBC3 = 1;//FAN

	EPwm3Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	// EALLOW;
	// EPwm4Regs.TZSEL.bit.CBC1 = 1;
	EPwm4Regs.TZSEL.bit.DCAEVT2 = 1;
	// EPwm4Regs.TZSEL.bit.DCBEVT2 = 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm4Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	EPwm4Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	// EPwm4Regs.TZCTL.bit.DCAEVT2 = 2;
	// EPwm4Regs.TZCTL.bit.DCBEVT2 = 2;


	// EPwm4Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCBH_LOW;
	EPwm4Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_LOW;
	// Enable TZ interrupt
	// EPwm4Regs.TZEINT.bit.OST = 1;
	// EDIS;
	
	
	// Enable TZ1/TZ2 and TZ3 as one shot trip sources on EPwm5 Module
	// EALLOW;
	// EPwm5Regs.TZSEL.bit.CBC1 = 1;
	// EPwm5Regs.TZSEL.bit.CBC2 = 1;
	//EPwm5Regs.TZSEL.bit.CBC3 = 1;//FAN
	EPwm5Regs.TZSEL.bit.DCAEVT2 = 1;
	// EPwm5Regs.TZSEL.bit.DCAEVT2 = 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm5Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	EPwm5Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	// EPwm5Regs.TZCTL.bit.DCAEVT2 = 2;
	// EPwm5Regs.TZCTL.bit.DCBEVT2 = 2;

	EPwm5Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_LOW;
	// EPwm5Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_LOW;
	// Enable TZ interrupt
	// EPwm5Regs.TZEINT.bit.OST = 1;
	// EDIS;
	
	// Enable TZ1\TZ2 and TZ3 as one shot trip sources on EPwm3 Module
	// EALLOW;
	// EPwm6Regs.TZSEL.bit.CBC1 = 1;
	EPwm6Regs.TZSEL.bit.CBC2 = 1;///JRF
	// EPwm6Regs.TZSEL.bit.CBC3 = 1;
	// EPwm6Regs.TZSEL.bit.DCAEVT2= 1;
	// EPwm6Regs.TZSEL.bit.DCBEVT2 = 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm6Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	// EPwm6Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	// EPwm6Regs.TZCTL.bit.DCAEVT2 = 2;
	// EPwm6Regs.TZCTL.bit.DCBEVT2 = 2;

	// EPwm6Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCBH_LOW;
	// EPwm6Regs.TZDCSEL.bit.DCAEVT2= TZ_DCAH_HI;
	// EPwm7Regs.TZSEL.bit.CBC2 = 1;//JRF
	// EPwm7Regs.TZCTL.bit.TZA = TZ_FORCE_LO;

	// Enable TZ interrupt
	// EPwm6Regs.TZEINT.bit.OST = 1;
	EDIS;
	
	
}

/***********************************************************/
//函数名:void InitDCEventDriver
//功能:Initialize Digtal Compare Event Module
//备注:DC Event for protecting Power and Motor
//===========================================================================
void InitDCEventDriver(void)
{
	
	// Define an event (DCAEVT1) based on TZ1 and TZ2
	EALLOW;
	EPwm1Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP1OUT;// DCAH = Comparator 1 output and TZ1 input
	// EPwm1Regs.DCTRIPSEL.bit.DCBHCOMPSEL = DC_TZ1 ;
	EPwm1Regs.DCACTL.bit.EVT1SRCSEL = DC_EVT1;// DCAEVT1 = DCAEVT1(not filtered)
	EPwm1Regs.DCACTL.bit.EVT1FRCSYNCSEL = DC_EVT_ASYNC;

	EPwm2Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP1OUT;// DCAH = Comparator 1 output AND TZ1 input
	// EPwm2Regs.DCTRIPSEL.bit.DCBHCOMPSEL = DC_TZ1;
	EPwm2Regs.DCACTL.bit.EVT1SRCSEL = DC_EVT1;// DCAEVT1 = DCAEVT1 (not filtered)
	EPwm2Regs.DCACTL.bit.EVT1FRCSYNCSEL = DC_EVT_ASYNC;

	EPwm4Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP2OUT;// DCAH = Comparator 2 output
	EPwm4Regs.DCACTL.bit.EVT2SRCSEL = DC_EVT2;// DCAEVT2 = DCAEVT2 (not filtered)
	EPwm4Regs.DCACTL.bit.EVT2FRCSYNCSEL = DC_EVT_ASYNC;// Take async path

	EPwm5Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP2OUT;// DCAH = Comparator 2 output
	EPwm5Regs.DCACTL.bit.EVT2SRCSEL = DC_EVT2;// DCAEVT2= DCAEVT2 (not filtered)
	EPwm5Regs.DCACTL.bit.EVT2FRCSYNCSEL = DC_EVT_ASYNC;// Take async path

	EDIS;
}


//===========================================================================
// End of file.
//===========================================================================

----------------------以上为DSP2803x_EPwm.c-----------------------------------------------------------

ke ma:

回复 Jordan Zhou:

能抓取到DACVAL的值。它是PI计算出来的值,一个PWM周期更新一次。我设置了EPwm1Regs.TZSEL.bit.CBC1=1;期望得到的是一个PWM周期只斩一次波。

在使用TMS320f28034这款芯片的单周期斩波功能,遇到了一些问题如下:

        ePWM的频率设置为20kHZ;ePWM1,ePWM2,ePWM3同步;ePWM1A和ePWM2A驱动全桥,控制逆变电源(ePWM1B和ePWM2B不使用);ePWM3A和ePWM3B用来做斜波补偿,和电流反馈信号一起从Comp1的一个端口进入,Comp1的另一个端口为软件计算的值写入DACVAL,对ePWM1A,ePWM2A进行斩波。现在发现在一个ePWM周期内出现多次斩波的现象。见附件。
下图通道1为全桥驱动;通道2为ePWM1A(最大占空比设置为50%);通道3为ePWM2A(最大占空比设置为50%);通道4为ePWM3A(占空比设置为50%)和ePWM3B(占空比设置为50%)+反馈电流;a b之间为一个周期。
//###########################################################################
//
// FILE:DSP2803x_Comp.c
//
// TITLE:DSP2803x Comparator Initialization & Support Functions.
//
//###########################################################################
// $TI Release: F2803x C/C++ Header Files and Peripheral Examples V127 $
// $Release Date: March 30, 2013 $
//###########################################################################

#include "DSP2803x_Device.h"// DSP2803x Headerfile Include File
#include "DSP2803x_Examples.h"// DSP2803x Examples Include File


void InitCompDriver(void);
void InitCompGpio(void);
void InitComp(void);

void InitComp(void)
{

	InitCompGpio();
	InitCompDriver();

}


void InitCompGpio()
{InitComp1Gpio();
}

void InitComp1Gpio()
{EALLOW;GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1;// Disable pull-up for GPIO1 (CMP1OUT)GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 3;// Configure GPIO1 for CMP1OUT operationGpioCtrlRegs.AIOMUX1.bit.AIO2 = 2;// Configure AIO2 for CMP1A (analog input) operationSysCtrlRegs.PCLKCR3.bit.COMP1ENCLK = 1;//EDIS;
}

#if DSP28_COMP2
void InitComp2Gpio()
{EALLOW;GpioCtrlRegs.AIOMUX1.bit.AIO4 = 2;// Configure AIO4 for CMP2A (analog input) operationEDIS;
}

#endif //end DSP28_COMP2

#if DSP28_COMP3
void InitComp3Gpio()
{EALLOW;GpioCtrlRegs.AIOMUX1.bit.AIO6 = 2;// Configure AIO6 for CMP3A (analog input) operationEDIS;
}

#endif //end DSP28_COMP3




/**********************************************************************************/
//函数名:void IntiCompDriver(void);
//功能:比较器模块初始化
//备注:
/*********************************************************************************/
void InitCompDriver()
{EALLOW;SysCtrlRegs.PCLKCR3.bit.COMP1ENCLK = 1;// Enable clock to the Comparator 1 blockComp1Regs.DACVAL.bit.DACVAL = 300;//C_CTCurr_Pro;Comp1Regs.COMPCTL.bit.COMPDACEN = 1;// Power up Comparator 1 locallyComp1Regs.COMPCTL.bit.COMPSOURCE = 0;Comp1Regs.COMPCTL.bit.CMPINV = 0;Comp1Regs.COMPCTL.bit.QUALSEL = 6;Comp1Regs.COMPCTL.bit.SYNCSEL =1;EDIS;
}


//===========================================================================
// End of file.
//===========================================================================
-----------------------------------以上为DSP2803x_Comp.c----------------------------------------------------------------
//**************************************************************************
//	Copyright(c)2017-DR_Welding
//	文件名称	:	WPCM2315CU2_Isr.c
//	作者		:	
//	模块功能	:系统中断
//	局部函数列表: 	无
//  更改记录	:
//	日期		DR版本		作者		备注
//	
//**************************************************************************

#define		in_interrupt

#include	"DSP2803x_Header.h"// Headerfile Include File
#include	"WPPM3312M2_Isr.h"
#include	"WPPM3312M2_SysReg.h"
#include	"WPPM3312M2_SysMacro.h"
#include	"WPPM3312M2_GlobalVarDef.h"
#include	"WPPM3312M2_EepromDriver.h"
#include	"WPPM3312M2_Can.h"
#include	"WPPM3312M2_Struct.h"
//#include"WPPM3312M2_LedShow.h"
#include"WPPM3312M2_KeyDispose.h"

//============================
//		内部函数声明
//============================
void vPwm1IntIsr(void);
void vTimer0IntIsr(void);
void IsrVarInit(void);

//******************************************************************
// 函数名	:void InitInterrupt(void)
// 作者		:
// 功能		:中断模块初始化
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	
//******************************************************************
void InitInterrupt(void)
{EALLOW;  	
	// 定义PWM1的中断向量PieVectTable.EPWM1_INT = &vPwm1IntIsr;PieCtrlRegs.PIEIER3.bit.INTx1 = 1;IER |= M_INT3;EDIS;  
}
//******************************************************************
// 函数名	:void vPwm1IntIsr(void)
// 作者		:
// 功能		:主拓扑PWM中断
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	
//******************************************************************
interrupt void vPwm1IntIsr(void)
{	
	//========= 更新主功率移相角=========mEnablePowerPwm();
	mSetPwm1Duty(1500);		
	PidLogic();//PI处理	

//======================== 清中断标志并再次使能中断 ===========================	
	EPwm1Regs.ETCLR.bit.INT = 1;
	PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;	
}

/****************************************************************************/
//函数名:void PidUpGrading(int PidResult);
// 作者		:MaKe
//功能:比较器模块更新PID计算结果
// 参数		:PidResult :PID计算结果
// 祷?:无
// 调用全局变量:无
// 修改全局变量:无
//备注:2018.06.29
/************************************************************************/
void PidUpGrading(int PidResult)
{EALLOW;Comp1Regs.DACVAL.bit.DACVAL = PidResult;	//C_CTCurr_Pro;//原边过流保护点EDIS;
}
------------------------------以上为WPCM2315CU2_Isr.c------------------------------------------------------------------------------//**************************************************************************
//	***
//	文件名称	:	DSP2803x_EPwm.c
//	作者		:	
//	模块功能	:DSP2803x EPwm Initialization & Support Functions.
//	局部函数列表: 	无
//	版本信息	:	TI File $Revision: /main/3 $
// 					Checkin $Date: November 10, 200914:05:11 $
//					$TI Release: 2803x C/C++ Header Files V1.21 $
// 					$Release Date: December 1, 2009 $
//  更改记录	:
//**************************************************************************


#include	"DSP2803x_Header.h"// Headerfile Include File
#include	"WPPM3312M2_SysMacro.h"
#include	"WPPM3312M2_SysReg.h"
#include	"DSP2803x_Device.h"




//============================
//		内部函数声明
//============================
void InitEPwmGpio(void);
void InitEPwm1Gpio(void);
void InitEPwm2Gpio(void);
void InitEPwm3Gpio(void);
void InitEPwm4Gpio(void);
void InitEPwm5Gpio(void);
void InitEPwm6Gpio(void);
void InitEPwm7Gpio(void);

void InitEPwmDriver(void);
void InitEPwm1Driver(void);
void InitEPwm2Driver(void);
void InitEPwm3Driver(void);
void InitEPwm4Driver(void);
void InitEPwm5Driver(void);
void InitEPwm6Driver(void);
void InitEPwm7Driver(void);

void InitTzGpio(void);
void InitTzDriver(void);
void InitDCEventDriver(void);

//******************************************************************
// 函数名	:void InitEPwm(void)
// 作者		:TI
// 功能		:初始化系统PWM模块及管脚设置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
void InitEPwm(void)
{
	// 配置管脚功能

	EALLOW;
	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;  
	EDIS;

	InitEPwmGpio();
//	InitTzGpio();
	// 初始化寄存器

//	InitTzDriver();
//	InitDCEventDriver();
	InitEPwmDriver();
	//mUpDatePwm2Phase(0);
	mUpDatePwm2Phase(1500);
	//mSetPwm4BDuty(0);

	mDisablePowerPwm();
	mDisableMotorPWM();

	mEnableMotorPWM();//////使能PWM3
//	mDisableJRFPWM();
//	mDisableFANPWM();

//	mDebugPWM(1000);  

	EALLOW;
	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;  
	EDIS;  
}


//******************************************************************
// 函数名	:void InitEPwmDriver(void)
// 作者		:TI
// 功能		:This function initializes GPIO pins to function as EPwm pins
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	Each GPIO pin can be configured as a GPIO pin or up to 3 different
// 				peripheral functional pins. By default all pins come up as GPIO
// 				inputs after reset.
//******************************************************************
void InitEPwmGpio(void)
{
#if DSP28_EPWM1InitEPwm1Gpio();
#endif // endif DSP28_EPWM1

#if DSP28_EPWM2InitEPwm2Gpio();
#endif // endif DSP28_EPWM2

#if DSP28_EPWM3InitEPwm3Gpio();
#endif // endif DSP28_EPWM3

#if DSP28_EPWM4// InitEPwm4Gpio();
#endif // endif DSP28_EPWM4

#if DSP28_EPWM5//InitEPwm5Gpio();
#endif // endif DSP28_EPWM5

#if DSP28_EPWM6//InitEPwm6Gpio();
#endif // endif DSP28_EPWM6

#if DSP28_EPWM7//InitEPwm7Gpio();
#endif // endif DSP28_EPWM7
}

//******************************************************************
// 函数名	:void InitEPwm1Gpio(void)
// 作者		:TI
// 功能		:初始化PWM1输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
#if DSP28_EPWM1
void InitEPwm1Gpio(void)
{
	EALLOW;

/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO0 = 1;// Disable pull-up on GPIO0 (EPWM1A)
	GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1;// Disable pull-up on GPIO1 (EPWM1B)

/* Configure EPWM-1 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM1 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1;// Configure GPIO0 as EPWM1A
	GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1;// Configure GPIO1 as EPWM1B

	EDIS;
}
#endif // endif DSP28_EPWM1

//******************************************************************
// 函数名	:void InitEPwm2Gpio(void)
// 作者		:TI
// 功能		:初始化PWM2输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM2
void InitEPwm2Gpio(void)
{
	EALLOW;

/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO2 = 1;// Disable pull-up on GPIO2 (EPWM2A)
	GpioCtrlRegs.GPAPUD.bit.GPIO3 = 1;// Disable pull-up on GPIO3 (EPWM2B)

/* Configure EPwm-2 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM2 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 1;// Configure GPIO2 as EPWM2A
	GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 1;// Configure GPIO3 as EPWM2B

	EDIS;
}
//#endif // endif DSP28_EPWM2

//******************************************************************
// 函数名	:void InitEPwm3Gpio(void)
// 作者		:TI
// 功能		:初始化PWM3输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM3
void InitEPwm3Gpio(void)
{
	EALLOW;

/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.GpioCtrlRegs.GPAPUD.bit.GPIO4 = 1;// Disable pull-up on GPIO4 (EPWM3A)
	GpioCtrlRegs.GPAPUD.bit.GPIO5 = 1;// Disable pull-up on GPIO5 (EPWM3B)

/* Configure EPwm-3 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM3 functional pins.
// Comment out other unwanted lines.GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 1;// Configure GPIO4 as EPWM3A
	GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 1;// Configure GPIO5 as EPWM3B

	EDIS;
}
//#endif // endif DSP28_EPWM3

//******************************************************************
// 函数名	:void InitEPwm4Gpio(void)
// 作者		:TI
// 功能		:初始化PWM4输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM4
void InitEPwm4Gpio(void)
{
	EALLOW;
/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO6 = 1;// Disable pull-up on GPIO6 (EPWM4A)
	GpioCtrlRegs.GPAPUD.bit.GPIO7 = 1;// Disable pull-up on GPIO7 (EPWM4B)

/* Configure EPWM-4 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM4 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 1;// Configure GPIO6 as EPWM4A
	GpioCtrlRegs.GPAMUX1.bit.GPIO7 = 1;// Configure GPIO7 as EPWM4B

	EDIS;
}
//#endif // endif DSP28_EPWM4

//******************************************************************
// 函数名	:void InitEPwm5Gpio(void)
// 作者		:
// 功能		:初始化PWM5输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:EPWM5模块只用到了GPIO9,故只初始化此管脚
//******************************************************************
//#if DSP28_EPWM5
void InitEPwm5Gpio(void)
{
	EALLOW;
/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO8 = 1;// Disable pull-up on GPIO8 (EPWM5A)
	GpioCtrlRegs.GPAPUD.bit.GPIO9 = 1;// Disable pull-up on GPIO9 (EPWM5B)

/* Configure EPWM-5 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM5 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO8 = 1;// Configure GPIO8 as EPWM5A
	GpioCtrlRegs.GPAMUX1.bit.GPIO9 = 1;// Configure GPIO9 as EPWM5B

	EDIS;
}
//#endif // endif DSP28_EPWM5

//******************************************************************
// 函数名	:void InitEPwm6Gpio(void)
// 作者		:TI
// 功能		:初始化PWM6输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM6
void InitEPwm6Gpio(void)
{
	EALLOW;
/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO10 = 1;// Disable pull-up on GPIO10 (EPWM6A)//GpioCtrlRegs.GPAPUD.bit.GPIO11 = 1;// Disable pull-up on GPIO11 (EPWM6B)

/* Configure EPWM-6 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM6 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO10 = 1;// Configure GPIO10 as EPWM6A//GpioCtrlRegs.GPAMUX1.bit.GPIO11 = 1;// Configure GPIO11 as EPWM6B

	EDIS;
}
//#endif // endif DSP28_EPWM6

//******************************************************************
// 函数名	:void InitEPwm7Gpio(void)
// 作者		:TI
// 功能		:初始化PWM7输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM7
void InitEPwm7Gpio(void)
{
	EALLOW;
/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.//GpioCtrlRegs.GPBPUD.bit.GPIO40 = 1;// Disable pull-up on GPIO40 (EPWM7A)
	GpioCtrlRegs.GPBPUD.bit.GPIO41 = 1;// Disable pull-up on GPIO41 (EPWM7B)

/* Configure EPWM-7 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM7 functional pins.
// Comment out other unwanted lines.// GpioCtrlRegs.GPBMUX1.bit.GPIO40 = 1;// Configure GPIO40 as EPWM7A
	GpioCtrlRegs.GPBMUX1.bit.GPIO41 = 1;// Configure GPIO41 as EPWM7B

	EDIS;
}
//#endif // endif DSP28_EPWM7


//******************************************************************
// 函数名	:void InitEPwmSyncGpio(void)
// 作者		:TI
// 功能		:This function initializes GPIO pins to function as EPwm Synch pins
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
void InitEPwmSyncGpio(void)
{

//EALLOW;

/* Configure EPWMSYNCI  */

/* Enable internal pull-up for the selected pins */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

// GpioCtrlRegs.GPAPUD.bit.GPIO6 = 0;// Enable pull-up on GPIO6 (EPWMSYNCI)
	GpioCtrlRegs.GPBPUD.bit.GPIO32 = 0;// Enable pull-up on GPIO32 (EPWMSYNCI)

/* Set qualification for selected pins to asynch only */
// This will select synch to SYSCLKOUT for the selected pins.
// Comment out other unwanted lines.

// GpioCtrlRegs.GPAQSEL1.bit.GPIO6 = 0;// Synch to SYSCLKOUT GPIO6 (EPWMSYNCI)
	GpioCtrlRegs.GPBQSEL1.bit.GPIO32 = 0;  // Synch to SYSCLKOUT GPIO32 (EPWMSYNCI)

/* Configure EPwmSync pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPwmSync functional pins.
// Comment out other unwanted lines.

// GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 2;// Configures GPIO6 for EPWMSYNCI operation
	GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 2;// Configures GPIO32 for EPWMSYNCI operation.

/* Configure EPWMSYNC0  */

/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// Comment out other unwanted lines.

// GpioCtrlRegs.GPAPUD.bit.GPIO6 = 1;// Disable pull-up on GPIO6 (EPWMSYNCO)
	GpioCtrlRegs.GPBPUD.bit.GPIO33 = 1;// Disable pull-up on GPIO33 (EPWMSYNCO)

// GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 3;// Configures GPIO6 for EPWMSYNCO
	GpioCtrlRegs.GPBMUX1.bit.GPIO33 = 2;  // Configures GPIO33 for EPWMSYNCO

}

//******************************************************************
// 函数名	:void InitTzGpio(void)
// 作者		:TI
// 功能		:This function initializes GPIO pins to function as Trip Zone (TZ) pins
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	Each GPIO pin can be configured as a GPIO pin or up to 3 different
// 				peripheral functional pins. By default all pins come up as GPIO
// 				inputs after reset.
//******************************************************************
void InitTzGpio(void)
{
	EALLOW;

/* Enable internal pull-up for the selected pins */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.
	GpioCtrlRegs.GPAPUD.bit.GPIO12 = 0;// Enable pull-up on GPIO12 (TZ1)
// GpioCtrlRegs.GPAPUD.bit.GPIO15 = 0;// Enable pull-up on GPIO15 (TZ1)
	GpioCtrlRegs.GPAPUD.bit.GPIO13 = 0;// Enable pull-up on GPIO13 (TZ2)
// GpioCtrlRegs.GPAPUD.bit.GPIO16 = 0;// Enable pull-up on GPIO16 (TZ2)
// GpioCtrlRegs.GPAPUD.bit.GPIO28 = 0;// Enable pull-up on GPIO28 (TZ2)
	GpioCtrlRegs.GPAPUD.bit.GPIO14 = 0;// Enable pull-up on GPIO14 (TZ3)
// GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0;// Enable pull-up on GPIO17 (TZ3)
// GpioCtrlRegs.GPAPUD.bit.GPIO29 = 0;// Enable pull-up on GPIO29 (TZ3)

/* Set qualification for selected pins to asynch only */
// Inputs are synchronized to SYSCLKOUT by default.
// This will select asynch (no qualification) for the selected pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAQSEL1.bit.GPIO12 = 3;  // Asynch input GPIO12 (TZ1)
// GpioCtrlRegs.GPAQSEL1.bit.GPIO15 = 3;  // Asynch input GPIO15 (TZ1)
	GpioCtrlRegs.GPAQSEL1.bit.GPIO13 = 3;  // Asynch input GPIO13 (TZ2)
// GpioCtrlRegs.GPAQSEL2.bit.GPIO16 = 3;  // Asynch input GPIO16 (TZ2)
// GpioCtrlRegs.GPAQSEL2.bit.GPIO28 = 3;  // Asynch input GPIO28 (TZ2)
	GpioCtrlRegs.GPAQSEL1.bit.GPIO14 = 3;  // Asynch input GPIO14 (TZ3)
// GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3;  // Asynch input GPIO17 (TZ3)
// GpioCtrlRegs.GPAQSEL2.bit.GPIO29 = 3;  // Asynch input GPIO29 (TZ3)


/* Configure TZ pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be TZ functional pins.
// Comment out other unwanted lines.
	GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 1;  // Configure GPIO12 as TZ1
//GpioCtrlRegs.GPAMUX1.bit.GPIO15 = 1;  // Configure GPIO15 as TZ1
	GpioCtrlRegs.GPAMUX1.bit.GPIO13 = 1;  // Configure GPIO13 as TZ2
// GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 3;  // Configure GPIO16 as TZ2
// GpioCtrlRegs.GPAMUX2.bit.GPIO28 = 3;  // Configure GPIO28 as TZ2
	GpioCtrlRegs.GPAMUX1.bit.GPIO14 = 1;  // Configure GPIO14 as TZ3
// GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 3;  // Configure GPIO17 as TZ3
// GpioCtrlRegs.GPAMUX2.bit.GPIO29 = 3;  // Configure GPIO29 as TZ3

	EDIS;

}

//******************************************************************
// 函数名	:void InitEPwmDriver(void)
// 作者		篢I
// 功能		:初始低砅WM模块寄存髋渲?
// 参数		:无
// 	:无
// 调用全局变量?
// 
// 备注
//******************************************************************
void InitEPwmDriver(void)
{ 
//#if DSP28_EPWM1InitEPwm1Driver();
//#endif 

//#if DSP28_EPWM2
	InitEPwm2Driver();
//#endif 

//#if DSP28_EPWM3
	InitEPwm3Driver();
//#endif 

//#if DSP28_EPWM4
	//InitEPwm4Driver();
//#endif 

//#if DSP28_EPWM5
	//InitEPwm5Driver();
//#endif 

//#if DSP28_EPWM6
//	InitEPwm6Driver();
//#endif 

#if DSP28_EPWM7
//	InitEPwm7Driver();
#endif 
}


//******************************************************************
// 函数名	:void InitEPwm1Driver(void)
// 作者		:TI
// 功		:初始化系统ePWM1寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	
//******************************************************************
#if DSP28_EPWM1
void InitEPwm1Driver(void)
{
	EALLOW;	
	EPwm1Regs.TBPRD 	= 3000;////PFSB_PERIOD,1250-48K
	//EPwm1Regs.TBPRD 	= 1500;////PFSB_PERIOD,1250-48K
	EPwm1Regs.TBPHS.all	= 0;
	EPwm1Regs.TBCTR		= 0;

	// Setup TBCLK
	EPwm1Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// Count up
	//EPwm1Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;
	EPwm1Regs.TBCTL.bit.PHSEN		= TB_DISABLE;		// Disable phase loading  
	EPwm1Regs.TBCTL.bit.PRDLD		= TB_SHADOW;		//
	EPwm1Regs.TBCTL.bit.SYNCOSEL	= TB_CTR_ZERO;//Count equal to zero; have a syn output
	EPwm1Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm1Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;			//
	EPwm1Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm1Regs.TBCTL.bit.PHSDIR		= 1; 
	EPwm1Regs.TBCTL.bit.FREE_SOFT	= 3;	//
	// Setup compare 
	EPwm1Regs.CMPA.half.CMPA= 1500;
	EPwm1Regs.CMPB = 1500;
	EPwm1Regs.TBPHS.half.TBPHS = 0;
	// Setup CMPCTL 
	EPwm1Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm1Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm1Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm1Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;/////
	EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;
	EPwm1Regs.AQCTLB.bit.ZRO = AQ_CLEAR;	
	EPwm1Regs.AQCTLB.bit.CBU = AQ_SET;

	//EPwm1Regs.AQSFRC.bit.RLDCSF = 0;

	
	//Set DeadBand
	EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;//
	EPwm1Regs.DBCTL.bit.IN_MODE = 0x0;
	EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
	//EPwm1Regs.DBFED = 200;//
	//EPwm1Regs.DBRED = 200;//
	EPwm1Regs.DBFED = 300;//
	EPwm1Regs.DBRED = 300;// 
	//EPwm1Regs.DBCTL.bit.HALFCYCLE = 1;

	//	// Set ETSEL
	EPwm1Regs.ETSEL.bit.INTSEL	= ET_CTR_ZERO;			// 2:0EPWMxINTn Select
	EPwm1Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable
	EPwm1Regs.ETSEL.bit.SOCASEL	= ET_CTRU_CMPA;			// 10:8Start of conversion A Select  
	EPwm1Regs.ETSEL.bit.SOCAEN	= ET_ENABLE;			// 11Start of conversion A Enable  
	EPwm1Regs.ETSEL.bit.SOCBSEL	= ET_CTRU_CMPB;			// 14:12  Start of conversion B Select	
	EPwm1Regs.ETSEL.bit.SOCBEN	= ET_ENABLE;			// 15Start of conversion B Enable

	EPwm1Regs.ETPS.bit.INTPRD	= ET_1ST;		// 1:0EPWMxINTn Period Select
	EPwm1Regs.ETPS.bit.INTCNT	= 0;		// 3:2EPWMxINTn Counter Register 
	EPwm1Regs.ETPS.bit.SOCAPRD	= ET_1ST;		// 9:8EPWMxSOCA Period Select
	EPwm1Regs.ETPS.bit.SOCACNT	= 0;		// 11:10  EPWMxSOCA Counter Register 
	EPwm1Regs.ETPS.bit.SOCBPRD	= 1;		// 13:12  EPWMxSOCB Period Select
	EPwm1Regs.ETPS.bit.SOCBCNT	= 0;		// 15:14  EPWMxSOCB Counter Register
 ///////////////////////////////////////////////////////EPwm1Regs.TZSEL.bit.DCAEVT2 = 1;//////EPwm1Regs.TZSEL.bit.DCAEVT2 = 0;//////EPwm1Regs.TZSEL.bit.DCBEVT2 = 0;//////EPwm1Regs.TZSEL.bit.DCBEVT2 = 1;EPwm1Regs.TZSEL.bit.CBC1=1;

// What do we want the TZ1 and TZ2 to doEPwm1Regs.TZCTL.bit.TZA = TZ_FORCE_LO;EPwm1Regs.TZCTL.bit.TZB = TZ_FORCE_LO;//EPwm1Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCBH_LOW; //TZ_DCAH_HI;//EPwm1Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCAH_LOW;EPwm1Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_HI;EPwm1Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCAH_HI;EPwm1Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP1OUT;// DCAH = Comparator 2 output
	EDIS;	
}
#endif 


//******************************************************************
// 函数名	:void InitEPwm2Driver(void)
// 作者		:TI
// 功能		初始化系统ePWM2寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	
//******************************************************************
#if DSP28_EPWM2
void InitEPwm2Driver(void)
{	EALLOW;
	//SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;	// Stop all the TB clocks	
	//EPwm2Regs.TBPRD 	= 1874;///48k
	EPwm2Regs.TBPRD 	= 3000;///20k// Count up
	//EPwm2Regs.TBPRD 	= 1500;///20k//Count updown
	EPwm2Regs.TBPHS.all	= 0;
	EPwm2Regs.TBCTR		= 0;

	// Setup TBCLK
	EPwm2Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// Count up
	//EPwm2Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;//Count updown
	EPwm2Regs.TBCTL.bit.PHSEN		= TB_ENABLE;		// Enable phase loading  
	EPwm2Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm2Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_IN;
	EPwm2Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm2Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm2Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm2Regs.TBCTL.bit.PHSDIR		= 1; 
	EPwm2Regs.TBCTL.bit.FREE_SOFT	= 3;				// 


	// Setup compare 
	EPwm2Regs.CMPA.half.CMPA= 1500;//
	EPwm2Regs.CMPB= 1500;//
	EPwm2Regs.TBPHS.half.TBPHS = 0;
	
	// Setup CMPCTL 
	EPwm2Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm2Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm2Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm2Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm2Regs.AQCTLA.bit.ZRO = AQ_SET;
	EPwm2Regs.AQCTLA.bit.CAU = AQ_CLEAR;
	EPwm2Regs.AQCTLB.bit.ZRO = AQ_CLEAR ;
	EPwm2Regs.AQCTLB.bit.CBU = AQ_SET;
	
//	EPwm2Regs.AQSFRC.bit.RLDCSF = 3;

	//Set DeadBand
 	EPwm2Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
	EPwm2Regs.DBCTL.bit.IN_MODE = 0x0;
	EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
	//EPwm2Regs.DBFED = 200 ;//
	//EPwm2Regs.DBRED = 200;
	EPwm2Regs.DBFED = 300;//
	EPwm2Regs.DBRED = 300; 
	////斩波比较模块
	//EPwm2Regs.TZSEL.bit.DCAEVT2 = 1;
	//EPwm2Regs.TZSEL.bit.DCAEVT2 = 0;
	//EPwm2Regs.TZSEL.bit.DCBEVT2 = 0;
	//EPwm2Regs.TZSEL.bit.DCBEVT2 = 1;
	EPwm2Regs.TZSEL.bit.CBC1=1;// What do we want the TZ1 and TZ2 to do?EPwm2Regs.TZCTL.bit.TZA = TZ_FORCE_LO;EPwm2Regs.TZCTL.bit.TZB = TZ_FORCE_LO;//EPwm2Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCBH_LOW;//EPwm2Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCBH_LOW;EPwm2Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_HI;EPwm2Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCAH_HI;EPwm2Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP1OUT; // DCAH = Comparator 2 outputEPwm2Regs.DCACTL.bit.EVT2SRCSEL = DC_EVT2;// DCAEVT2 = DCAEVT2 (not filtered)EPwm2Regs.DCACTL.bit.EVT2FRCSYNCSEL = DC_EVT_ASYNC;// Take async pathEPwm2Regs.TZEINT.bit.DCBEVT2=0;//??
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS;

}
#endif 

//******************************************************************
// 函数名	:void InitEPwm3Driver(void)
// 作者		:TI
// 功能		:初始化系统ePWM3寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM3
void InitEPwm3Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	//EPwm3Regs.TBPRD 			= Motor_PERIOD;
	EPwm3Regs.TBPRD 			= 3000;//1500;//C_MOTOR_PWM_PRD;
	EPwm3Regs.TBPHS.all			= 0;
	EPwm3Regs.TBCTR				= 0;
	EPwm3Regs.TBPHS.half.TBPHS	= 0;

	// Setup TBCLK
	//EPwm3Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;		// Count up
	EPwm3Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// 对称波形输出 
	EPwm3Regs.TBCTL.bit.PHSEN		= TB_DISABLE;// Disable phase loading  
	EPwm3Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	//EPwm3Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_DISABLE;
	EPwm3Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_IN;	//  Count equal to zero; have a syn output
	EPwm3Regs.TBCTL.bit.SWFSYNC		= 0; 
	//EPwm3Regs.TBCTL.bit.HSPCLKDIV	= 0x04;///1/8
	EPwm3Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
//	EPwm3Regs.TBCTL.bit.CLKDIV		= 0x04;///1/16 
	EPwm3Regs.TBCTL.bit.CLKDIV		= TB_DIV1;
	EPwm3Regs.TBCTL.bit.PHSDIR		= 1;
	EPwm3Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compareEPwm3Regs.CMPA.half.CMPA =1500;
	EPwm3Regs.CMPB  = 0;
	// Setup CMPCTL 
	EPwm3Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm3Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm3Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm3Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm3Regs.AQCTLA.bit.CAU = AQ_CLEAR;			// 
	EPwm3Regs.AQCTLA.bit.PRD = AQ_SET;				//  
	EPwm3Regs.AQCTLB.bit.CBU = AQ_SET;				// 
	EPwm3Regs.AQCTLB.bit.PRD = AQ_CLEAR;	// 

	EPwm3Regs.ETSEL.bit.INTSEL	= ET_CTR_PRD;			// 2:0EPWMxINTn Select
	EPwm3Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable
	
/////////////////////////////////////////////////////
	//死区模块(DB)配置
	EPwm3Regs.DBCTL.bit.OUT_MODE =DB_FULL_ENABLE;
	EPwm3Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
	EPwm3Regs.DBCTL.bit.IN_MODE = 0;
	//EPwm3Regs.DBCTL.bit.HALFCYCLE = 0;
	EPwm3Regs.DBFED = 200;//Falling delay
	EPwm3Regs.DBRED = 200;  //Raising delay  //0.01667*300=5U

	// 事件触发模块(EZ)配置
	EPwm3Regs.ETSEL.bit.INTSEL	= ET_CTRD_CMPA;		// 2:0EPWMxINTn Select
	EPwm3Regs.ETSEL.bit.INTEN	= ET_DISABLE;		// 3EPWMxINTn Enable
	EPwm3Regs.ETSEL.bit.SOCASEL	= ET_CTR_ZERO;		// 10:8Start of conversion A Select  
	EPwm3Regs.ETSEL.bit.SOCAEN	= ET_ENABLE;		// 11Start of conversion A Enable  
	EPwm3Regs.ETSEL.bit.SOCBSEL	= ET_CTR_ZERO;		// 14:12  Start of conversion B Select  
	EPwm3Regs.ETSEL.bit.SOCBEN	= ET_ENABLE;		// 15Start of conversion B Enable  

	EPwm3Regs.ETPS.bit.INTPRD = 1;		// 1:0EPWMxINTn Period Select
	EPwm3Regs.ETPS.bit.INTCNT = 0;		// 3:2EPWMxINTn Counter Register 
	EPwm3Regs.ETPS.bit.SOCAPRD = 1;		// 9:8EPWMxSOCA Period Select
	EPwm3Regs.ETPS.bit.SOCACNT = 0;		// 11:10  EPWMxSOCA Counter Register 
	EPwm3Regs.ETPS.bit.SOCBPRD = 1;		// 13:12  EPWMxSOCB Period Select
	EPwm3Regs.ETPS.bit.SOCBCNT = 0;	 	// 15:14  EPWMxSOCB Counter Register 	
	EDIS; 
}
//#endif 
//******************************************************************
// 函数名	:void InitEPwm4Driver(void)
// 作者		:TI
// 功能		:初始化系统ePWM4寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	送丝机H桥驱动
//******************************************************************
//#if DSP28_EPWM4
void InitEPwm4Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	
	EPwm4Regs.TBPRD 			= 1000;
	EPwm4Regs.TBPHS.all			= 0;
	EPwm4Regs.TBCTR				= 0;
	EPwm4Regs.TBPHS.half.TBPHS	= 0;
	
	// Setup TBCLK
	EPwm4Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;	// Count up and down 
	EPwm4Regs.TBCTL.bit.PHSEN		= TB_DISABLE;		// Disable phase loading  
	EPwm4Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm4Regs.TBCTL.bit.SYNCOSEL	= TB_CTR_ZERO;
	EPwm4Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm4Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm4Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm4Regs.TBCTL.bit.PHSDIR		= 1; 
	EPwm4Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compare 
	EPwm4Regs.CMPA.half.CMPA = Motor_PERIOD - 5;
	EPwm4Regs.CMPB = 5;

	// Setup CMPCTL 
	EPwm4Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm4Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm4Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm4Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm4Regs.AQCTLA.bit.CAU =  AQ_SET;					// Set PWM4A
	EPwm4Regs.AQCTLA.bit.CAD =  AQ_CLEAR;
	EPwm4Regs.AQCTLB.bit.CBU = AQ_CLEAR;				// Set PWM4B
	EPwm4Regs.AQCTLB.bit.CBD = AQ_SET;

//	EPwm4Regs.AQSFRC.bit.RLDCSF = 3;

	// Set deadband
//	EPwm4Regs.DBCTL.bit.OUT_MODE = DB_DISABLE;// Dead-band Output Mode Control
//	EPwm4Regs.DBCTL.bit.POLSEL= DB_ACTV_HI;// Polarity Select Control
//	EPwm4Regs.DBCTL.bit.IN_MODE  = DBB_ALL;// Dead Band Input Mode Control
//	EPwm4Regs.DBFED = 100;//Falling delay
//	EPwm4Regs.DBRED = 100;//Raising delay
	
	// Set ETSEL
	EPwm4Regs.ETSEL.bit.INTSEL	= ET_CTRD_CMPB;	// 2:0EPWMxINTn Select
	EPwm4Regs.ETSEL.bit.INTEN	= ET_ENABLE;		// 3EPWMxINTn Enable
	EPwm4Regs.ETSEL.bit.SOCASEL	= ET_CTR_ZERO;		// 10:8Start of conversion A Select
	EPwm4Regs.ETSEL.bit.SOCAEN	= ET_ENABLE;		// 11Start of conversion A Enable
	EPwm4Regs.ETSEL.bit.SOCBSEL	= ET_CTR_ZERO;			// 14:12  Start of conversion B Select  
	EPwm4Regs.ETSEL.bit.SOCBEN	= ET_ENABLE;		// 15Start of conversion B Enable

	EPwm4Regs.ETPS.bit.INTPRD	= ET_1ST;		// 1:0EPWMxINTn Period Select
	EPwm4Regs.ETPS.bit.INTCNT	= 0;			// 3:2EPWMxINTn Counter Register 
	EPwm4Regs.ETPS.bit.SOCAPRD	= ET_1ST;		// 9:8EPWMxSOCA Period Select
	EPwm4Regs.ETPS.bit.SOCACNT	= 0;			// 11:10  EPWMxSOCA Counter Register 
	EPwm4Regs.ETPS.bit.SOCBPRD	= ET_1ST;		// 13:12  EPWMxSOCB Period Select
	EPwm4Regs.ETPS.bit.SOCBCNT	= 0;			// 15:14  EPWMxSOCB Counter Register 
//	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS; 	
}
//#endif 

//******************************************************************
// 函数名	:void InitEPwm5Driver(void)
// 作者		:何志军
// 功能		:初始化系统ePWM5寄存髋渲?
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	送丝机H桥驱动
//******************************************************************
//#if DSP28_EPWM5
void InitEPwm5Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	EPwm5Regs.TBPRD 			= 1000;
	EPwm5Regs.TBPHS.all			= 0;
	EPwm5Regs.TBCTR				= 0;

	// Setup TBCLK
	EPwm5Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;		// Count up
	EPwm5Regs.TBCTL.bit.PHSEN		= TB_ENABLE;	// Disable phase loading  
	EPwm5Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm5Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_IN;
	EPwm5Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm5Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm5Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm5Regs.TBCTL.bit.PHSDIR		= 1; 
	EPwm5Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compare 
	EPwm5Regs.CMPA.half.CMPA = Motor_PERIOD - 5;
	EPwm5Regs.CMPB = 5;

	// Setup CMPCTL 
	EPwm5Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm5Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm5Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm5Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm5Regs.AQCTLA.bit.CAU = AQ_SET;					// Set PWM6A
	EPwm5Regs.AQCTLA.bit.CAD = AQ_CLEAR;
	EPwm5Regs.AQCTLB.bit.CBU = AQ_CLEAR;				// Set PWM6B
	EPwm5Regs.AQCTLB.bit.CBD = AQ_SET;
	
	// set deadband
	// EPwm5Regs.DBCTL.bit.OUT_MODE = DB_DISABLE;// Dead-band Output Mode Control
	// EPwm5Regs.DBCTL.bit.POLSEL= DB_ACTV_HI;// Polarity Select Control
			// EPwm5Regs.DBCTL.bit.IN_MODE  = DBB_ALL;// Dead Band Input Mode Control
	// EPwm5Regs.DBFED = 100;//Falling delay
	// EPwm5Regs.DBRED = 100;//Raising delay

	EPwm5Regs.ETSEL.bit.INTSEL	= ET_CTRD_CMPB;			// 2:0EPWMxINTn Select
	EPwm5Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable
	EPwm5Regs.ETSEL.bit.SOCASEL	= ET_CTR_ZERO;// 10:8Start of conversion A Select  
	EPwm5Regs.ETSEL.bit.SOCAEN	= ET_DISABLE;			// 11Start of conversion A Enable  
	EPwm5Regs.ETSEL.bit.SOCBSEL	= ET_CTR_ZERO;	// 14:12  Start of conversion B Select  
	EPwm5Regs.ETSEL.bit.SOCBEN	= ET_DISABLE;			// 15Start of conversion B Enable  

	EPwm5Regs.ETPS.bit.INTPRD = 1;		// 1:0EPWMxINTn Period Select
	EPwm5Regs.ETPS.bit.INTCNT = 0;		// 3:2EPWMxINTn Counter Register 
	EPwm5Regs.ETPS.bit.SOCAPRD = 0;		// 9:8EPWMxSOCA Period Select
	EPwm5Regs.ETPS.bit.SOCACNT = 0;		// 11:10  EPWMxSOCA Counter Register 
	EPwm5Regs.ETPS.bit.SOCBPRD = 0;		// 13:12  EPWMxSOCB Period Select
	EPwm5Regs.ETPS.bit.SOCBCNT = 0;		// 15:14  EPWMxSOCB Counter Register 

//	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS; 
}
//#endif 

//******************************************************************
// 函数名	:void InitEPwm6Driver(void)
// 作者		:TI
// 功能		:初始化系统ePWM6寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	加热阀控制
//******************************************************************
//#if DSP28_EPWM6//

void InitEPwm6Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	EPwm6Regs.TBPRD 			= 1500;
	EPwm6Regs.TBPHS.all			= 0;
	EPwm6Regs.TBCTR				= 0;
	EPwm6Regs.TBPHS.half.TBPHS	= 0;

	// Setup TBCLK
	EPwm6Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// Count up
	EPwm6Regs.TBCTL.bit.PHSEN		= TB_DISABLE;// Disable phase loading  
	EPwm6Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm6Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_DISABLE;
	EPwm6Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm6Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm6Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm6Regs.TBCTL.bit.PHSDIR		= 1;
	EPwm6Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compare 
	EPwm6Regs.CMPA.half.CMPA  = 3;
	// Setup CMPCTL 
	EPwm6Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm6Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm6Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm6Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm6Regs.AQCTLA.bit.CAU = AQ_CLEAR;				// Set PWM6A
	EPwm6Regs.AQCTLA.bit.ZRO = AQ_SET;

	EPwm6Regs.ETSEL.bit.INTSEL	= ET_CTR_PRD;			// 2:0EPWMxINTn Select
	EPwm6Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable

	EPwm6Regs.ETPS.bit.INTPRD = 1;		// 1:0EPWMxINTn Period Select
	EPwm6Regs.ETPS.bit.INTCNT = 0;		// 3:2EPWMxINTn Counter Register
	EPwm6Regs.AQCSFRC.bit.CSFA = 0;
	EPwm6Regs.AQCSFRC.bit.CSFB = 0;// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS; 
}
//#endif 

//******************************************************************
// 函数名	:void InitEPwm7Driver(void)
// 作者		:TI
// 功能		:初始化系统ePWM7寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改绷浚何?
// 备注		:	Slope Compensation PWM Control	(Hardware
//******************************************************************
//#if DSP28_EPWM7
void InitEPwm7Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	EPwm7Regs.TBPRD 			= 1000;//3130--10K
	EPwm7Regs.TBPHS.all			= 0;
	EPwm7Regs.TBCTR				= 0;
	EPwm7Regs.TBPHS.half.TBPHS	= 0;

	// Setup TBCLK
	EPwm7Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// Count up
	EPwm7Regs.TBCTL.bit.PHSEN		= TB_DISABLE;		// Disable phase loading  
	EPwm7Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm7Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_DISABLE;
	EPwm7Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm7Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm7Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm7Regs.TBCTL.bit.PHSDIR		= 1;
	EPwm7Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compare 
	EPwm7Regs.CMPB = 0;
	// Setup CMPCTL 
	EPwm7Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm7Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm7Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm7Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	// EPwm7Regs.AQCTLB.bit.CBU = AQ_CLEAR;				// Set PWM7B
	// EPwm7Regs.AQCTLB.bit.CBD = AQ_SET;
	EPwm7Regs.AQCTLB.bit.ZRO = AQ_SET;
	EPwm7Regs.AQCTLB.bit.CBU = AQ_CLEAR;

	EPwm7Regs.ETSEL.bit.INTSEL	= ET_CTRD_CMPB;			// 2:0EPWMxINTn Select
	EPwm7Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable

	EPwm7Regs.ETPS.bit.INTPRD = 1;		// 1:0EPWMxINTn Period Select
	EPwm7Regs.ETPS.bit.INTCNT = 0;		// 3:2EPWMxINTn Counter Register

//	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS; 
}
//#endif 


/******************************************************************/
//函数名:void InitTzDriver(void)
//功能:Initialize the TZ Module for epwm1,epwm2,epwm4,epwm5 and epwm6 of WPPM3312Z
//备注:2015.06.25
//===========================================================================
void InitTzDriver(void)
{// Enable TZ1/TZ2 and TZ3 as one shot trip sources on EPwm1 Module
	EALLOW;
	EPwm1Regs.TZSEL.bit.CBC1 = 1;
	//EPwm1Regs.TZSEL.bit.OSHT1 = 1;
	//EPwm1Regs.TZSEL.bit.DCBEVT1 = 1;
	EPwm1Regs.TZSEL.bit.DCAEVT1 = 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm1Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	EPwm1Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	EPwm1Regs.TZCTL.bit.DCAEVT1 = 2;
	// EPwm1Regs.TZCTL.bit.DCBEVT1= 2;

	// EPwm1Regs.TZDCSEL.bit.DCBEVT1 = TZ_DCBH_LOW;
	EPwm1Regs.TZDCSEL.bit.DCAEVT1 = TZ_DCAH_HI;
	// Enable TZ interrupt
	// EPwm1Regs.TZEINT.bit.OST = 1;
	// EDIS;
	// Enable  TZ1\TZ2 and TZ3 as one shot trip sources on EPwm2 Module
	// EALLOW;
	EPwm2Regs.TZSEL.bit.CBC1 = 1;  
	//EPwm2Regs.TZSEL.bit.OSHT1 = 1;  
	// EPwm2Regs.TZSEL.bit.DCBEVT1= 1;
	EPwm2Regs.TZSEL.bit.DCAEVT1= 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm2Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	EPwm2Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	EPwm2Regs.TZCTL.bit.DCAEVT1 = 2;
	// EPwm2Regs.TZCTL.bit.DCBEVT1 = 2;

	// EPwm2Regs.TZDCSEL.bit.DCBEVT1 = TZ_DCBH_LOW;
	EPwm2Regs.TZDCSEL.bit.DCAEVT1 = TZ_DCAH_HI;
	// Enable TZ interrupt
	// EPwm2Regs.TZEINT.bit.OST = 1;
	// EDIS;
	// Enable TZ1/TZ2 and TZ3 as one shot trip sources on EPwm4 Module
	EPwm3Regs.TZSEL.bit.CBC3 = 1;//FAN

	EPwm3Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	// EALLOW;
	// EPwm4Regs.TZSEL.bit.CBC1 = 1;
	EPwm4Regs.TZSEL.bit.DCAEVT2 = 1;
	// EPwm4Regs.TZSEL.bit.DCBEVT2 = 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm4Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	EPwm4Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	// EPwm4Regs.TZCTL.bit.DCAEVT2 = 2;
	// EPwm4Regs.TZCTL.bit.DCBEVT2 = 2;


	// EPwm4Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCBH_LOW;
	EPwm4Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_LOW;
	// Enable TZ interrupt
	// EPwm4Regs.TZEINT.bit.OST = 1;
	// EDIS;
	
	
	// Enable TZ1/TZ2 and TZ3 as one shot trip sources on EPwm5 Module
	// EALLOW;
	// EPwm5Regs.TZSEL.bit.CBC1 = 1;
	// EPwm5Regs.TZSEL.bit.CBC2 = 1;
	//EPwm5Regs.TZSEL.bit.CBC3 = 1;//FAN
	EPwm5Regs.TZSEL.bit.DCAEVT2 = 1;
	// EPwm5Regs.TZSEL.bit.DCAEVT2 = 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm5Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	EPwm5Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	// EPwm5Regs.TZCTL.bit.DCAEVT2 = 2;
	// EPwm5Regs.TZCTL.bit.DCBEVT2 = 2;

	EPwm5Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_LOW;
	// EPwm5Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_LOW;
	// Enable TZ interrupt
	// EPwm5Regs.TZEINT.bit.OST = 1;
	// EDIS;
	
	// Enable TZ1\TZ2 and TZ3 as one shot trip sources on EPwm3 Module
	// EALLOW;
	// EPwm6Regs.TZSEL.bit.CBC1 = 1;
	EPwm6Regs.TZSEL.bit.CBC2 = 1;///JRF
	// EPwm6Regs.TZSEL.bit.CBC3 = 1;
	// EPwm6Regs.TZSEL.bit.DCAEVT2= 1;
	// EPwm6Regs.TZSEL.bit.DCBEVT2 = 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm6Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	// EPwm6Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	// EPwm6Regs.TZCTL.bit.DCAEVT2 = 2;
	// EPwm6Regs.TZCTL.bit.DCBEVT2 = 2;

	// EPwm6Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCBH_LOW;
	// EPwm6Regs.TZDCSEL.bit.DCAEVT2= TZ_DCAH_HI;
	// EPwm7Regs.TZSEL.bit.CBC2 = 1;//JRF
	// EPwm7Regs.TZCTL.bit.TZA = TZ_FORCE_LO;

	// Enable TZ interrupt
	// EPwm6Regs.TZEINT.bit.OST = 1;
	EDIS;
	
	
}

/***********************************************************/
//函数名:void InitDCEventDriver
//功能:Initialize Digtal Compare Event Module
//备注:DC Event for protecting Power and Motor
//===========================================================================
void InitDCEventDriver(void)
{
	
	// Define an event (DCAEVT1) based on TZ1 and TZ2
	EALLOW;
	EPwm1Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP1OUT;// DCAH = Comparator 1 output and TZ1 input
	// EPwm1Regs.DCTRIPSEL.bit.DCBHCOMPSEL = DC_TZ1 ;
	EPwm1Regs.DCACTL.bit.EVT1SRCSEL = DC_EVT1;// DCAEVT1 = DCAEVT1(not filtered)
	EPwm1Regs.DCACTL.bit.EVT1FRCSYNCSEL = DC_EVT_ASYNC;

	EPwm2Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP1OUT;// DCAH = Comparator 1 output AND TZ1 input
	// EPwm2Regs.DCTRIPSEL.bit.DCBHCOMPSEL = DC_TZ1;
	EPwm2Regs.DCACTL.bit.EVT1SRCSEL = DC_EVT1;// DCAEVT1 = DCAEVT1 (not filtered)
	EPwm2Regs.DCACTL.bit.EVT1FRCSYNCSEL = DC_EVT_ASYNC;

	EPwm4Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP2OUT;// DCAH = Comparator 2 output
	EPwm4Regs.DCACTL.bit.EVT2SRCSEL = DC_EVT2;// DCAEVT2 = DCAEVT2 (not filtered)
	EPwm4Regs.DCACTL.bit.EVT2FRCSYNCSEL = DC_EVT_ASYNC;// Take async path

	EPwm5Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP2OUT;// DCAH = Comparator 2 output
	EPwm5Regs.DCACTL.bit.EVT2SRCSEL = DC_EVT2;// DCAEVT2= DCAEVT2 (not filtered)
	EPwm5Regs.DCACTL.bit.EVT2FRCSYNCSEL = DC_EVT_ASYNC;// Take async path

	EDIS;
}


//===========================================================================
// End of file.
//===========================================================================

----------------------以上为DSP2803x_EPwm.c-----------------------------------------------------------

Jordan Zhou:

回复 ke ma:

这个值,是否过低,导致误触发?

在使用TMS320f28034这款芯片的单周期斩波功能,遇到了一些问题如下:

        ePWM的频率设置为20kHZ;ePWM1,ePWM2,ePWM3同步;ePWM1A和ePWM2A驱动全桥,控制逆变电源(ePWM1B和ePWM2B不使用);ePWM3A和ePWM3B用来做斜波补偿,和电流反馈信号一起从Comp1的一个端口进入,Comp1的另一个端口为软件计算的值写入DACVAL,对ePWM1A,ePWM2A进行斩波。现在发现在一个ePWM周期内出现多次斩波的现象。见附件。
下图通道1为全桥驱动;通道2为ePWM1A(最大占空比设置为50%);通道3为ePWM2A(最大占空比设置为50%);通道4为ePWM3A(占空比设置为50%)和ePWM3B(占空比设置为50%)+反馈电流;a b之间为一个周期。
//###########################################################################
//
// FILE:DSP2803x_Comp.c
//
// TITLE:DSP2803x Comparator Initialization & Support Functions.
//
//###########################################################################
// $TI Release: F2803x C/C++ Header Files and Peripheral Examples V127 $
// $Release Date: March 30, 2013 $
//###########################################################################

#include "DSP2803x_Device.h"// DSP2803x Headerfile Include File
#include "DSP2803x_Examples.h"// DSP2803x Examples Include File


void InitCompDriver(void);
void InitCompGpio(void);
void InitComp(void);

void InitComp(void)
{

	InitCompGpio();
	InitCompDriver();

}


void InitCompGpio()
{InitComp1Gpio();
}

void InitComp1Gpio()
{EALLOW;GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1;// Disable pull-up for GPIO1 (CMP1OUT)GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 3;// Configure GPIO1 for CMP1OUT operationGpioCtrlRegs.AIOMUX1.bit.AIO2 = 2;// Configure AIO2 for CMP1A (analog input) operationSysCtrlRegs.PCLKCR3.bit.COMP1ENCLK = 1;//EDIS;
}

#if DSP28_COMP2
void InitComp2Gpio()
{EALLOW;GpioCtrlRegs.AIOMUX1.bit.AIO4 = 2;// Configure AIO4 for CMP2A (analog input) operationEDIS;
}

#endif //end DSP28_COMP2

#if DSP28_COMP3
void InitComp3Gpio()
{EALLOW;GpioCtrlRegs.AIOMUX1.bit.AIO6 = 2;// Configure AIO6 for CMP3A (analog input) operationEDIS;
}

#endif //end DSP28_COMP3




/**********************************************************************************/
//函数名:void IntiCompDriver(void);
//功能:比较器模块初始化
//备注:
/*********************************************************************************/
void InitCompDriver()
{EALLOW;SysCtrlRegs.PCLKCR3.bit.COMP1ENCLK = 1;// Enable clock to the Comparator 1 blockComp1Regs.DACVAL.bit.DACVAL = 300;//C_CTCurr_Pro;Comp1Regs.COMPCTL.bit.COMPDACEN = 1;// Power up Comparator 1 locallyComp1Regs.COMPCTL.bit.COMPSOURCE = 0;Comp1Regs.COMPCTL.bit.CMPINV = 0;Comp1Regs.COMPCTL.bit.QUALSEL = 6;Comp1Regs.COMPCTL.bit.SYNCSEL =1;EDIS;
}


//===========================================================================
// End of file.
//===========================================================================
-----------------------------------以上为DSP2803x_Comp.c----------------------------------------------------------------
//**************************************************************************
//	Copyright(c)2017-DR_Welding
//	文件名称	:	WPCM2315CU2_Isr.c
//	作者		:	
//	模块功能	:系统中断
//	局部函数列表: 	无
//  更改记录	:
//	日期		DR版本		作者		备注
//	
//**************************************************************************

#define		in_interrupt

#include	"DSP2803x_Header.h"// Headerfile Include File
#include	"WPPM3312M2_Isr.h"
#include	"WPPM3312M2_SysReg.h"
#include	"WPPM3312M2_SysMacro.h"
#include	"WPPM3312M2_GlobalVarDef.h"
#include	"WPPM3312M2_EepromDriver.h"
#include	"WPPM3312M2_Can.h"
#include	"WPPM3312M2_Struct.h"
//#include"WPPM3312M2_LedShow.h"
#include"WPPM3312M2_KeyDispose.h"

//============================
//		内部函数声明
//============================
void vPwm1IntIsr(void);
void vTimer0IntIsr(void);
void IsrVarInit(void);

//******************************************************************
// 函数名	:void InitInterrupt(void)
// 作者		:
// 功能		:中断模块初始化
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	
//******************************************************************
void InitInterrupt(void)
{EALLOW;  	
	// 定义PWM1的中断向量PieVectTable.EPWM1_INT = &vPwm1IntIsr;PieCtrlRegs.PIEIER3.bit.INTx1 = 1;IER |= M_INT3;EDIS;  
}
//******************************************************************
// 函数名	:void vPwm1IntIsr(void)
// 作者		:
// 功能		:主拓扑PWM中断
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	
//******************************************************************
interrupt void vPwm1IntIsr(void)
{	
	//========= 更新主功率移相角=========mEnablePowerPwm();
	mSetPwm1Duty(1500);		
	PidLogic();//PI处理	

//======================== 清中断标志并再次使能中断 ===========================	
	EPwm1Regs.ETCLR.bit.INT = 1;
	PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;	
}

/****************************************************************************/
//函数名:void PidUpGrading(int PidResult);
// 作者		:MaKe
//功能:比较器模块更新PID计算结果
// 参数		:PidResult :PID计算结果
// 祷?:无
// 调用全局变量:无
// 修改全局变量:无
//备注:2018.06.29
/************************************************************************/
void PidUpGrading(int PidResult)
{EALLOW;Comp1Regs.DACVAL.bit.DACVAL = PidResult;	//C_CTCurr_Pro;//原边过流保护点EDIS;
}
------------------------------以上为WPCM2315CU2_Isr.c------------------------------------------------------------------------------//**************************************************************************
//	***
//	文件名称	:	DSP2803x_EPwm.c
//	作者		:	
//	模块功能	:DSP2803x EPwm Initialization & Support Functions.
//	局部函数列表: 	无
//	版本信息	:	TI File $Revision: /main/3 $
// 					Checkin $Date: November 10, 200914:05:11 $
//					$TI Release: 2803x C/C++ Header Files V1.21 $
// 					$Release Date: December 1, 2009 $
//  更改记录	:
//**************************************************************************


#include	"DSP2803x_Header.h"// Headerfile Include File
#include	"WPPM3312M2_SysMacro.h"
#include	"WPPM3312M2_SysReg.h"
#include	"DSP2803x_Device.h"




//============================
//		内部函数声明
//============================
void InitEPwmGpio(void);
void InitEPwm1Gpio(void);
void InitEPwm2Gpio(void);
void InitEPwm3Gpio(void);
void InitEPwm4Gpio(void);
void InitEPwm5Gpio(void);
void InitEPwm6Gpio(void);
void InitEPwm7Gpio(void);

void InitEPwmDriver(void);
void InitEPwm1Driver(void);
void InitEPwm2Driver(void);
void InitEPwm3Driver(void);
void InitEPwm4Driver(void);
void InitEPwm5Driver(void);
void InitEPwm6Driver(void);
void InitEPwm7Driver(void);

void InitTzGpio(void);
void InitTzDriver(void);
void InitDCEventDriver(void);

//******************************************************************
// 函数名	:void InitEPwm(void)
// 作者		:TI
// 功能		:初始化系统PWM模块及管脚设置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
void InitEPwm(void)
{
	// 配置管脚功能

	EALLOW;
	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;  
	EDIS;

	InitEPwmGpio();
//	InitTzGpio();
	// 初始化寄存器

//	InitTzDriver();
//	InitDCEventDriver();
	InitEPwmDriver();
	//mUpDatePwm2Phase(0);
	mUpDatePwm2Phase(1500);
	//mSetPwm4BDuty(0);

	mDisablePowerPwm();
	mDisableMotorPWM();

	mEnableMotorPWM();//////使能PWM3
//	mDisableJRFPWM();
//	mDisableFANPWM();

//	mDebugPWM(1000);  

	EALLOW;
	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;  
	EDIS;  
}


//******************************************************************
// 函数名	:void InitEPwmDriver(void)
// 作者		:TI
// 功能		:This function initializes GPIO pins to function as EPwm pins
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	Each GPIO pin can be configured as a GPIO pin or up to 3 different
// 				peripheral functional pins. By default all pins come up as GPIO
// 				inputs after reset.
//******************************************************************
void InitEPwmGpio(void)
{
#if DSP28_EPWM1InitEPwm1Gpio();
#endif // endif DSP28_EPWM1

#if DSP28_EPWM2InitEPwm2Gpio();
#endif // endif DSP28_EPWM2

#if DSP28_EPWM3InitEPwm3Gpio();
#endif // endif DSP28_EPWM3

#if DSP28_EPWM4// InitEPwm4Gpio();
#endif // endif DSP28_EPWM4

#if DSP28_EPWM5//InitEPwm5Gpio();
#endif // endif DSP28_EPWM5

#if DSP28_EPWM6//InitEPwm6Gpio();
#endif // endif DSP28_EPWM6

#if DSP28_EPWM7//InitEPwm7Gpio();
#endif // endif DSP28_EPWM7
}

//******************************************************************
// 函数名	:void InitEPwm1Gpio(void)
// 作者		:TI
// 功能		:初始化PWM1输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
#if DSP28_EPWM1
void InitEPwm1Gpio(void)
{
	EALLOW;

/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO0 = 1;// Disable pull-up on GPIO0 (EPWM1A)
	GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1;// Disable pull-up on GPIO1 (EPWM1B)

/* Configure EPWM-1 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM1 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1;// Configure GPIO0 as EPWM1A
	GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1;// Configure GPIO1 as EPWM1B

	EDIS;
}
#endif // endif DSP28_EPWM1

//******************************************************************
// 函数名	:void InitEPwm2Gpio(void)
// 作者		:TI
// 功能		:初始化PWM2输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM2
void InitEPwm2Gpio(void)
{
	EALLOW;

/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO2 = 1;// Disable pull-up on GPIO2 (EPWM2A)
	GpioCtrlRegs.GPAPUD.bit.GPIO3 = 1;// Disable pull-up on GPIO3 (EPWM2B)

/* Configure EPwm-2 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM2 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 1;// Configure GPIO2 as EPWM2A
	GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 1;// Configure GPIO3 as EPWM2B

	EDIS;
}
//#endif // endif DSP28_EPWM2

//******************************************************************
// 函数名	:void InitEPwm3Gpio(void)
// 作者		:TI
// 功能		:初始化PWM3输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM3
void InitEPwm3Gpio(void)
{
	EALLOW;

/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.GpioCtrlRegs.GPAPUD.bit.GPIO4 = 1;// Disable pull-up on GPIO4 (EPWM3A)
	GpioCtrlRegs.GPAPUD.bit.GPIO5 = 1;// Disable pull-up on GPIO5 (EPWM3B)

/* Configure EPwm-3 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM3 functional pins.
// Comment out other unwanted lines.GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 1;// Configure GPIO4 as EPWM3A
	GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 1;// Configure GPIO5 as EPWM3B

	EDIS;
}
//#endif // endif DSP28_EPWM3

//******************************************************************
// 函数名	:void InitEPwm4Gpio(void)
// 作者		:TI
// 功能		:初始化PWM4输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM4
void InitEPwm4Gpio(void)
{
	EALLOW;
/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO6 = 1;// Disable pull-up on GPIO6 (EPWM4A)
	GpioCtrlRegs.GPAPUD.bit.GPIO7 = 1;// Disable pull-up on GPIO7 (EPWM4B)

/* Configure EPWM-4 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM4 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 1;// Configure GPIO6 as EPWM4A
	GpioCtrlRegs.GPAMUX1.bit.GPIO7 = 1;// Configure GPIO7 as EPWM4B

	EDIS;
}
//#endif // endif DSP28_EPWM4

//******************************************************************
// 函数名	:void InitEPwm5Gpio(void)
// 作者		:
// 功能		:初始化PWM5输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:EPWM5模块只用到了GPIO9,故只初始化此管脚
//******************************************************************
//#if DSP28_EPWM5
void InitEPwm5Gpio(void)
{
	EALLOW;
/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO8 = 1;// Disable pull-up on GPIO8 (EPWM5A)
	GpioCtrlRegs.GPAPUD.bit.GPIO9 = 1;// Disable pull-up on GPIO9 (EPWM5B)

/* Configure EPWM-5 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM5 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO8 = 1;// Configure GPIO8 as EPWM5A
	GpioCtrlRegs.GPAMUX1.bit.GPIO9 = 1;// Configure GPIO9 as EPWM5B

	EDIS;
}
//#endif // endif DSP28_EPWM5

//******************************************************************
// 函数名	:void InitEPwm6Gpio(void)
// 作者		:TI
// 功能		:初始化PWM6输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM6
void InitEPwm6Gpio(void)
{
	EALLOW;
/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAPUD.bit.GPIO10 = 1;// Disable pull-up on GPIO10 (EPWM6A)//GpioCtrlRegs.GPAPUD.bit.GPIO11 = 1;// Disable pull-up on GPIO11 (EPWM6B)

/* Configure EPWM-6 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM6 functional pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAMUX1.bit.GPIO10 = 1;// Configure GPIO10 as EPWM6A//GpioCtrlRegs.GPAMUX1.bit.GPIO11 = 1;// Configure GPIO11 as EPWM6B

	EDIS;
}
//#endif // endif DSP28_EPWM6

//******************************************************************
// 函数名	:void InitEPwm7Gpio(void)
// 作者		:TI
// 功能		:初始化PWM7输出管脚
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM7
void InitEPwm7Gpio(void)
{
	EALLOW;
/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.//GpioCtrlRegs.GPBPUD.bit.GPIO40 = 1;// Disable pull-up on GPIO40 (EPWM7A)
	GpioCtrlRegs.GPBPUD.bit.GPIO41 = 1;// Disable pull-up on GPIO41 (EPWM7B)

/* Configure EPWM-7 pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPWM7 functional pins.
// Comment out other unwanted lines.// GpioCtrlRegs.GPBMUX1.bit.GPIO40 = 1;// Configure GPIO40 as EPWM7A
	GpioCtrlRegs.GPBMUX1.bit.GPIO41 = 1;// Configure GPIO41 as EPWM7B

	EDIS;
}
//#endif // endif DSP28_EPWM7


//******************************************************************
// 函数名	:void InitEPwmSyncGpio(void)
// 作者		:TI
// 功能		:This function initializes GPIO pins to function as EPwm Synch pins
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
void InitEPwmSyncGpio(void)
{

//EALLOW;

/* Configure EPWMSYNCI  */

/* Enable internal pull-up for the selected pins */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

// GpioCtrlRegs.GPAPUD.bit.GPIO6 = 0;// Enable pull-up on GPIO6 (EPWMSYNCI)
	GpioCtrlRegs.GPBPUD.bit.GPIO32 = 0;// Enable pull-up on GPIO32 (EPWMSYNCI)

/* Set qualification for selected pins to asynch only */
// This will select synch to SYSCLKOUT for the selected pins.
// Comment out other unwanted lines.

// GpioCtrlRegs.GPAQSEL1.bit.GPIO6 = 0;// Synch to SYSCLKOUT GPIO6 (EPWMSYNCI)
	GpioCtrlRegs.GPBQSEL1.bit.GPIO32 = 0;  // Synch to SYSCLKOUT GPIO32 (EPWMSYNCI)

/* Configure EPwmSync pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be EPwmSync functional pins.
// Comment out other unwanted lines.

// GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 2;// Configures GPIO6 for EPWMSYNCI operation
	GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 2;// Configures GPIO32 for EPWMSYNCI operation.

/* Configure EPWMSYNC0  */

/* Disable internal pull-up for the selected output pinsfor reduced power consumption */
// Pull-ups can be enabled or disabled by the user.
// Comment out other unwanted lines.

// GpioCtrlRegs.GPAPUD.bit.GPIO6 = 1;// Disable pull-up on GPIO6 (EPWMSYNCO)
	GpioCtrlRegs.GPBPUD.bit.GPIO33 = 1;// Disable pull-up on GPIO33 (EPWMSYNCO)

// GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 3;// Configures GPIO6 for EPWMSYNCO
	GpioCtrlRegs.GPBMUX1.bit.GPIO33 = 2;  // Configures GPIO33 for EPWMSYNCO

}

//******************************************************************
// 函数名	:void InitTzGpio(void)
// 作者		:TI
// 功能		:This function initializes GPIO pins to function as Trip Zone (TZ) pins
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	Each GPIO pin can be configured as a GPIO pin or up to 3 different
// 				peripheral functional pins. By default all pins come up as GPIO
// 				inputs after reset.
//******************************************************************
void InitTzGpio(void)
{
	EALLOW;

/* Enable internal pull-up for the selected pins */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.
	GpioCtrlRegs.GPAPUD.bit.GPIO12 = 0;// Enable pull-up on GPIO12 (TZ1)
// GpioCtrlRegs.GPAPUD.bit.GPIO15 = 0;// Enable pull-up on GPIO15 (TZ1)
	GpioCtrlRegs.GPAPUD.bit.GPIO13 = 0;// Enable pull-up on GPIO13 (TZ2)
// GpioCtrlRegs.GPAPUD.bit.GPIO16 = 0;// Enable pull-up on GPIO16 (TZ2)
// GpioCtrlRegs.GPAPUD.bit.GPIO28 = 0;// Enable pull-up on GPIO28 (TZ2)
	GpioCtrlRegs.GPAPUD.bit.GPIO14 = 0;// Enable pull-up on GPIO14 (TZ3)
// GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0;// Enable pull-up on GPIO17 (TZ3)
// GpioCtrlRegs.GPAPUD.bit.GPIO29 = 0;// Enable pull-up on GPIO29 (TZ3)

/* Set qualification for selected pins to asynch only */
// Inputs are synchronized to SYSCLKOUT by default.
// This will select asynch (no qualification) for the selected pins.
// Comment out other unwanted lines.

	GpioCtrlRegs.GPAQSEL1.bit.GPIO12 = 3;  // Asynch input GPIO12 (TZ1)
// GpioCtrlRegs.GPAQSEL1.bit.GPIO15 = 3;  // Asynch input GPIO15 (TZ1)
	GpioCtrlRegs.GPAQSEL1.bit.GPIO13 = 3;  // Asynch input GPIO13 (TZ2)
// GpioCtrlRegs.GPAQSEL2.bit.GPIO16 = 3;  // Asynch input GPIO16 (TZ2)
// GpioCtrlRegs.GPAQSEL2.bit.GPIO28 = 3;  // Asynch input GPIO28 (TZ2)
	GpioCtrlRegs.GPAQSEL1.bit.GPIO14 = 3;  // Asynch input GPIO14 (TZ3)
// GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3;  // Asynch input GPIO17 (TZ3)
// GpioCtrlRegs.GPAQSEL2.bit.GPIO29 = 3;  // Asynch input GPIO29 (TZ3)


/* Configure TZ pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be TZ functional pins.
// Comment out other unwanted lines.
	GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 1;  // Configure GPIO12 as TZ1
//GpioCtrlRegs.GPAMUX1.bit.GPIO15 = 1;  // Configure GPIO15 as TZ1
	GpioCtrlRegs.GPAMUX1.bit.GPIO13 = 1;  // Configure GPIO13 as TZ2
// GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 3;  // Configure GPIO16 as TZ2
// GpioCtrlRegs.GPAMUX2.bit.GPIO28 = 3;  // Configure GPIO28 as TZ2
	GpioCtrlRegs.GPAMUX1.bit.GPIO14 = 1;  // Configure GPIO14 as TZ3
// GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 3;  // Configure GPIO17 as TZ3
// GpioCtrlRegs.GPAMUX2.bit.GPIO29 = 3;  // Configure GPIO29 as TZ3

	EDIS;

}

//******************************************************************
// 函数名	:void InitEPwmDriver(void)
// 作者		篢I
// 功能		:初始低砅WM模块寄存髋渲?
// 参数		:无
// 	:无
// 调用全局变量?
// 
// 备注
//******************************************************************
void InitEPwmDriver(void)
{ 
//#if DSP28_EPWM1InitEPwm1Driver();
//#endif 

//#if DSP28_EPWM2
	InitEPwm2Driver();
//#endif 

//#if DSP28_EPWM3
	InitEPwm3Driver();
//#endif 

//#if DSP28_EPWM4
	//InitEPwm4Driver();
//#endif 

//#if DSP28_EPWM5
	//InitEPwm5Driver();
//#endif 

//#if DSP28_EPWM6
//	InitEPwm6Driver();
//#endif 

#if DSP28_EPWM7
//	InitEPwm7Driver();
#endif 
}


//******************************************************************
// 函数名	:void InitEPwm1Driver(void)
// 作者		:TI
// 功		:初始化系统ePWM1寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	
//******************************************************************
#if DSP28_EPWM1
void InitEPwm1Driver(void)
{
	EALLOW;	
	EPwm1Regs.TBPRD 	= 3000;////PFSB_PERIOD,1250-48K
	//EPwm1Regs.TBPRD 	= 1500;////PFSB_PERIOD,1250-48K
	EPwm1Regs.TBPHS.all	= 0;
	EPwm1Regs.TBCTR		= 0;

	// Setup TBCLK
	EPwm1Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// Count up
	//EPwm1Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;
	EPwm1Regs.TBCTL.bit.PHSEN		= TB_DISABLE;		// Disable phase loading  
	EPwm1Regs.TBCTL.bit.PRDLD		= TB_SHADOW;		//
	EPwm1Regs.TBCTL.bit.SYNCOSEL	= TB_CTR_ZERO;//Count equal to zero; have a syn output
	EPwm1Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm1Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;			//
	EPwm1Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm1Regs.TBCTL.bit.PHSDIR		= 1; 
	EPwm1Regs.TBCTL.bit.FREE_SOFT	= 3;	//
	// Setup compare 
	EPwm1Regs.CMPA.half.CMPA= 1500;
	EPwm1Regs.CMPB = 1500;
	EPwm1Regs.TBPHS.half.TBPHS = 0;
	// Setup CMPCTL 
	EPwm1Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm1Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm1Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm1Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;/////
	EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;
	EPwm1Regs.AQCTLB.bit.ZRO = AQ_CLEAR;	
	EPwm1Regs.AQCTLB.bit.CBU = AQ_SET;

	//EPwm1Regs.AQSFRC.bit.RLDCSF = 0;

	
	//Set DeadBand
	EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;//
	EPwm1Regs.DBCTL.bit.IN_MODE = 0x0;
	EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
	//EPwm1Regs.DBFED = 200;//
	//EPwm1Regs.DBRED = 200;//
	EPwm1Regs.DBFED = 300;//
	EPwm1Regs.DBRED = 300;// 
	//EPwm1Regs.DBCTL.bit.HALFCYCLE = 1;

	//	// Set ETSEL
	EPwm1Regs.ETSEL.bit.INTSEL	= ET_CTR_ZERO;			// 2:0EPWMxINTn Select
	EPwm1Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable
	EPwm1Regs.ETSEL.bit.SOCASEL	= ET_CTRU_CMPA;			// 10:8Start of conversion A Select  
	EPwm1Regs.ETSEL.bit.SOCAEN	= ET_ENABLE;			// 11Start of conversion A Enable  
	EPwm1Regs.ETSEL.bit.SOCBSEL	= ET_CTRU_CMPB;			// 14:12  Start of conversion B Select	
	EPwm1Regs.ETSEL.bit.SOCBEN	= ET_ENABLE;			// 15Start of conversion B Enable

	EPwm1Regs.ETPS.bit.INTPRD	= ET_1ST;		// 1:0EPWMxINTn Period Select
	EPwm1Regs.ETPS.bit.INTCNT	= 0;		// 3:2EPWMxINTn Counter Register 
	EPwm1Regs.ETPS.bit.SOCAPRD	= ET_1ST;		// 9:8EPWMxSOCA Period Select
	EPwm1Regs.ETPS.bit.SOCACNT	= 0;		// 11:10  EPWMxSOCA Counter Register 
	EPwm1Regs.ETPS.bit.SOCBPRD	= 1;		// 13:12  EPWMxSOCB Period Select
	EPwm1Regs.ETPS.bit.SOCBCNT	= 0;		// 15:14  EPWMxSOCB Counter Register
 ///////////////////////////////////////////////////////EPwm1Regs.TZSEL.bit.DCAEVT2 = 1;//////EPwm1Regs.TZSEL.bit.DCAEVT2 = 0;//////EPwm1Regs.TZSEL.bit.DCBEVT2 = 0;//////EPwm1Regs.TZSEL.bit.DCBEVT2 = 1;EPwm1Regs.TZSEL.bit.CBC1=1;

// What do we want the TZ1 and TZ2 to doEPwm1Regs.TZCTL.bit.TZA = TZ_FORCE_LO;EPwm1Regs.TZCTL.bit.TZB = TZ_FORCE_LO;//EPwm1Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCBH_LOW; //TZ_DCAH_HI;//EPwm1Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCAH_LOW;EPwm1Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_HI;EPwm1Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCAH_HI;EPwm1Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP1OUT;// DCAH = Comparator 2 output
	EDIS;	
}
#endif 


//******************************************************************
// 函数名	:void InitEPwm2Driver(void)
// 作者		:TI
// 功能		初始化系统ePWM2寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	
//******************************************************************
#if DSP28_EPWM2
void InitEPwm2Driver(void)
{	EALLOW;
	//SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;	// Stop all the TB clocks	
	//EPwm2Regs.TBPRD 	= 1874;///48k
	EPwm2Regs.TBPRD 	= 3000;///20k// Count up
	//EPwm2Regs.TBPRD 	= 1500;///20k//Count updown
	EPwm2Regs.TBPHS.all	= 0;
	EPwm2Regs.TBCTR		= 0;

	// Setup TBCLK
	EPwm2Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// Count up
	//EPwm2Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;//Count updown
	EPwm2Regs.TBCTL.bit.PHSEN		= TB_ENABLE;		// Enable phase loading  
	EPwm2Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm2Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_IN;
	EPwm2Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm2Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm2Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm2Regs.TBCTL.bit.PHSDIR		= 1; 
	EPwm2Regs.TBCTL.bit.FREE_SOFT	= 3;				// 


	// Setup compare 
	EPwm2Regs.CMPA.half.CMPA= 1500;//
	EPwm2Regs.CMPB= 1500;//
	EPwm2Regs.TBPHS.half.TBPHS = 0;
	
	// Setup CMPCTL 
	EPwm2Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm2Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm2Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm2Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm2Regs.AQCTLA.bit.ZRO = AQ_SET;
	EPwm2Regs.AQCTLA.bit.CAU = AQ_CLEAR;
	EPwm2Regs.AQCTLB.bit.ZRO = AQ_CLEAR ;
	EPwm2Regs.AQCTLB.bit.CBU = AQ_SET;
	
//	EPwm2Regs.AQSFRC.bit.RLDCSF = 3;

	//Set DeadBand
 	EPwm2Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
	EPwm2Regs.DBCTL.bit.IN_MODE = 0x0;
	EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
	//EPwm2Regs.DBFED = 200 ;//
	//EPwm2Regs.DBRED = 200;
	EPwm2Regs.DBFED = 300;//
	EPwm2Regs.DBRED = 300; 
	////斩波比较模块
	//EPwm2Regs.TZSEL.bit.DCAEVT2 = 1;
	//EPwm2Regs.TZSEL.bit.DCAEVT2 = 0;
	//EPwm2Regs.TZSEL.bit.DCBEVT2 = 0;
	//EPwm2Regs.TZSEL.bit.DCBEVT2 = 1;
	EPwm2Regs.TZSEL.bit.CBC1=1;// What do we want the TZ1 and TZ2 to do?EPwm2Regs.TZCTL.bit.TZA = TZ_FORCE_LO;EPwm2Regs.TZCTL.bit.TZB = TZ_FORCE_LO;//EPwm2Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCBH_LOW;//EPwm2Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCBH_LOW;EPwm2Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_HI;EPwm2Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCAH_HI;EPwm2Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP1OUT; // DCAH = Comparator 2 outputEPwm2Regs.DCACTL.bit.EVT2SRCSEL = DC_EVT2;// DCAEVT2 = DCAEVT2 (not filtered)EPwm2Regs.DCACTL.bit.EVT2FRCSYNCSEL = DC_EVT_ASYNC;// Take async pathEPwm2Regs.TZEINT.bit.DCBEVT2=0;//??
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS;

}
#endif 

//******************************************************************
// 函数名	:void InitEPwm3Driver(void)
// 作者		:TI
// 功能		:初始化系统ePWM3寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:
//******************************************************************
//#if DSP28_EPWM3
void InitEPwm3Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	//EPwm3Regs.TBPRD 			= Motor_PERIOD;
	EPwm3Regs.TBPRD 			= 3000;//1500;//C_MOTOR_PWM_PRD;
	EPwm3Regs.TBPHS.all			= 0;
	EPwm3Regs.TBCTR				= 0;
	EPwm3Regs.TBPHS.half.TBPHS	= 0;

	// Setup TBCLK
	//EPwm3Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;		// Count up
	EPwm3Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// 对称波形输出 
	EPwm3Regs.TBCTL.bit.PHSEN		= TB_DISABLE;// Disable phase loading  
	EPwm3Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	//EPwm3Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_DISABLE;
	EPwm3Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_IN;	//  Count equal to zero; have a syn output
	EPwm3Regs.TBCTL.bit.SWFSYNC		= 0; 
	//EPwm3Regs.TBCTL.bit.HSPCLKDIV	= 0x04;///1/8
	EPwm3Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
//	EPwm3Regs.TBCTL.bit.CLKDIV		= 0x04;///1/16 
	EPwm3Regs.TBCTL.bit.CLKDIV		= TB_DIV1;
	EPwm3Regs.TBCTL.bit.PHSDIR		= 1;
	EPwm3Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compareEPwm3Regs.CMPA.half.CMPA =1500;
	EPwm3Regs.CMPB  = 0;
	// Setup CMPCTL 
	EPwm3Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm3Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm3Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm3Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm3Regs.AQCTLA.bit.CAU = AQ_CLEAR;			// 
	EPwm3Regs.AQCTLA.bit.PRD = AQ_SET;				//  
	EPwm3Regs.AQCTLB.bit.CBU = AQ_SET;				// 
	EPwm3Regs.AQCTLB.bit.PRD = AQ_CLEAR;	// 

	EPwm3Regs.ETSEL.bit.INTSEL	= ET_CTR_PRD;			// 2:0EPWMxINTn Select
	EPwm3Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable
	
/////////////////////////////////////////////////////
	//死区模块(DB)配置
	EPwm3Regs.DBCTL.bit.OUT_MODE =DB_FULL_ENABLE;
	EPwm3Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
	EPwm3Regs.DBCTL.bit.IN_MODE = 0;
	//EPwm3Regs.DBCTL.bit.HALFCYCLE = 0;
	EPwm3Regs.DBFED = 200;//Falling delay
	EPwm3Regs.DBRED = 200;  //Raising delay  //0.01667*300=5U

	// 事件触发模块(EZ)配置
	EPwm3Regs.ETSEL.bit.INTSEL	= ET_CTRD_CMPA;		// 2:0EPWMxINTn Select
	EPwm3Regs.ETSEL.bit.INTEN	= ET_DISABLE;		// 3EPWMxINTn Enable
	EPwm3Regs.ETSEL.bit.SOCASEL	= ET_CTR_ZERO;		// 10:8Start of conversion A Select  
	EPwm3Regs.ETSEL.bit.SOCAEN	= ET_ENABLE;		// 11Start of conversion A Enable  
	EPwm3Regs.ETSEL.bit.SOCBSEL	= ET_CTR_ZERO;		// 14:12  Start of conversion B Select  
	EPwm3Regs.ETSEL.bit.SOCBEN	= ET_ENABLE;		// 15Start of conversion B Enable  

	EPwm3Regs.ETPS.bit.INTPRD = 1;		// 1:0EPWMxINTn Period Select
	EPwm3Regs.ETPS.bit.INTCNT = 0;		// 3:2EPWMxINTn Counter Register 
	EPwm3Regs.ETPS.bit.SOCAPRD = 1;		// 9:8EPWMxSOCA Period Select
	EPwm3Regs.ETPS.bit.SOCACNT = 0;		// 11:10  EPWMxSOCA Counter Register 
	EPwm3Regs.ETPS.bit.SOCBPRD = 1;		// 13:12  EPWMxSOCB Period Select
	EPwm3Regs.ETPS.bit.SOCBCNT = 0;	 	// 15:14  EPWMxSOCB Counter Register 	
	EDIS; 
}
//#endif 
//******************************************************************
// 函数名	:void InitEPwm4Driver(void)
// 作者		:TI
// 功能		:初始化系统ePWM4寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	送丝机H桥驱动
//******************************************************************
//#if DSP28_EPWM4
void InitEPwm4Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	
	EPwm4Regs.TBPRD 			= 1000;
	EPwm4Regs.TBPHS.all			= 0;
	EPwm4Regs.TBCTR				= 0;
	EPwm4Regs.TBPHS.half.TBPHS	= 0;
	
	// Setup TBCLK
	EPwm4Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;	// Count up and down 
	EPwm4Regs.TBCTL.bit.PHSEN		= TB_DISABLE;		// Disable phase loading  
	EPwm4Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm4Regs.TBCTL.bit.SYNCOSEL	= TB_CTR_ZERO;
	EPwm4Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm4Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm4Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm4Regs.TBCTL.bit.PHSDIR		= 1; 
	EPwm4Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compare 
	EPwm4Regs.CMPA.half.CMPA = Motor_PERIOD - 5;
	EPwm4Regs.CMPB = 5;

	// Setup CMPCTL 
	EPwm4Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm4Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm4Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm4Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm4Regs.AQCTLA.bit.CAU =  AQ_SET;					// Set PWM4A
	EPwm4Regs.AQCTLA.bit.CAD =  AQ_CLEAR;
	EPwm4Regs.AQCTLB.bit.CBU = AQ_CLEAR;				// Set PWM4B
	EPwm4Regs.AQCTLB.bit.CBD = AQ_SET;

//	EPwm4Regs.AQSFRC.bit.RLDCSF = 3;

	// Set deadband
//	EPwm4Regs.DBCTL.bit.OUT_MODE = DB_DISABLE;// Dead-band Output Mode Control
//	EPwm4Regs.DBCTL.bit.POLSEL= DB_ACTV_HI;// Polarity Select Control
//	EPwm4Regs.DBCTL.bit.IN_MODE  = DBB_ALL;// Dead Band Input Mode Control
//	EPwm4Regs.DBFED = 100;//Falling delay
//	EPwm4Regs.DBRED = 100;//Raising delay
	
	// Set ETSEL
	EPwm4Regs.ETSEL.bit.INTSEL	= ET_CTRD_CMPB;	// 2:0EPWMxINTn Select
	EPwm4Regs.ETSEL.bit.INTEN	= ET_ENABLE;		// 3EPWMxINTn Enable
	EPwm4Regs.ETSEL.bit.SOCASEL	= ET_CTR_ZERO;		// 10:8Start of conversion A Select
	EPwm4Regs.ETSEL.bit.SOCAEN	= ET_ENABLE;		// 11Start of conversion A Enable
	EPwm4Regs.ETSEL.bit.SOCBSEL	= ET_CTR_ZERO;			// 14:12  Start of conversion B Select  
	EPwm4Regs.ETSEL.bit.SOCBEN	= ET_ENABLE;		// 15Start of conversion B Enable

	EPwm4Regs.ETPS.bit.INTPRD	= ET_1ST;		// 1:0EPWMxINTn Period Select
	EPwm4Regs.ETPS.bit.INTCNT	= 0;			// 3:2EPWMxINTn Counter Register 
	EPwm4Regs.ETPS.bit.SOCAPRD	= ET_1ST;		// 9:8EPWMxSOCA Period Select
	EPwm4Regs.ETPS.bit.SOCACNT	= 0;			// 11:10  EPWMxSOCA Counter Register 
	EPwm4Regs.ETPS.bit.SOCBPRD	= ET_1ST;		// 13:12  EPWMxSOCB Period Select
	EPwm4Regs.ETPS.bit.SOCBCNT	= 0;			// 15:14  EPWMxSOCB Counter Register 
//	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS; 	
}
//#endif 

//******************************************************************
// 函数名	:void InitEPwm5Driver(void)
// 作者		:何志军
// 功能		:初始化系统ePWM5寄存髋渲?
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	送丝机H桥驱动
//******************************************************************
//#if DSP28_EPWM5
void InitEPwm5Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	EPwm5Regs.TBPRD 			= 1000;
	EPwm5Regs.TBPHS.all			= 0;
	EPwm5Regs.TBCTR				= 0;

	// Setup TBCLK
	EPwm5Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UPDOWN;		// Count up
	EPwm5Regs.TBCTL.bit.PHSEN		= TB_ENABLE;	// Disable phase loading  
	EPwm5Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm5Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_IN;
	EPwm5Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm5Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm5Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm5Regs.TBCTL.bit.PHSDIR		= 1; 
	EPwm5Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compare 
	EPwm5Regs.CMPA.half.CMPA = Motor_PERIOD - 5;
	EPwm5Regs.CMPB = 5;

	// Setup CMPCTL 
	EPwm5Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm5Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm5Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm5Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm5Regs.AQCTLA.bit.CAU = AQ_SET;					// Set PWM6A
	EPwm5Regs.AQCTLA.bit.CAD = AQ_CLEAR;
	EPwm5Regs.AQCTLB.bit.CBU = AQ_CLEAR;				// Set PWM6B
	EPwm5Regs.AQCTLB.bit.CBD = AQ_SET;
	
	// set deadband
	// EPwm5Regs.DBCTL.bit.OUT_MODE = DB_DISABLE;// Dead-band Output Mode Control
	// EPwm5Regs.DBCTL.bit.POLSEL= DB_ACTV_HI;// Polarity Select Control
			// EPwm5Regs.DBCTL.bit.IN_MODE  = DBB_ALL;// Dead Band Input Mode Control
	// EPwm5Regs.DBFED = 100;//Falling delay
	// EPwm5Regs.DBRED = 100;//Raising delay

	EPwm5Regs.ETSEL.bit.INTSEL	= ET_CTRD_CMPB;			// 2:0EPWMxINTn Select
	EPwm5Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable
	EPwm5Regs.ETSEL.bit.SOCASEL	= ET_CTR_ZERO;// 10:8Start of conversion A Select  
	EPwm5Regs.ETSEL.bit.SOCAEN	= ET_DISABLE;			// 11Start of conversion A Enable  
	EPwm5Regs.ETSEL.bit.SOCBSEL	= ET_CTR_ZERO;	// 14:12  Start of conversion B Select  
	EPwm5Regs.ETSEL.bit.SOCBEN	= ET_DISABLE;			// 15Start of conversion B Enable  

	EPwm5Regs.ETPS.bit.INTPRD = 1;		// 1:0EPWMxINTn Period Select
	EPwm5Regs.ETPS.bit.INTCNT = 0;		// 3:2EPWMxINTn Counter Register 
	EPwm5Regs.ETPS.bit.SOCAPRD = 0;		// 9:8EPWMxSOCA Period Select
	EPwm5Regs.ETPS.bit.SOCACNT = 0;		// 11:10  EPWMxSOCA Counter Register 
	EPwm5Regs.ETPS.bit.SOCBPRD = 0;		// 13:12  EPWMxSOCB Period Select
	EPwm5Regs.ETPS.bit.SOCBCNT = 0;		// 15:14  EPWMxSOCB Counter Register 

//	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS; 
}
//#endif 

//******************************************************************
// 函数名	:void InitEPwm6Driver(void)
// 作者		:TI
// 功能		:初始化系统ePWM6寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改全局变量:无
// 备注		:	加热阀控制
//******************************************************************
//#if DSP28_EPWM6//

void InitEPwm6Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	EPwm6Regs.TBPRD 			= 1500;
	EPwm6Regs.TBPHS.all			= 0;
	EPwm6Regs.TBCTR				= 0;
	EPwm6Regs.TBPHS.half.TBPHS	= 0;

	// Setup TBCLK
	EPwm6Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// Count up
	EPwm6Regs.TBCTL.bit.PHSEN		= TB_DISABLE;// Disable phase loading  
	EPwm6Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm6Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_DISABLE;
	EPwm6Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm6Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm6Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm6Regs.TBCTL.bit.PHSDIR		= 1;
	EPwm6Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compare 
	EPwm6Regs.CMPA.half.CMPA  = 3;
	// Setup CMPCTL 
	EPwm6Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm6Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm6Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm6Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	EPwm6Regs.AQCTLA.bit.CAU = AQ_CLEAR;				// Set PWM6A
	EPwm6Regs.AQCTLA.bit.ZRO = AQ_SET;

	EPwm6Regs.ETSEL.bit.INTSEL	= ET_CTR_PRD;			// 2:0EPWMxINTn Select
	EPwm6Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable

	EPwm6Regs.ETPS.bit.INTPRD = 1;		// 1:0EPWMxINTn Period Select
	EPwm6Regs.ETPS.bit.INTCNT = 0;		// 3:2EPWMxINTn Counter Register
	EPwm6Regs.AQCSFRC.bit.CSFA = 0;
	EPwm6Regs.AQCSFRC.bit.CSFB = 0;// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS; 
}
//#endif 

//******************************************************************
// 函数名	:void InitEPwm7Driver(void)
// 作者		:TI
// 功能		:初始化系统ePWM7寄存器配置
// 参数		:无
// 返回值	:无
// 调用全局变量:无
// 修改绷浚何?
// 备注		:	Slope Compensation PWM Control	(Hardware
//******************************************************************
//#if DSP28_EPWM7
void InitEPwm7Driver(void)
{
	EALLOW;
	// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
	EPwm7Regs.TBPRD 			= 1000;//3130--10K
	EPwm7Regs.TBPHS.all			= 0;
	EPwm7Regs.TBCTR				= 0;
	EPwm7Regs.TBPHS.half.TBPHS	= 0;

	// Setup TBCLK
	EPwm7Regs.TBCTL.bit.CTRMODE		= TB_COUNT_UP;		// Count up
	EPwm7Regs.TBCTL.bit.PHSEN		= TB_DISABLE;		// Disable phase loading  
	EPwm7Regs.TBCTL.bit.PRDLD		= TB_SHADOW;
	EPwm7Regs.TBCTL.bit.SYNCOSEL	= TB_SYNC_DISABLE;
	EPwm7Regs.TBCTL.bit.SWFSYNC		= 0; 
	EPwm7Regs.TBCTL.bit.HSPCLKDIV	= TB_DIV1;
	EPwm7Regs.TBCTL.bit.CLKDIV		= TB_DIV1;  
	EPwm7Regs.TBCTL.bit.PHSDIR		= 1;
	EPwm7Regs.TBCTL.bit.FREE_SOFT	= 3;

	// Setup compare 
	EPwm7Regs.CMPB = 0;
	// Setup CMPCTL 
	EPwm7Regs.CMPCTL.bit.SHDWAMODE	= CC_SHADOW;		// Load registers every ZERO
	EPwm7Regs.CMPCTL.bit.SHDWBMODE	= CC_SHADOW;
	EPwm7Regs.CMPCTL.bit.LOADAMODE	= CC_CTR_ZERO;
	EPwm7Regs.CMPCTL.bit.LOADBMODE	= CC_CTR_ZERO; 
	
	// Set actions
	// EPwm7Regs.AQCTLB.bit.CBU = AQ_CLEAR;				// Set PWM7B
	// EPwm7Regs.AQCTLB.bit.CBD = AQ_SET;
	EPwm7Regs.AQCTLB.bit.ZRO = AQ_SET;
	EPwm7Regs.AQCTLB.bit.CBU = AQ_CLEAR;

	EPwm7Regs.ETSEL.bit.INTSEL	= ET_CTRD_CMPB;			// 2:0EPWMxINTn Select
	EPwm7Regs.ETSEL.bit.INTEN	= ET_ENABLE;			// 3EPWMxINTn Enable

	EPwm7Regs.ETPS.bit.INTPRD = 1;		// 1:0EPWMxINTn Period Select
	EPwm7Regs.ETPS.bit.INTCNT = 0;		// 3:2EPWMxINTn Counter Register

//	SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;// Start all the timers synced
	EDIS; 
}
//#endif 


/******************************************************************/
//函数名:void InitTzDriver(void)
//功能:Initialize the TZ Module for epwm1,epwm2,epwm4,epwm5 and epwm6 of WPPM3312Z
//备注:2015.06.25
//===========================================================================
void InitTzDriver(void)
{// Enable TZ1/TZ2 and TZ3 as one shot trip sources on EPwm1 Module
	EALLOW;
	EPwm1Regs.TZSEL.bit.CBC1 = 1;
	//EPwm1Regs.TZSEL.bit.OSHT1 = 1;
	//EPwm1Regs.TZSEL.bit.DCBEVT1 = 1;
	EPwm1Regs.TZSEL.bit.DCAEVT1 = 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm1Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	EPwm1Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	EPwm1Regs.TZCTL.bit.DCAEVT1 = 2;
	// EPwm1Regs.TZCTL.bit.DCBEVT1= 2;

	// EPwm1Regs.TZDCSEL.bit.DCBEVT1 = TZ_DCBH_LOW;
	EPwm1Regs.TZDCSEL.bit.DCAEVT1 = TZ_DCAH_HI;
	// Enable TZ interrupt
	// EPwm1Regs.TZEINT.bit.OST = 1;
	// EDIS;
	// Enable  TZ1\TZ2 and TZ3 as one shot trip sources on EPwm2 Module
	// EALLOW;
	EPwm2Regs.TZSEL.bit.CBC1 = 1;  
	//EPwm2Regs.TZSEL.bit.OSHT1 = 1;  
	// EPwm2Regs.TZSEL.bit.DCBEVT1= 1;
	EPwm2Regs.TZSEL.bit.DCAEVT1= 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm2Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	EPwm2Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	EPwm2Regs.TZCTL.bit.DCAEVT1 = 2;
	// EPwm2Regs.TZCTL.bit.DCBEVT1 = 2;

	// EPwm2Regs.TZDCSEL.bit.DCBEVT1 = TZ_DCBH_LOW;
	EPwm2Regs.TZDCSEL.bit.DCAEVT1 = TZ_DCAH_HI;
	// Enable TZ interrupt
	// EPwm2Regs.TZEINT.bit.OST = 1;
	// EDIS;
	// Enable TZ1/TZ2 and TZ3 as one shot trip sources on EPwm4 Module
	EPwm3Regs.TZSEL.bit.CBC3 = 1;//FAN

	EPwm3Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	// EALLOW;
	// EPwm4Regs.TZSEL.bit.CBC1 = 1;
	EPwm4Regs.TZSEL.bit.DCAEVT2 = 1;
	// EPwm4Regs.TZSEL.bit.DCBEVT2 = 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm4Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	EPwm4Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	// EPwm4Regs.TZCTL.bit.DCAEVT2 = 2;
	// EPwm4Regs.TZCTL.bit.DCBEVT2 = 2;


	// EPwm4Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCBH_LOW;
	EPwm4Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_LOW;
	// Enable TZ interrupt
	// EPwm4Regs.TZEINT.bit.OST = 1;
	// EDIS;
	
	
	// Enable TZ1/TZ2 and TZ3 as one shot trip sources on EPwm5 Module
	// EALLOW;
	// EPwm5Regs.TZSEL.bit.CBC1 = 1;
	// EPwm5Regs.TZSEL.bit.CBC2 = 1;
	//EPwm5Regs.TZSEL.bit.CBC3 = 1;//FAN
	EPwm5Regs.TZSEL.bit.DCAEVT2 = 1;
	// EPwm5Regs.TZSEL.bit.DCAEVT2 = 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm5Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	EPwm5Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	// EPwm5Regs.TZCTL.bit.DCAEVT2 = 2;
	// EPwm5Regs.TZCTL.bit.DCBEVT2 = 2;

	EPwm5Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_LOW;
	// EPwm5Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCAH_LOW;
	// Enable TZ interrupt
	// EPwm5Regs.TZEINT.bit.OST = 1;
	// EDIS;
	
	// Enable TZ1\TZ2 and TZ3 as one shot trip sources on EPwm3 Module
	// EALLOW;
	// EPwm6Regs.TZSEL.bit.CBC1 = 1;
	EPwm6Regs.TZSEL.bit.CBC2 = 1;///JRF
	// EPwm6Regs.TZSEL.bit.CBC3 = 1;
	// EPwm6Regs.TZSEL.bit.DCAEVT2= 1;
	// EPwm6Regs.TZSEL.bit.DCBEVT2 = 1;
	// What do we want the TZ1 and TZ2 to do?
	EPwm6Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
	// EPwm6Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
	// EPwm6Regs.TZCTL.bit.DCAEVT2 = 2;
	// EPwm6Regs.TZCTL.bit.DCBEVT2 = 2;

	// EPwm6Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCBH_LOW;
	// EPwm6Regs.TZDCSEL.bit.DCAEVT2= TZ_DCAH_HI;
	// EPwm7Regs.TZSEL.bit.CBC2 = 1;//JRF
	// EPwm7Regs.TZCTL.bit.TZA = TZ_FORCE_LO;

	// Enable TZ interrupt
	// EPwm6Regs.TZEINT.bit.OST = 1;
	EDIS;
	
	
}

/***********************************************************/
//函数名:void InitDCEventDriver
//功能:Initialize Digtal Compare Event Module
//备注:DC Event for protecting Power and Motor
//===========================================================================
void InitDCEventDriver(void)
{
	
	// Define an event (DCAEVT1) based on TZ1 and TZ2
	EALLOW;
	EPwm1Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP1OUT;// DCAH = Comparator 1 output and TZ1 input
	// EPwm1Regs.DCTRIPSEL.bit.DCBHCOMPSEL = DC_TZ1 ;
	EPwm1Regs.DCACTL.bit.EVT1SRCSEL = DC_EVT1;// DCAEVT1 = DCAEVT1(not filtered)
	EPwm1Regs.DCACTL.bit.EVT1FRCSYNCSEL = DC_EVT_ASYNC;

	EPwm2Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP1OUT;// DCAH = Comparator 1 output AND TZ1 input
	// EPwm2Regs.DCTRIPSEL.bit.DCBHCOMPSEL = DC_TZ1;
	EPwm2Regs.DCACTL.bit.EVT1SRCSEL = DC_EVT1;// DCAEVT1 = DCAEVT1 (not filtered)
	EPwm2Regs.DCACTL.bit.EVT1FRCSYNCSEL = DC_EVT_ASYNC;

	EPwm4Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP2OUT;// DCAH = Comparator 2 output
	EPwm4Regs.DCACTL.bit.EVT2SRCSEL = DC_EVT2;// DCAEVT2 = DCAEVT2 (not filtered)
	EPwm4Regs.DCACTL.bit.EVT2FRCSYNCSEL = DC_EVT_ASYNC;// Take async path

	EPwm5Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP2OUT;// DCAH = Comparator 2 output
	EPwm5Regs.DCACTL.bit.EVT2SRCSEL = DC_EVT2;// DCAEVT2= DCAEVT2 (not filtered)
	EPwm5Regs.DCACTL.bit.EVT2FRCSYNCSEL = DC_EVT_ASYNC;// Take async path

	EDIS;
}


//===========================================================================
// End of file.
//===========================================================================

----------------------以上为DSP2803x_EPwm.c-----------------------------------------------------------

ke ma:

回复 Jordan Zhou:

不是。问题是一个ePWM周期内只应该斩波一次,现在它斩波了两次甚至更多次。如上图示波器抓取的ab之间为一个ePWM周期,3通道(紫色)有高电平斩波后变为低电平,在这个周期内应该一直为低电平,直到下一个ePWM周期再开始新的动作。

赞(0)
未经允许不得转载:TI中文支持网 » TMS320F28034 PCMC斩波问题
分享到: 更多 (0)