问题如上spwm程序无法进入中断执行数组赋值导致出不来spwm
这是程序的仿真波形,不是swpm波,没进中断,各位大神帮忙看下啥问题,谢!
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
#define uint unsigned int
void InitEPwm1(void);
void InitEPwm2(void);
void InitEPwm1Gpio(void);
void InitEPwm2Gpio(void);
interrupt void epwm1_timer_isr(void);
#define tablesize 200 //一个周期正弦表大小
uint Num=0;
//正弦表
const uint sinetable[tablesize]={
1462, 1415, 1369, 1322, 1276, 1230, 1184, 1138, 1093, 1048,
1004, 960, 917, 874, 832, 791, 750, 710, 671, 633,
595, 559, 523, 488, 455, 422, 391, 360, 331, 303,
276, 250, 226, 202, 181, 160, 141, 123, 106, 91,
77, 65, 54, 44, 36, 30, 25, 21, 19, 18,
19, 21, 25, 30, 36, 44, 54, 65, 77, 91,
106, 123, 141, 160, 181, 202, 226, 250, 276, 303,
331, 360, 391, 422, 455, 488, 523, 559, 595, 633,
671, 710, 750, 791, 832, 874, 917, 960, 1004, 1048,
1093, 1138, 1184, 1230, 1276, 1322, 1369, 1415, 1462, 1509,
1556, 1603, 1649, 1696, 1742, 1788, 1834, 1880, 1925, 1970,
2014, 2058, 2101, 2144, 2186, 2227, 2268, 2308, 2347, 2385,
2423, 2459, 2495, 2530, 2563, 2596, 2627, 2658, 2687, 2715,
2742, 2768, 2792, 2816, 2837, 2858, 2877, 2895, 2912, 2927,
2941, 2953, 2964, 2974, 2982, 2988, 2993, 2997, 2999, 3000,
2999, 2997, 2993, 2988, 2982, 2974, 2964, 2953, 2941, 2927,
2912, 2895, 2877, 2858, 2837, 2816, 2792, 2768, 2742, 2715,
2687, 2658, 2627, 2596, 2563, 2530, 2495, 2459, 2423, 2385,
2347, 2308, 2268, 2227, 2186, 2144, 2101, 2058, 2014, 1970,
1925, 1880, 1834, 1788, 1742, 1696, 1649, 1603, 1556, 1509
};
void main(void)
{
InitSysCtrl();//1、初始化系统
InitEPwm1Gpio();
InitEPwm2Gpio();
DINT;//Disable interrupt 清除所有中断,并禁用CPU中断
InitPieCtrl();//PIE初始化
IER = 0x0000;
IFR = 0x0000;//禁用CPU中断和清除所有CPU中断
InitPieVectTable();//PIE向量表初始化
EALLOW;//Edit allow
PieVectTable.EPWM1_INT = &epwm1_timer_isr;
EDIS; //Edit disable
InitEPwm1();
InitEPwm2();
IER |= M_INT3;
PieCtrlRegs.PIEIER3.bit.INTx1 = 1;// PWM1中断
EINT; // 启用全局中断INTM
ERTM;//使能做全局实时中断DBGM
for(;;)
{
__asm("NOP");
}
}
interrupt void epwm1_timer_isr(void)
{
if(Num==tablesize)
Num=0;
EPwm1Regs.CMPA.half.CMPA=sinetable[Num];
Num++;
EPwm1Regs.ETCLR.bit.INT = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;//写1清0
}
void InitEPwm1()
{
EPwm1Regs.TBPRD = 3000; // Set timer period
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm1Regs.TBCTR = 0x0000; // Clear counter
// Setup TBCLK
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase loading
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1; // Slow just to observe on the scope
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; // Load registers every ZERO
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO_PRD;
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO_PRD;
// Setup compare
EPwm1Regs.CMPA.half.CMPA = 800; //占空比设置为0,防止上电瞬间电压值达到最大
// Set actions
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; // Set PWM2A on Zero
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;
// Interrupt where we will modify the deadband
EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; // Select INT on Zero event
EPwm1Regs.ETSEL.bit.INTEN = 1; // Enable INT
EPwm1Regs.ETPS.bit.INTPRD = ET_1ST; // Generate INT on 3rd event
}
void InitEPwm2()
{
//TBCLK=SYSCLKOUT/(HSPCLKDIV*CLKDIV)=(1/60M)/(1*1)
//Tpwm=2*TBPRD*T_TBCLK (For Updown mode)
//1/40K=2*TBPRD*(1/60M)==>TBPRD=750
EPwm2Regs.TBPRD = 750; // Set timer period
EPwm2Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm2Regs.TBCTR = 0x0000; // Clear counter
// Setup TBCLK
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count updown
EPwm2Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase loading
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; // Load registers every ZERO
EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
// Setup compare
EPwm2Regs.CMPA.half.CMPA = 375;
// Set actions
EPwm2Regs.AQCTLA.bit.CAU = AQ_CLEAR; // Set PWM1A on Zero
EPwm2Regs.AQCTLA.bit.CAD = AQ_SET;
// Interrupt where we will change the Deadband
EPwm2Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; // Select INT on Zero event
EPwm2Regs.ETSEL.bit.INTEN = 1; // Enable INT
EPwm2Regs.ETPS.bit.INTPRD = ET_3RD; // Generate INT on 3rd event
}
void InitEPwm1Gpio(void)
{
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO0 = 1; // Disable pull-up on GPIO0 (EPWM1A)
GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1; // Disable pull-up on GPIO1 (EPWM1B)
GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; // Configure GPIO0 as EPWM1A
GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1; // Configure GPIO1 as EPWM1B
EDIS;
}
void InitEPwm2Gpio(void)
{
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO2 = 1; // Disable pull-up on GPIO2 (EPWM2A)
GpioCtrlRegs.GPAPUD.bit.GPIO3 = 1; // Disable pull-up on GPIO3 (EPWM2B)
GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 1; // Configure GPIO2 as EPWM2A
GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 1; // Configure GPIO3 as EPWM2B
EDIS;
}
此帖出自
小平头技术问答
好的,谢
一周热门 更多>