//包含头文件
#include"DSP2833x_Device.h"
#include"DSP2833x_Examples.h"
//声明变量
const int sina[360]=
{
//0~119
0,65,130,196,261,326,391,457,521,586,
651,715,779,843,907,970,1033,1096,1158,1220,
1282,1343,1404,1465,1525,1584,1643,1702,1760,1818,
1874,1931,1987,2042,2096,2150,2204,2256,2308,2359,
2410,2460,2509,2557,2604,2651,2697,2742,2786,2830,
2872,2914,2955,2994,3033,3071,3108,3145,3180,3214,
3247,3279,3311,3341,3370,3398,3425,3451,3476,3500,
3523,3545,3566,3586,3604,3622,3638,3653,3668,3681,
3693,3703,3713,3722,3729,3735,3740,3744,3747,3749,
3749,3749,3747,3744,3740,3735,3729,3722,3713,3703,
3693,3681,3668,3653,3638,3622,3604,3586,3566,3545,
3523,3500,3476,3451,3425,3398,3370,3341,3311,3279,
//120~239
3247,3214,3180,3145,3108,3071,3033,2994,2955,2914,
2872,2830,2786,2742,2697,2651,2604,2557,2509,2460,
2410,2359,2308,2256,2204,2150,2096,2042,1987,1931,
1875,1818,1760,1702,1643,1584,1525,1465,1404,1343,
1282,1220,1158,1096,1033,970,907,843,779,715,
651,586,521,457,391,326,261,196,130,65,
0,-65,-130,-196,-261,-326,-391,-457,-521,-586,
-651,-715,-779,-843,-907,-970,-1033,-1096,-1158,-1220,
-1282,-1343,-1404,-1465,-1525,-1584,-1643,-1702,-1760,-1818,
-1874,-1931,-1987,-2042,-2096,-2150,-2204,-2256,-2308,-2359,
-2410,-2460,-2509,-2557,-2604,-2651,-2697,-2742,-2786,-2830,
-2872,-2914,-2955,-2994,-3033,-3071,-3108,-3145,-3180,-3214,
//240~359
-3247,-3279,-3311,-3341,-3370,-3398,-3425,-3451,-3476,-3500,
-3523,-3545,-3566,-3586,-3604,-3622,-3638,-3653,-3668,-3681,
-3693,-3703,-3713,-3722,-3729,-3735,-3740,-3744,-3747,-3749,
-3749,-3749,-3747,-3744,-3740,-3735,-3729,-3722,-3713,-3703,
-3693,-3681,-3668,-3653,-3638,-3622,-3604,-3586,-3566,-3545,
-3523,-3500,-3476,-3451,-3425,-3398,-3370,-3341,-3311,-3279,
-3247,-3214,-3180,-3145,-3108,-3071,-3033,-2994,-2955,-2914,
-2872,-2830,-2786,-2742,-2697,-2651,-2604,-2557,-2509,-2460,
-2410,-2359,-2308,-2256,-2204,-2150,-2096,-2042,-1987,-1931,
-1875,-1818,-1760,-1702,-1643,-1584,-1525,-1465,-1404,-1343,
-1282,-1220,-1158,-1096,-1033,-970,-907,-843,-779,-715,
-651,-586,-521,-457,-391,-326,-261,-196,-130,-65
};
const int sinb[360]=
{
//120~239
-3247,-3279,-3311,-3341,-3370,-3398,-3425,-3451,-3476,-3500,
-3523,-3545,-3566,-3586,-3604,-3622,-3638,-3653,-3668,-3681,
-3693,-3703,-3713,-3722,-3729,-3735,-3740,-3744,-3747,-3749,
-3749,-3749,-3747,-3744,-3740,-3735,-3729,-3722,-3713,-3703,
-3693,-3681,-3668,-3653,-3638,-3622,-3604,-3586,-3566,-3545,
-3523,-3500,-3476,-3451,-3425,-3398,-3370,-3341,-3311,-3279,
-3247,-3214,-3180,-3145,-3108,-3071,-3033,-2994,-2955,-2914,
-2872,-2830,-2786,-2742,-2697,-2651,-2604,-2557,-2509,-2460,
-2410,-2359,-2308,-2256,-2204,-2150,-2096,-2042,-1987,-1931,
-1875,-1818,-1760,-1702,-1643,-1584,-1525,-1465,-1404,-1343,
-1282,-1220,-1158,-1096,-1033,-970,-907,-843,-779,-715,
-651,-586,-521,-457,-391,-326,-261,-196,-130,-65,
//240~359
0,65,130,196,261,326,391,457,521,586,
651,715,779,843,907,970,1033,1096,1158,1220,
1282,1343,1404,1465,1525,1584,1643,1702,1760,1818,
1874,1931,1987,2042,2096,2150,2204,2256,2308,2359,
2410,2460,2509,2557,2604,2651,2697,2742,2786,2830,
2872,2914,2955,2994,3033,3071,3108,3145,3180,3214,
3247,3279,3311,3341,3370,3398,3425,3451,3476,3500,
3523,3545,3566,3586,3604,3622,3638,3653,3668,3681,
3693,3703,3713,3722,3729,3735,3740,3744,3747,3749,
3749,3749,3747,3744,3740,3735,3729,3722,3713,3703,
3693,3681,3668,3653,3638,3622,3604,3586,3566,3545,
3523,3500,3476,3451,3425,3398,3370,3341,3311,3279,
//0~119
3247,3214,3180,3145,3108,3071,3033,2994,2955,2914,
2872,2830,2786,2742,2697,2651,2604,2557,2509,2460,
2410,2359,2308,2256,2204,2150,2096,2042,1987,1931,
1875,1818,1760,1702,1643,1584,1525,1465,1404,1343,
1282,1220,1158,1096,1033,970,907,843,779,715,
651,586,521,457,391,326,261,196,130,65,
0,-65,-130,-196,-261,-326,-391,-457,-521,-586,
-651,-715,-779,-843,-907,-970,-1033,-1096,-1158,-1220,
-1282,-1343,-1404,-1465,-1525,-1584,-1643,-1702,-1760,-1818,
-1874,-1931,-1987,-2042,-2096,-2150,-2204,-2256,-2308,-2359,
-2410,-2460,-2509,-2557,-2604,-2651,-2697,-2742,-2786,-2830,
-2872,-2914,-2955,-2994,-3033,-3071,-3108,-3145,-3180,-3214
};
const int sinc[360]=
{
//240~359
3247,3214,3180,3145,3108,3071,3033,2994,2955,2914,
2872,2830,2786,2742,2697,2651,2604,2557,2509,2460,
2410,2359,2308,2256,2204,2150,2096,2042,1987,1931,
1875,1818,1760,1702,1643,1584,1525,1465,1404,1343,
1282,1220,1158,1096,1033,970,907,843,779,715,
651,586,521,457,391,326,261,196,130,65,
0,-65,-130,-196,-261,-326,-391,-457,-521,-586,
-651,-715,-779,-843,-907,-970,-1033,-1096,-1158,-1220,
-1282,-1343,-1404,-1465,-1525,-1584,-1643,-1702,-1760,-1818,
-1874,-1931,-1987,-2042,-2096,-2150,-2204,-2256,-2308,-2359,
-2410,-2460,-2509,-2557,-2604,-2651,-2697,-2742,-2786,-2830,
-2872,-2914,-2955,-2994,-3033,-3071,-3108,-3145,-3180,-3214,
//0~119
-3247,-3279,-3311,-3341,-3370,-3398,-3425,-3451,-3476,-3500,
-3523,-3545,-3566,-3586,-3604,-3622,-3638,-3653,-3668,-3681,
-3693,-3703,-3713,-3722,-3729,-3735,-3740,-3744,-3747,-3749,
-3749,-3749,-3747,-3744,-3740,-3735,-3729,-3722,-3713,-3703,
-3693,-3681,-3668,-3653,-3638,-3622,-3604,-3586,-3566,-3545,
-3523,-3500,-3476,-3451,-3425,-3398,-3370,-3341,-3311,-3279,
-3247,-3214,-3180,-3145,-3108,-3071,-3033,-2994,-2955,-2914,
-2872,-2830,-2786,-2742,-2697,-2651,-2604,-2557,-2509,-2460,
-2410,-2359,-2308,-2256,-2204,-2150,-2096,-2042,-1987,-1931,
-1875,-1818,-1760,-1702,-1643,-1584,-1525,-1465,-1404,-1343,
-1282,-1220,-1158,-1096,-1033,-970,-907,-843,-779,-715,
-651,-586,-521,-457,-391,-326,-261,-196,-130,-65,
//120~239
0,65,130,196,261,326,391,457,521,586,
651,715,779,843,907,970,1033,1096,1158,1220,
1282,1343,1404,1465,1525,1584,1643,1702,1760,1818,
1874,1931,1987,2042,2096,2150,2204,2256,2308,2359,
2410,2460,2509,2557,2604,2651,2697,2742,2786,2830,
2872,2914,2955,2994,3033,3071,3108,3145,3180,3214,
3247,3279,3311,3341,3370,3398,3425,3451,3476,3500,
3523,3545,3566,3586,3604,3622,3638,3653,3668,3681,
3693,3703,3713,3722,3729,3735,3740,3744,3747,3749,
3749,3749,3747,3744,3740,3735,3729,3722,3713,3703,
3693,3681,3668,3653,3638,3622,3604,3586,3566,3545,
3523,3500,3476,3451,3425,3398,3370,3341,3311,3279
};
Uint32 ratioa;
Uint32 ratiob;
Uint32 ratioc;
void Scan_Key0(void);
void Scan_Key1(void);
void Manage_Key0(void);
void Manage_Key1(void);
int m,n;
unsigned long int a;
unsigned long int b;
unsigned long int fc=10000;
float fr=50;
int frmax=50;
float k; //调制比
#define EPWM_DB 450 //当TBCLK=150Mhz 死区时间为3us
#define EPWM_TBPRD 7500 //当TBCLK=150Mhz,增减计数频率为10K
void InitEpwm1()
{
EPwm1Regs.TBPRD=EPWM_TBPRD; //设定PWM周期为10k
EPwm1Regs.TBPHS.half.TBPHS=0x0000; //相位寄存器为0
EPwm1Regs.TBCTR=0x0000; //时基计数器为0
EPwm1Regs.TBCTL.bit.CTRMODE=TB_COUNT_UPDOWN; //增减计数
EPwm1Regs.TBCTL.bit.PRDLD=TB_SHADOW; //周期寄存器为影子装载模式(当CTR=0时,会读影子寄存器)
EPwm1Regs.TBCTL.bit.PHSEN=TB_DISABLE; //禁止相位同步
EPwm1Regs.TBCTL.bit.HSPCLKDIV=TB_DIV1; //*时基时钟为
EPwm1Regs.TBCTL.bit.CLKDIV=TB_DIV1; // 150M*
EPwm1Regs.CMPCTL.bit.SHDWAMODE=CC_SHADOW; //计数比较A寄存器为影子装载模式
EPwm1Regs.CMPCTL.bit.LOADAMODE=CC_CTR_ZERO; //当CTR=0时CMPA重载
EPwm1Regs.CMPA.half.CMPA=0;
EPwm1Regs.AQCTLA.bit.CAU=AQ_CLEAR; //CTR=CAU时,输出低电平
EPwm1Regs.AQCTLA.bit.CAD=AQ_SET; //CTR=CAD时,输出高电平
EPwm1Regs.DBCTL.bit.OUT_MODE=DB_FULL_ENABLE; //死区模块输出使能
EPwm1Regs.DBCTL.bit.POLSEL=DB_ACTV_HIC;//下降沿翻转
EPwm1Regs.DBCTL.bit.IN_MODE=DBA_ALL; //ePWMA双边沿延时(ePWMB输入无效)
EPwm1Regs.DBFED=EPWM_DB; //下降沿延时3us
EPwm1Regs.DBRED=EPWM_DB; //上升沿延时3us
EPwm1Regs.ETSEL.bit.INTSEL=ET_CTR_PRD; //当CTR=PRD时,触发中断
EPwm1Regs.ETSEL.bit.INTEN=1; //使能ePWM1INT
EPwm1Regs.ETPS.bit.INTPRD=ET_1ST;