2019-03-26 15:11发布
cht8805 发表于 2016-7-15 09:31 FLASH烧写已成功,主要问题是BOOTMODE管脚设置不对,引导启动硬件条件不对。现在的问题是调试时SPWM频率2 ...
最多设置5个标签!
#include "DSP28x_Project.h"
volatile Uint32 Num;
int SinceTable[50]={25,28,31,34,37,39,42,44,46,47,48,49,49,49,49,48,
47,46,44,42,39,37,34,31,28,25,21,18,15,12,10,7,
5,3,2,1,0,0,0,0,1,2,3,5,7,10,12,15,
18,21,};
#define PWM1_INT_ENABLE 1
void InitEPwmTimer(void); // EPWM模块初始化程序
void update_compare(void); // 比较值定义
interrupt void epwm1_timer_isr(void); // 中断服务程序
//extern Uint16 RamfuncsLoadStart;
//extern Uint16 RamfuncsLoadEnd;
//extern Uint16 RamfuncsRunStart;
#pragma CODE_SECTION(epwm1_timer_isr, "ramfuncs");
void main(void)
{
InitSysCtrl(); // 系统初始化函数
#ifdef FLASH
//MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
memcpy((uint16_t *)&RamfuncsRunStart,(uint16_t *)&RamfuncsLoadStart, (unsigned long)&RamfuncsLoadSize);
InitFlash();
#endif
InitEPwm1Gpio(); // EPWM端口初始化
DINT; // 关闭CPU中断
InitPieCtrl(); // PIE中断控制
IER = 0x0000; // 关闭中断使能
IFR = 0x0000; // 清除中断标志位
InitPieVectTable();
EALLOW;
PieVectTable.EPWM1_INT = &epwm1_timer_isr;//中断函数入口
EDIS; // 赋值中断函数地址
InitEPwmTimer(); // 初始化EPWM模块
IER |= M_INT3; // 使能CPU级第三组中断
PieCtrlRegs.PIEIER3.bit.INTx1 = PWM1_INT_ENABLE;
// 使能PIE3.1
EINT; // 使能全局中断
ERTM;
Num=0;
for(;;)
{
//DELAY_US(10);
asm(" NOP");
}
}
/*EPWM模块初始化函数*/
void InitEPwmTimer()
{
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // 停止TB计数
EDIS;
EPwm1Regs.ETSEL.bit.INTSEL = ET_CTRU_CMPA; // 计数值等于比较值时产生中断
EPwm1Regs.ETSEL.bit.INTEN = 1; // 使能中断
EPwm1Regs.ETPS.bit.INTPRD = ET_1ST; // 第一次时产生中断
EPwm1Regs.TBPRD =50; //
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; // 同步值
EPwm1Regs.TBCTR = 0; // 清除定时器计数
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // 定时器增模式
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // 同步脉冲装载不使能
EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW; // 从镜像装载
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE; // 关闭同步输出
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // TB时钟等于SYSCLK
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; // 镜像模式
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_PRD; // 当CTR=prd的时候装载镜像数据
//EPwm1Regs.CMPA.half.CMPA = 30000;
EPwm1Regs.CMPA.half.CMPA = 25; //调整占空比 50%时值应等于定时器周期一半
//数值越小,占空比越小
EPwm1Regs.AQCTLA.bit.CAU =AQ_SET;
EPwm1Regs.AQCTLB.bit.CAU =AQ_CLEAR;
EPwm1Regs.AQCTLA.bit.ZRO = AQ_CLEAR;
EPwm1Regs.AQCTLB.bit.ZRO = AQ_SET;
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; // TB时钟计数
EDIS;
}
/*epwm1中断服务程序*/
//c2000的中断函数都要用“inerrupt”申明
interrupt void epwm1_timer_isr(void)
{
if(Num>49)
{Num=0;}
EPwm1Regs.CMPA.half.CMPA=SinceTable[Num];
Num++;
//update_compare();
EPwm1Regs.ETCLR.bit.INT = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
一周热门 更多>