#include "DSP281x_Device.h"
#include "DSP281x_SysCtrl.h"
#include "DSP281x_Gpio.h"
#include "DSP281x_Ev.h"
void InitSysCtrl(void) //系统初始化
{
Uint16 i;
EALLOW;
SysCtrlRegs.WDCR=0x0068; //禁止看门狗
SysCtrlRegs.PLLCR.all=0xA; //初始化PLL
for(i=0;i<5000;i++)
{}
SysCtrlRegs.HISPCP.all=0x0001; //HSPCLK=75MHz
SysCtrlRegs.LOSPCP.all=0x0002; //LOSPCP=37.5MHz
SysCtrlRegs.PCLKCR.bit.EVAENCLK=1; //使能EVA时钟
SysCtrlRegs.PCLKCR.bit.EVBENCLK=1; //使能EVB时钟
EDIS;
}
void InitGpio(void)
{
EALLOW;
GpioMuxRegs.GPAMUX.bit.PWM1_GPIOA0=1;
GpioMuxRegs.GPAMUX.bit.PWM2_GPIOA1=1;
GpioMuxRegs.GPAMUX.bit.PWM3_GPIOA2=1;
GpioMuxRegs.GPAMUX.bit.PWM4_GPIOA3=1;
GpioMuxRegs.GPBMUX.bit.PWM7_GPIOB0=1;
GpioMuxRegs.GPBMUX.bit.PWM8_GPIOB1=1;
GpioMuxRegs.GPBMUX.bit.PWM9_GPIOB2=1;
GpioMuxRegs.GPBMUX.bit.PWM10_GPIOB3=1;
EDIS;
}
void InitEv(void)
{
EvaRegs.T1CON.bit.TMODE=2; //连续增模式
EvaRegs.T1CON.bit.TPS=1; //T1CLK=75/2=37.5MHz
EvaRegs.T1CON.bit.TENABLE=0; //暂时禁止T1计数
EvaRegs.T1CON.bit.TCLKS10=0; //使用内部时钟T1CLK
EvaRegs.T1PR=0x03cf;
EvaRegs.T1CNT=0;
EvaRegs.COMCONA.bit.CENABLE=1; //使能比较单元的比较操作
EvaRegs.COMCONA.bit.FCOMPOE=1; //使能输出
EvaRegs.COMCONA.bit.CLD=2;
//死区时间4.27us
EvaRegs.DBTCONA.bit.DBT=10; //死区定时器周期,m=10
EvaRegs.DBTCONA.bit.EDBT1=1; //死区定时器1使能
EvaRegs.DBTCONA.bit.EDBT2=1; //死区定时器2使能
EvaRegs.DBTCONA.bit.DBTPS=4; //死区定时器预定标因子
EvaRegs.ACTRA.all=0x0999; //设定引脚PWM1~6的动作属性,低电平有效
EvaRegs.CMPR1=0x01e8; //PWM1、2的占空比50%
EvaRegs.CMPR2=0x01e8; //PWM3、4的占空比50%
EvbRegs.T3CON.bit.TMODE=2; //连续增模式
EvbRegs.T3CON.bit.TPS=1; //T1CLK=75/2=37.5MHz
EvbRegs.T3CON.bit.TENABLE=0; //暂时禁止T3计数
EvbRegs.T3CON.bit.TCLKS10=0; //使用内部时钟T1CLK
EvbRegs.T3PR=0x03cf;
EvbRegs.T3CNT=0;
EvbRegs.COMCONB.bit.CENABLE=1; //使能比较单元的比较操作
EvbRegs.COMCONB.bit.FCOMPOE=1; //使能输出
EvbRegs.COMCONB.bit.CLD=2;
//死区时间4.27us
EvbRegs.DBTCONB.bit.DBT=10; //死区定时器周期,m=10
EvbRegs.DBTCONB.bit.EDBT1=1; //死区定时器1使能
EvbRegs.DBTCONB.bit.EDBT2=1; //死区定时器2使能
EvbRegs.DBTCONB.bit.DBTPS=4; //死区定时器预定标因子
EvbRegs.ACTRB.all=0x0999; //设定引脚PWM1~6的动作属性,低电平有效
EvbRegs.CMPR4=0x01e8; //PWM7、8的占空比50%
EvbRegs.CMPR5=0x01e8; //PWM9、10的占空比50%
}
main(void)
{
InitSysCtrl();
DINT;
IER=0x0000;
IFR=0x0000;
InitGpio();
InitEv();
EvaRegs.T1CON.bit.TENABLE=1;
EvbRegs.T3CON.bit.TENABLE=1;
for(;;)
{
}
}
|