#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h"
#if (CPU_FRQ_150MHZ)
#define CPU_CLK 150e6
#endif
#if (CPU_FRQ_100MHZ)
#define CPU_CLK 100e6
#endif
extern Uint16 x;
#define busy_in GpioDataRegs.GPBDAT.bit.GPIO58
#define busy_out GpioDataRegs.GPBDAT.bit.GPIO59
#define EOLC GpioDataRegs.GPBDAT.bit.GPIO52
#define square GpioDataRegs.GPADAT.bit.GPIO4
#define XintfFPGA (0x004000)
#define Xintf_FPGA(x) (*((volatile Uint16 *)(XintfFPGA+(x<<7))))
#define delay 4e-3 //设定脉冲延时时间
extern int a=0;
extern int b=0;
extern int c=0;
extern int d=0;
extern int y=0;
extern float af[11][2]={{0,3.1416},{0.0065,3.0274},{0.0486,2.8222},{0.1486,2.5637},{0.3065,2.2676},{0.5,1.9427},{0.6935,1.5945},{0.8514,1.2261},{0.9514,0.8384},{0.9935,0.4308},{1,0}};//建立11行2维数据表
extern int i=0,ta=0,tb=0,tc=0,ty=0;
extern float alpha=0,ta1=0,ta2=0,ta3=0,ta4=0,tb1=0,tc1=0;
extern int16 temp1[8] = {0};
extern float ADC1_CH0[20] = {0};
extern float ADC1_CH2[20] = {0};
extern int n = 0,j = 0,EOLC_value=0,m=0;
extern int h = 0;
void configtest_gpio(void);
void adcsetup(void);
interrupt void Init_ad_isr(void);
void epwmsetup(void);
void main(void)
{
while(1)
{
InitSysCtrl();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
InitXintf();
configtest_gpio();
adcsetup();
EALLOW;
PieVectTable.USER1 = &Init_ad_isr;
EDIS;
EINT;
ERTM;
}
}
interrupt void Init_ad_isr(void)
{
if(square==1)
{
epwmsetup;
}
EINT;
}
void adcsetup(void)
{
while(1)
{
EOLC_value = EOLC;
if(EOLC_value==0)
{
for(n = 0;n < 8;n++)
{
temp1[n] = Xintf_FPGA(0)<<2;
if(n == 0)
{
ADC1_CH0[j] = 0.000305*temp1[n];
}
else
if(n == 2)
{
ADC1_CH2[j] = 0.000305*temp1[n];
if(ADC1_CH2[j] > 0)
{
square = 1;
}
else
{
square = 0;
}
}
}
if(j < 20)
{
j++;
}
else
{
j = 0;
}
}
}
}
这是程序的一部分,因为硬件电路是固定的所以没法用比较器实现。pwm 和 外部ad的采样是先做的 通过观察是没有问题的, ADC1_CH2[j]这个通道是正弦波的采样,现在把它变成了方波,想在方波的上升沿产生中断进入pwm子程序,但是发现一直进不去,一开始用的是可屏蔽中断但不知道选哪个pie中断分组,现在用的是不可屏蔽中断,单步调试发现根本进不了中断。也是刚开始学dsp,希望各位大佬指点 |