//--------------------
//reference:http://www.hellodsp.com/bbs/viewthread.php?tid=24898&extra=page%3D1
//Dual Channel SIN Generator(Table look-up)
//--------------------
//下载解压后,原始代码如下:
#include "DSP281x_Device.h"
#include "DSP281x_Examples.h"
Uint16 flag="0",count=0;
Uint16 SPWM[125]={8,23,38,53,68,83,98,112,127,142,157,171,185,200,214,228,242,255,269,282,296,
309,321,334,347,359,371,382,394,405,416,427,437,448,457,467,476,485,494,503,511,518,526,533,
540,546,552,558,563,568,573,577,581,585,588,591,593,595,597,598,599,600,600,600,599,598,597,
595,593,591,588,585,581,577,573,568,563,558,552,546,540,533,526,518,511,503,494,485,476,467,
457,448,437,427,416,405,394,382,371,359,347,334,321,309,296,282,269,255,242,228,214,200,185,
171,157,142,127,112,98,83,68,53,38,23,8};
void init_EVA(void);
interrupt void EVA_timer1_isr(void);
void main(void)
{
InitSysCtrl();
EALLOW;
GpioMuxRegs.GPAMUX.all = 0x00FF;
GpioMuxRegs.GPBMUX.all = 0x00FF;
EDIS;
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
init_EVA();
EvaRegs.EVAIMRA.bit.T1PINT=1;
EvaRegs.EVAIFRA.bit.T1PINT=1;
EALLOW;
PieVectTable.T1PINT = &EVA_timer1_isr;
EDIS;
PieCtrlRegs.PIEIER2.all=M_INT4;
IER|=M_INT2;
EINT;
ERTM;
for(;;);
}
interrupt void EVA_timer1_isr(void)
{
if(count==125)
{
flag=~flag;
count="0";
}
else
{
EvaRegs.CMPR1 = 625+SPWM[count];
EvaRegs.CMPR2 = 625+SPWM[count];
count++;
}
else
{
EvaRegs.CMPR1 = 625-SPWM[count];
EvaRegs.CMPR2 = 625-SPWM[count];
count++;
}
EvaRegs.EVAIMRA.bit.T1PINT=1;
EvaRegs.EVAIFRA.all=BIT7;
PieCtrlRegs.PIEACK.all=PIEACK_GROUP2;
}
void init_EVA()
{
EvaRegs.T1PR = 1250;
EvaRegs.T1CMPR = 1250;
EvaRegs.T1CNT = 0x0000;
EvaRegs.T1CON.all = 0x0842;
EvaRegs.GPTCONA.bit.TCMPOE = 1;
EvaRegs.GPTCONA.bit.T1PIN = 1;
EvaRegs.CMPR1 = 1000;
EvaRegs.CMPR2 = 625;
EvaRegs.ACTRA.all = 0x0666;
EvaRegs.DBTCONA.all = 0x0000;
EvaRegs.COMCONA.all = 0xA600;
}
//analy:
[有句话说得好:谁用谁知道。]
编译环境:CCStudio v3.3
编译报错:……
检查后发现:
函数 interrupt void EVA_timer1_isr(void)中的
if……else 语句使用有错。
一次修正:阅读代码后发现,源码中应为
使用了if……else if(...)语句
二次修正:在 if() 语句中 源码为 if(count==125),
在 else if() 语句中写入:count>125 和 count<125
再次编译通过;
泰克(1GS/s,100MHz)观察波形有误。
三次修正:源码在 if() 的花括号内有对 flag 的操作,flag=~flag;,
追踪 flag:Uint16 flag="0"
则 flag 必在后续程序中起到作用。
修改如下:else if(flag)……else if(!flag)。
编译通过;
泰克观察:
得到相似波形。
后面对程序继续做了修改,大体如上。
文章评论(0条评论)
登录后参与讨论