|
最近在写spwm的程序,但无论怎么,出来的占空比都是50%的,郁闷。希望大家帮我看看。谢谢各位!!
#include "DSP28_Device.h"
#include "math.h"
#include "stdio.h"
interrupt void T1_Compare_isr(void); //定时器1中断服务程序
int i = 0; //定位正弦表
int sine[100] = {996,1055,1113,1171,1227,1283,1337,1389,1440,1489,
1535,1579,1621,1660,1696,1729,1759,17860,1809,1829,
1846,1858,1868,1873,1875,1873,1868,1858,1846,1829,
1809,1786,1759,1729,1696,1660,1621,1579,1535,1489,
1440,1389,1337,1283,1227,1171,1113,1055,996,938,
879,820,762,704,648,592,538,486,435,387,
340,296,254,215,179,146,116,89,66,46,
30,17,7,2,0,2,7,17,30,46,
66,89,116,146,179,215,254,296,340,387,
435,486,538,592,648,704,762,820,879,938};
void main(void)
{
/*GPIO 初始化*/
InitGpio();
/*初始化系统*/
InitSysCtrl();
/*关中断*/
DINT;
IER = 0x0000;
IFR = 0x0000;
/*初始化PIE控制寄存器*/
InitPieCtrl();
/*初始化PIE矢量表*/
InitPieVectTable();
/* EALLOW;
PieVectTable.T1PINT = &T1_Compare_isr;
EDIS;
//使能T1周期中断:PIE-组2,中断4
PieCtrl.PIEIER2.bit.INTx4 = 1;
//使能CPU INT2,GP-Time1的周期中断连接到该中断
IER = 2;*/
EINT;
ERTM;
/*初始化EV*/
InitEv();
EvaRegs.EVAIMRA.bit.T1PINT = 1; //使能T1PINT中断
EvaRegs.T1CON.bit.TENABLE = 1; //使能GP Timer 1
for(;;);
{
KickDog();
}
}
interrupt void T1_Compare_isr(void)
{
EvaRegs.T1CMPR = sine; // 更新比较寄存器CMPRx的值
i = i+1;
if(i==100)
i = 0;
EvaRegs.EVAIMRA.bit.T1PINT = 1; //GP定时器1周期中断标志位 置位
EvaRegs.EVAIFRA.bit.T1PINT = 1; // T1CINT(GP定时器1比较中断位) 使能位 使能
PieCtrl.PIEACK.all = PIEACK_GROUP2; //PIE 响应寄存器
}
void InitEv(void)
{
EvaRegs.GPTCONA.all=0x0051; //GP定时器控制寄存器设置 定时器比较输出使能,T1PIN输出低有效,T1PWM比较输出使能
EvaRegs.T1CNT=0;//定时器1计数器从0开始计数
EvaRegs.T1CON.all=0x0802; //设置控制寄存器为模式为连续增/减,使能定时器和比较器
// EvaRegs.T1PR=0x7530; //30000
EvaRegs.T1PR=0x3A98; //15000
//EvaRegs.T1PR=1875;
EvaRegs.T1CMPR=EvaRegs.T1PR/2;
}
|
|